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 /** 16 * PageRevisions Ui constructor 17 * 18 * @param string $id id of page 19 */ 20 public function __construct($id) 21 { 22 global $ID, $INFO; 23 if (!$id) $id = $INFO['id']; 24 parent::__construct($id); 25 } 26 27 /** 28 * Display list of old revisions of the page 29 * 30 * @author Andreas Gohr <andi@splitbrain.org> 31 * @author Ben Coburn <btcoburn@silicodon.net> 32 * @author Kate Arzamastseva <pshns@ukr.net> 33 * @author Satoshi Sahara <sahara.satoshi@gmail.com> 34 * 35 * @param int $first skip the first n changelog lines 36 * @return void 37 */ 38 public function show($first = 0) 39 { 40 global $lang; 41 42 // get revisions, and set correct pagenation parameters (first, hasNext) 43 if ($first === null) $first = 0; 44 $hasNext = false; 45 $revisions = $this->getRevisions($first, $hasNext); 46 47 // print intro 48 print p_locale_xhtml('revisions'); 49 50 // create the form 51 $form = new Form([ 52 'id' => 'page__revisions', 53 'class' => 'changes', 54 ]); 55 $form->addTagOpen('div')->addClass('no'); 56 57 // start listing 58 $form->addTagOpen('ul'); 59 foreach ($revisions as $info) { 60 $rev = $info['date']; 61 $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : ''; 62 $form->addTagOpen('li')->addClass($class); 63 $form->addTagOpen('div')->addClass('li'); 64 65 if (page_exists($this->id, $rev)) { 66 $form->addCheckbox('rev2[]')->val($rev); 67 } else { 68 $form->addCheckbox('')->val($rev)->attr('disabled','disabled'); 69 } 70 $form->addHTML(' '); 71 72 $objRevInfo = $this->getObjRevInfo($info); 73 $html = implode(' ', [ 74 $objRevInfo->editDate(), // edit date and time 75 $objRevInfo->difflink(), // link to diffview icon 76 $objRevInfo->itemName(), // name of page or media 77 $objRevInfo->editSummary(), // edit summary 78 $objRevInfo->editor(), // editor info 79 $objRevInfo->sizechange(), // size change indicator 80 $objRevInfo->currentIndicator(), // current indicator (only when k=1) 81 ]); 82 $form->addHTML($html); 83 $form->addTagClose('div'); 84 $form->addTagClose('li'); 85 } 86 $form->addTagClose('ul'); // end of revision list 87 88 // show button for diff view 89 $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit'); 90 91 $form->addTagClose('div'); // close div class=no 92 93 print $form->toHTML('Revisions'); 94 95 // provide navigation for pagenated revision list (of pages and/or media files) 96 print $this->navigation($first, $hasNext, function ($n) { 97 return array('do' => 'revisions', 'first' => $n); 98 }); 99 } 100 101 /** 102 * Get revisions, and set correct pagenation parameters (first, hasNext) 103 * 104 * @param int $first 105 * @param bool $hasNext 106 * @return array revisions to be shown in a pagenated list 107 * @see also https://www.dokuwiki.org/devel:changelog 108 */ 109 protected function getRevisions(&$first, &$hasNext) 110 { 111 global $INFO, $conf; 112 113 $changelog = new PageChangeLog($INFO['id']); 114 115 $revisions = []; 116 117 /* we need to get one additional log entry to be able to 118 * decide if this is the last page or is there another one. 119 * see also Ui\Recent::getRecents() 120 */ 121 $revlist = $changelog->getRevisions($first, $conf['recent'] +1); 122 if (count($revlist) == 0 && $first != 0) { 123 $first = 0; 124 $revlist = $changelog->getRevisions($first, $conf['recent'] +1); 125 } 126 $exists = $INFO['exists']; 127 if ($first === 0 && $exists) { 128 // add current page as revision[0] 129 $revisions[] = array( 130 'date' => $INFO['lastmod'], 131 'ip' => null, 132 'type' => $INFO['meta']['last_change']['type'], 133 'id' => $INFO['id'], 134 'user' => $INFO['editor'], 135 'sum' => $INFO['sum'], 136 'extra' => null, 137 'sizechange' => $INFO['meta']['last_change']['sizechange'], 138 'current' => true, 139 ); 140 } 141 142 // decide if this is the last page or is there another one 143 $hasNext = false; 144 if (count($revlist) > $conf['recent']) { 145 $hasNext = true; 146 array_pop($revlist); // remove one additional log entry 147 } 148 149 // append each revison info array to the revisions 150 foreach ($revlist as $rev) { 151 $revisions[] = $changelog->getRevisionInfo($rev); 152 } 153 return $revisions; 154 } 155 156} 157