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