/** * list old revisions * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> * @author Kate Arzamastseva <*****@*****.**> * * @param int $first skip the first n changelog lines * @param bool|string $media_id id of media, or false for current page */ function html_revisions($first = 0, $media_id = false) { global $ID; global $INFO; global $conf; global $lang; $id = $ID; if ($media_id) { $id = $media_id; $changelog = new MediaChangeLog($id); } else { $changelog = new PageChangeLog($id); } /* 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 html_recent() */ $revisions = $changelog->getRevisions($first, $conf['recent'] + 1); if (count($revisions) == 0 && $first != 0) { $first = 0; $revisions = $changelog->getRevisions($first, $conf['recent'] + 1); } $hasNext = false; if (count($revisions) > $conf['recent']) { $hasNext = true; array_pop($revisions); // remove extra log entry } if (!$media_id) { $date = dformat($INFO['lastmod']); } else { $date = dformat(@filemtime(mediaFN($id))); } if (!$media_id) { print p_locale_xhtml('revisions'); } $params = array('id' => 'page__revisions', 'class' => 'changes'); if ($media_id) { $params['action'] = media_managerURL(array('image' => $media_id), '&'); } $form = new Doku_Form($params); $form->addElement(form_makeOpenTag('ul')); if (!$media_id) { $exists = $INFO['exists']; } else { $exists = file_exists(mediaFN($id)); } $display_name = !$media_id && useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; if (!$display_name) { $display_name = $id; } if ($exists && $first == 0) { if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); } else { $form->addElement(form_makeOpenTag('li')); } $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); $form->addElement(form_makeTag('input', array('type' => 'checkbox', 'name' => 'rev2[]', 'value' => 'current'))); $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); $form->addElement($date); $form->addElement(form_makeCloseTag('span')); $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); if (!$media_id) { $href = wl($id); } else { $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); } $form->addElement(form_makeOpenTag('a', array('class' => 'wikilink1', 'href' => $href))); $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); if ($media_id) { $form->addElement(form_makeOpenTag('div')); } if (!$media_id) { $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); $form->addElement(' – '); $form->addElement(htmlspecialchars($INFO['sum'])); $form->addElement(form_makeCloseTag('span')); } $changelog->setChunkSize(1024); $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if ($media_id) { $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id)))); if ($revinfo['user']) { $editor = $revinfo['user']; } else { $editor = $revinfo['ip']; } } else { $editor = $INFO['editor']; } $form->addElement(empty($editor) ? '(' . $lang['external_edit'] . ')' : editorinfo($editor)); $form->addElement(form_makeCloseTag('span')); $form->addElement('(' . $lang['current'] . ')'); if ($media_id) { $form->addElement(form_makeCloseTag('div')); } $form->addElement(form_makeCloseTag('div')); $form->addElement(form_makeCloseTag('li')); } foreach ($revisions as $rev) { $date = dformat($rev); $info = $changelog->getRevisionInfo($rev); if ($media_id) { $exists = file_exists(mediaFN($id, $rev)); } else { $exists = page_exists($id, $rev); } if ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); } else { $form->addElement(form_makeOpenTag('li')); } $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); if ($exists) { $form->addElement(form_makeTag('input', array('type' => 'checkbox', 'name' => 'rev2[]', 'value' => $rev))); } else { $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); } $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); $form->addElement($date); $form->addElement(form_makeCloseTag('span')); if ($exists) { if (!$media_id) { $href = wl($id, "rev={$rev},do=diff", false, '&'); } else { $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); } $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); $form->addElement(form_makeTag('img', array('src' => DOKU_BASE . 'lib/images/diff.png', 'width' => 15, 'height' => 11, 'title' => $lang['diff'], 'alt' => $lang['diff']))); $form->addElement(form_makeCloseTag('a')); if (!$media_id) { $href = wl($id, "rev={$rev}", false, '&'); } else { $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); } $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); } else { $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); $form->addElement($display_name); } if ($media_id) { $form->addElement(form_makeOpenTag('div')); } if ($info['sum']) { $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); if (!$media_id) { $form->addElement(' – '); } $form->addElement('<bdi>' . htmlspecialchars($info['sum']) . '</bdi>'); $form->addElement(form_makeCloseTag('span')); } $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if ($info['user']) { $form->addElement('<bdi>' . editorinfo($info['user']) . '</bdi>'); if (auth_ismanager()) { $form->addElement(' <bdo dir="ltr">(' . $info['ip'] . ')</bdo>'); } } else { $form->addElement('<bdo dir="ltr">' . $info['ip'] . '</bdo>'); } $form->addElement(form_makeCloseTag('span')); if ($media_id) { $form->addElement(form_makeCloseTag('div')); } $form->addElement(form_makeCloseTag('div')); $form->addElement(form_makeCloseTag('li')); } $form->addElement(form_makeCloseTag('ul')); if (!$media_id) { $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); } else { $form->addHidden('mediado', 'diff'); $form->addElement(form_makeButton('submit', '', $lang['diff2'])); } html_form('revisions', $form); print '<div class="pagenav">'; $last = $first + $conf['recent']; if ($first > 0) { $first -= $conf['recent']; if ($first < 0) { $first = 0; } print '<div class="pagenav-prev">'; if ($media_id) { print html_btn('newer', $media_id, "p", media_managerURL(array('first' => $first), '&', false, true)); } else { print html_btn('newer', $id, "p", array('do' => 'revisions', 'first' => $first)); } print '</div>'; } if ($hasNext) { print '<div class="pagenav-next">'; if ($media_id) { print html_btn('older', $media_id, "n", media_managerURL(array('first' => $last), '&', false, true)); } else { print html_btn('older', $id, "n", array('do' => 'revisions', 'first' => $last)); } print '</div>'; } print '</div>'; }
/** * Returns a list of available revisions of a given wiki page * * @author Michael Klier <*****@*****.**> * * @param string $id page id * @param int $first skip the first n changelog lines * @return array * @throws RemoteAccessDeniedException no read access for page * @throws RemoteException empty id */ function pageVersions($id, $first) { $id = $this->resolvePageId($id); if (auth_quickaclcheck($id) < AUTH_READ) { throw new RemoteAccessDeniedException('You are not allowed to read this page', 111); } global $conf; $versions = array(); if (empty($id)) { throw new RemoteException('Empty page ID', 131); } $pagelog = new PageChangeLog($id); $revisions = $pagelog->getRevisions($first, $conf['recent'] + 1); if (count($revisions) == 0 && $first != 0) { $first = 0; $revisions = $pagelog->getRevisions($first, $conf['recent'] + 1); } if (count($revisions) > 0 && $first == 0) { array_unshift($revisions, ''); // include current revision if (count($revisions) > $conf['recent']) { array_pop($revisions); // remove extra log entry } } if (count($revisions) > $conf['recent']) { array_pop($revisions); // remove extra log entry } if (!empty($revisions)) { foreach ($revisions as $rev) { $file = wikiFN($id, $rev); $time = @filemtime($file); // we check if the page actually exists, if this is not the // case this can lead to less pages being returned than // specified via $conf['recent'] if ($time) { $pagelog->setChunkSize(1024); $info = $pagelog->getRevisionInfo($time); if (!empty($info)) { $data = array(); $data['user'] = $info['user']; $data['ip'] = $info['ip']; $data['type'] = $info['type']; $data['sum'] = $info['sum']; $data['modified'] = $this->api->toDate($info['date']); $data['version'] = $info['date']; array_push($versions, $data); } } } return $versions; } else { return array(); } }