MediaRevisions.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace dokuwiki\Ui;
  3. use dokuwiki\ChangeLog\MediaChangeLog;
  4. use dokuwiki\ChangeLog\RevisionInfo;
  5. use dokuwiki\Form\Form;
  6. use InvalidArgumentException;
  7. /**
  8. * DokuWiki MediaRevisions Interface
  9. *
  10. * @package dokuwiki\Ui
  11. */
  12. class MediaRevisions extends Revisions
  13. {
  14. /* @var MediaChangeLog */
  15. protected $changelog;
  16. /**
  17. * MediaRevisions Ui constructor
  18. *
  19. * @param string $id id of media
  20. */
  21. public function __construct($id)
  22. {
  23. if (!$id) {
  24. throw new InvalidArgumentException('media id should not be empty!');
  25. }
  26. parent::__construct($id);
  27. }
  28. /** @inheritdoc */
  29. protected function setChangeLog()
  30. {
  31. $this->changelog = new MediaChangeLog($this->id);
  32. }
  33. /**
  34. * Display a list of Media Revisions in the MediaManager
  35. *
  36. * @author Andreas Gohr <andi@splitbrain.org>
  37. * @author Ben Coburn <btcoburn@silicodon.net>
  38. * @author Kate Arzamastseva <pshns@ukr.net>
  39. * @author Satoshi Sahara <sahara.satoshi@gmail.com>
  40. *
  41. * @param int $first skip the first n changelog lines
  42. * @return void
  43. */
  44. public function show($first = -1)
  45. {
  46. global $lang;
  47. $changelog =& $this->changelog;
  48. // get revisions, and set correct pagination parameters (first, hasNext)
  49. if ($first === null) $first = -1;
  50. $hasNext = false;
  51. $revisions = $this->getRevisions($first, $hasNext);
  52. // create the form
  53. $form = new Form([
  54. 'id' => 'page__revisions', // must not be "media__revisions"
  55. 'action' => media_managerURL(['image' => $this->id], '&'),
  56. 'class' => 'changes',
  57. ]);
  58. $form->setHiddenField('mediado', 'diff'); // required for media revisions
  59. $form->addTagOpen('div')->addClass('no');
  60. // start listing
  61. $form->addTagOpen('ul');
  62. foreach ($revisions as $info) {
  63. $rev = $info['date'];
  64. $info['media'] = true;
  65. $RevInfo = new RevisionInfo($info);
  66. $RevInfo->isCurrent($changelog->isCurrentRevision($rev));
  67. $class = ($RevInfo->val('type') === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
  68. $form->addTagOpen('li')->addClass($class);
  69. $form->addTagOpen('div')->addClass('li');
  70. if ($RevInfo->isCurrent()) {
  71. $form->addCheckbox('rev2[]')->val($rev);
  72. } elseif (file_exists(mediaFN($this->id, $rev))) {
  73. $form->addCheckbox('rev2[]')->val($rev);
  74. } else {
  75. $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
  76. }
  77. $form->addHTML(' ');
  78. $html = implode(' ', [
  79. $RevInfo->showEditDate(), // edit date and time
  80. $RevInfo->showIconCompareWithCurrent(), // link to diff view icon
  81. $RevInfo->showFileName(), // name of page or media
  82. '<div>',
  83. $RevInfo->showEditSummary(), // edit summary
  84. $RevInfo->showEditor(), // editor info
  85. $RevInfo->showSizechange(), // size change indicator
  86. $RevInfo->showCurrentIndicator(), // current indicator (only when k=1)
  87. '</div>',
  88. ]);
  89. $form->addHTML($html);
  90. $form->addTagClose('div');
  91. $form->addTagClose('li');
  92. }
  93. $form->addTagClose('ul'); // end of revision list
  94. // show button for diff view
  95. $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
  96. $form->addTagClose('div'); // close div class=no
  97. print $form->toHTML('Revisions');
  98. // provide navigation for paginated revision list (of pages and/or media files)
  99. print $this->navigation($first, $hasNext, function ($n) {
  100. return media_managerURL(['first' => $n], '&', false, true);
  101. });
  102. }
  103. }