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.
 
 
 
 
 

117 lines
3.7 KiB

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