You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

122 lines
3.8 KiB

  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. * @param int $first skip the first n changelog lines
  37. * @return void
  38. * @author Kate Arzamastseva <pshns@ukr.net>
  39. * @author Satoshi Sahara <sahara.satoshi@gmail.com>
  40. *
  41. * @author Andreas Gohr <andi@splitbrain.org>
  42. * @author Ben Coburn <btcoburn@silicodon.net>
  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. $RevInfo = new RevisionInfo($info);
  65. $RevInfo->isCurrent($changelog->isCurrentRevision($rev));
  66. $class = ($RevInfo->val('type') === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
  67. $form->addTagOpen('li')->addClass($class);
  68. $form->addTagOpen('div')->addClass('li');
  69. if ($RevInfo->isCurrent()) {
  70. $form->addCheckbox('rev2[]')->val($rev);
  71. } elseif (file_exists(mediaFN($this->id, $rev))) {
  72. $form->addCheckbox('rev2[]')->val($rev);
  73. } else {
  74. $form->addCheckbox('')->val($rev)->attr('disabled', 'disabled');
  75. }
  76. $form->addHTML(' ');
  77. $html = implode(' ', [
  78. $RevInfo->showEditDate(), // edit date and time
  79. $RevInfo->showIconCompareWithCurrent(), // link to diff view icon
  80. $RevInfo->showFileName(), // name of page or media
  81. '<div>',
  82. $RevInfo->showEditSummary(), // edit summary
  83. $RevInfo->showEditor(), // editor info
  84. $RevInfo->showSizechange(), // size change indicator
  85. $RevInfo->showCurrentIndicator(), // current indicator (only when k=1)
  86. '</div>',
  87. ]);
  88. $form->addHTML($html);
  89. $form->addTagClose('div');
  90. $form->addTagClose('li');
  91. }
  92. $form->addTagClose('ul'); // end of revision list
  93. // show button for diff view
  94. $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
  95. $form->addTagClose('div'); // close div class=no
  96. echo $form->toHTML('Revisions');
  97. // provide navigation for paginated revision list (of pages and/or media files)
  98. echo $this->navigation(
  99. $first,
  100. $hasNext,
  101. static fn($n) => media_managerURL(['first' => $n], '&', false, true)
  102. );
  103. }
  104. }