PageRevisions.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * @author Andreas Gohr <andi@splitbrain.org>
  35. * @author Ben Coburn <btcoburn@silicodon.net>
  36. * @author Kate Arzamastseva <pshns@ukr.net>
  37. * @author Satoshi Sahara <sahara.satoshi@gmail.com>
  38. *
  39. * @param int $first skip the first n changelog lines
  40. * @return void
  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. print 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. $info['media'] = false;
  63. $RevInfo = new RevisionInfo($info);
  64. $RevInfo->isCurrent($changelog->isCurrentRevision($rev));
  65. $class = ($RevInfo->val('type') === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
  66. $form->addTagOpen('li')->addClass($class);
  67. $form->addTagOpen('div')->addClass('li');
  68. if ($RevInfo->isCurrent()) {
  69. $form->addCheckbox('rev2[]')->val($rev);
  70. } elseif ($rev == $REV) {
  71. $form->addCheckbox('rev2[]')->val($rev)->attr('checked','checked');
  72. } elseif (page_exists($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(true), // edit date and time
  80. $RevInfo->showIconCompareWithCurrent(), // link to diff view icon
  81. $RevInfo->showFileName(), // name of page or media
  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. ]);
  87. $form->addHTML($html);
  88. $form->addTagClose('div');
  89. $form->addTagClose('li');
  90. }
  91. $form->addTagClose('ul'); // end of revision list
  92. // show button for diff view
  93. $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
  94. $form->addTagClose('div'); // close div class=no
  95. print $form->toHTML('Revisions');
  96. // provide navigation for paginated revision list (of pages and/or media files)
  97. print $this->navigation($first, $hasNext, function ($n) {
  98. return array('do' => 'revisions', 'first' => $n);
  99. });
  100. }
  101. }