id = $id; $this->setChangeLog(); } /** * set class property changelog */ abstract protected function setChangeLog(); /** * Get revisions, and set correct pagination parameters (first, hasNext) * * @param int $first * @param bool $hasNext * @return array revisions to be shown in a pagenated list * @see also https://www.dokuwiki.org/devel:changelog */ protected function getRevisions(&$first, &$hasNext) { global $conf; $changelog =& $this->changelog; $revisions = []; $currentRevInfo = $changelog->getCurrentRevisionInfo(); if (!$currentRevInfo) return $revisions; $num = $conf['recent']; if ($first == 0) { // add extrenal or existing last revision that is excluded from $changelog->getRevisions() if (array_key_exists('timestamp', $currentRevInfo) || ( $currentRevInfo['type'] != DOKU_CHANGE_TYPE_DELETE && $currentRevInfo['date'] == $changelog->lastRevision() ) ) { $revisions[] = $currentRevInfo; $num = $num - 1; } } /* we need to get one additional log entry to be able to * decide if this is the last page or is there another one. * see also Ui\Recent::getRecents() */ $revlist = $changelog->getRevisions($first, $num + 1); if (count($revlist) == 0 && $first > 0) { // resets to zero if $first requested a too high number $first = 0; return $this->getRevisions($first, $hasNext); } // decide if this is the last page or is there another one $hasNext = false; if (count($revlist) > $num) { $hasNext = true; array_pop($revlist); // remove one additional log entry } // append each revison info array to the revisions foreach ($revlist as $rev) { $revisions[] = $changelog->getRevisionInfo($rev); } return $revisions; } /** * Navigation buttons for Pagenation (prev/next) * * @param int $first * @param bool $hasNext * @param callable $callback returns array of hidden fields for the form button * @return string html */ protected function navigation($first, $hasNext, $callback) { global $conf; $html = ''; return $html; } /** * Returns instance of objRevInfo * * @param array $info Revision info structure of a page or media file * @return objRevInfo object (anonymous class) */ public function getObjRevInfo(array $info) { return new class ($info) // anonymous class (objRevInfo) { protected $info; public function __construct(array $info) { $info['item'] = strrpos($info['id'], '.') ? 'media' : 'page'; $info['current'] = $info['current'] ?? false; // revision info may have timestamp key when external edits occurred $info['timestamp'] = $info['timestamp'] ?? true; $this->info = $info; } // current indicator public function currentIndicator() { global $lang; return ($this->info['current']) ? '('.$lang['current'].')' : ''; } // edit date and time of the page or media file public function editDate() { global $lang; $date = dformat($this->info['date']); if ($this->info['timestamp'] === false) { // externally deleted or older file restored $date = preg_replace('/[0-9a-zA-Z]/','_', $date); } return ''. $date .''; } // edit summary public function editSummary() { return ''.' – '. hsc($this->info['sum']).''; } // editor of the page or media file public function editor() { // slightly different with display of Ui\Recent, i.e. external edit global $lang; $html = ''; if (!$this->info['user'] && !$this->info['ip']) { $html.= '('.$lang['external_edit'].')'; } elseif ($this->info['user']) { $html.= ''. editorinfo($this->info['user']) .''; if (auth_ismanager()) $html.= ' ('. $this->info['ip'] .')'; } else { $html.= ''. $this->info['ip'] .''; } $html.= ''; return $html; } // name of the page or media file public function itemName() { // slightly different with display of Ui\Recent, i.e. revison may not exists $id = $this->info['id']; $rev = $this->info['date']; switch ($this->info['item']) { case 'media': // media file revision if ($this->info['current']) { $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view'], '&'); $html = ''.$id.''; } elseif (file_exists(mediaFN($id, $rev))) { $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view', 'rev'=> $rev], '&'); $html = ''.$id.''; } else { $html = $id; } return $html; case 'page': // page revision $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; if (!$display_name) $display_name = $id; if ($this->info['type'] == DOKU_CHANGE_TYPE_DELETE) { // externally deleted or older file restored $href = wl($id, "", false, '&'); $html = ''.$display_name.''; } elseif ($this->info['current'] || page_exists($id, $rev)) { $href = wl($id, "rev=$rev", false, '&'); $html = ''.$display_name.''; } else { $html = $display_name; } return $html; } return ''; } // icon difflink public function difflink() { global $lang; $id = $this->info['id']; $rev = $this->info['date']; switch ($this->info['item']) { case 'media': // media file revision if ($this->info['current'] || !file_exists(mediaFN($id, $rev))) { $html = ''; } else { $href = media_managerURL(['image'=> $id, 'rev'=> $rev, 'mediado'=>'diff'], '&'); $html = '' . ''.$lang['diff'] .'' . ' '; } return $html; case 'page': // page revision if ($this->info['current'] || !page_exists($id, $rev)) { $html = ''; } else { $href = wl($id, "rev=$rev,do=diff", false, '&'); $html = '' . ''.$lang['diff'].'' . ''; } return $html; } return ''; } // size change public function sizeChange() { $class = 'sizechange'; $value = filesize_h(abs($this->info['sizechange'])); if ($this->info['sizechange'] > 0) { $class .= ' positive'; $value = '+' . $value; } elseif ($this->info['sizechange'] < 0) { $class .= ' negative'; $value = '-' . $value; } else { $value = '±' . $value; } return ''.$value.''; } }; // end of anonymous class (objRevInfo) } }