/** * clear the page's current background image * * @param array $args arguments * key 'page' is the page (i.e. page.rev) * @return array response */ function page_clear_background_img($args) { if (!isset($args['page'])) { return response('Required argument "page" missing', 400); } if (!page_exists($args['page'])) { return response('Page ' . quot($args['page']) . ' does not exist', 400); } load_modules('glue'); $obj = load_object(array('name' => $args['page'] . '.page')); if ($obj['#error']) { // page object does not exist, hence no background image to clear return response(true); } else { $obj = $obj['#data']; } if (!empty($obj['page-background-file'])) { // delete file delete_upload(array('pagename' => array_shift(expl('.', $args['page'])), 'file' => $obj['page-background-file'], 'max_cnt' => 1)); // and remove attributes return object_remove_attr(array('name' => $obj['name'], 'attr' => array('page-background-file', 'page-background-mime'))); } else { return response(true); } }
/** * Saves data for a given page (creates a new revision) * * If this call succeeds you can assume your data has either been saved or it was * not necessary to save it because the data already existed in the wanted form or * the given schemas are no longer assigned to that page. * * Important: You have to check write permissions for the given page before calling * this function yourself! * * this duplicates a bit of code from entry.php - we could also fake post data and let * entry handle it, but that would be rather unclean and might be problematic when multiple * calls are done within the same request. * * @todo should this try to lock the page? * * * @param string $page * @param array $data ('schema' => ( 'fieldlabel' => 'value', ...)) * @param string $summary * @throws StructException */ public function saveData($page, $data, $summary = '') { $page = cleanID($page); $summary = trim($summary); if (!$summary) { $summary = $this->getLang('summary'); } if (!page_exists($page)) { throw new StructException("Page does not exist. You can not attach struct data"); } // validate and see if anything changes $valid = AccessDataValidator::validateDataForPage($data, $page, $errors); if ($valid === false) { throw new StructException("Validation failed:\n%s", join("\n", $errors)); } if (!$valid) { return; } // empty array when no changes were detected $newrevision = self::createPageRevision($page, $summary); // save the provided data $assignments = new Assignments(); foreach ($valid as $v) { $v->saveData($newrevision); // make sure this schema is assigned $assignments->assignPageSchema($page, $v->getAccessTable()->getSchema()->getTable()); } }
/** * Appends the instruction to render our syntax output component to each page * after the first found headline or the very begining if no headline was found * * @param Doku_Event $event * @param $param */ public function handle_output(Doku_Event $event, $param) { global $ID; if ($this->lastread != $ID) { return; } // avoid nested calls $this->lastread = ''; if (!page_exists($ID)) { return; } $ins = -1; $pos = 0; foreach ($event->data->calls as $num => $call) { // try to find the first header if ($call[0] == 'header') { $pos = $call[2]; $ins = $num; break; } // abort when after we looked at the first 150 bytes if ($call[3] > 150) { break; } } // insert our own call after the found position array_splice($event->data->calls, $ins + 1, 0, array(array('plugin', array('struct_output', array('pos' => $pos), DOKU_LEXER_SPECIAL, ''), $pos))); }
function controller_revisions($args) { page_canonical($args[0][0]); $page = $args[0][0]; if (!page_exists($page)) { hotglue_error(404); } // get all revisions of page and determine the current revision's index load_modules('glue'); $a = expl('.', $page); $revs = revisions_info(array('pagename' => $a[0], 'sort' => 'time')); $revs = $revs['#data']; $cur_rev = false; for ($i = 0; $i < count($revs); $i++) { if ($revs[$i]['revision'] == $a[1]) { $cur_rev = $i; break; } } if ($cur_rev === false) { // we didn't find the current revision hotglue_error(500); } default_html(true); html_add_css(base_url() . 'modules/revisions_browser/revisions_browser.css'); if (USE_MIN_FILES) { html_add_js(base_url() . 'modules/revisions_browser/revisions_browser.min.js'); } else { html_add_js(base_url() . 'modules/revisions_browser/revisions_browser.js'); } html_add_js_var('$.glue.page', $page); $bdy =& body(); elem_attr($bdy, 'id', 'revisions'); render_page(array('page' => $page, 'edit' => false)); body_append('<div id="revisions_browser_ctrl">'); body_append('<div id="revisions_browser_prev">'); if ($cur_rev + 1 < count($revs)) { body_append('<a href="' . base_url() . '?' . htmlspecialchars(urlencode($revs[$cur_rev + 1]['page']), ENT_COMPAT, 'UTF-8') . '/revisions">prev</a>'); } body_append('</div><div id="revisions_browser_cur">'); if (substr($revs[$cur_rev]['revision'], 0, 5) == 'auto-') { body_append(date('d M y H:i', $revs[$cur_rev]['time'])); } else { body_append(htmlspecialchars($revs[$cur_rev]['revision'], ENT_NOQUOTES, 'UTF-8')); } body_append('<br>'); if ($a[1] == 'head') { body_append('<a href="' . base_url() . '?' . htmlspecialchars(urlencode($page), ENT_COMPAT, 'UTF-8') . '/edit">back to editing mode</a>'); } else { body_append('<a id="revisions_browser_revert_btn" href="#">revert</a>'); } body_append('</div><div id="revisions_browser_next">'); if (0 < $cur_rev) { body_append('<a href="' . base_url() . '?' . htmlspecialchars(urlencode($revs[$cur_rev - 1]['page']), ENT_COMPAT, 'UTF-8') . '/revisions">next</a>'); } body_append('</div>'); body_append('</div>'); echo html_finalize(); }
/** * Handle the user input [required] * * @param helper_plugin_bureaucracy_field[] $fields the list of fields in the form * @param string $thanks the thank you message as defined in the form * or default one. Might be modified by the action * before returned * @param array $argv additional arguments passed to the action * @return bool|string false on error, $thanks on success */ public function run($fields, $thanks, $argv) { global $ID; // prepare replacements $this->prepareNamespacetemplateReplacements(); $this->prepareDateTimereplacements(); $this->prepareLanguagePlaceholder(); $this->prepareNoincludeReplacement(); $this->prepareFieldReplacements($fields); //handle arguments $page_to_modify = array_shift($argv); if ($page_to_modify === '_self') { # shortcut to modify the same page as the submitter $page_to_modify = $ID; } else { //resolve against page which contains the form resolve_pageid(getNS($ID), $page_to_modify, $ignored); } $template_section_id = cleanID(array_shift($argv)); if (!page_exists($page_to_modify)) { msg(sprintf($this->getLang('e_pagenotexists'), html_wikilink($page_to_modify)), -1); return false; } // check auth // // This is an important point. In order to be able to modify a page via this method ALL you need is READ access to the page // This is good for admins to be able to only allow people to modify a page via a certain method. If you want to protect the page // from people to WRITE via this method, deny access to the form page. $auth = $this->aclcheck($page_to_modify); // runas if ($auth < AUTH_READ) { msg($this->getLang('e_denied'), -1); return false; } // fetch template $template = rawWiki($page_to_modify); if (empty($template)) { msg(sprintf($this->getLang('e_template'), $page_to_modify), -1); return false; } // do the replacements $template = $this->updatePage($template, $template_section_id); if (!$template) { msg(sprintf($this->getLang('e_failedtoparse'), $page_to_modify), -1); return false; } // save page saveWikiText($page_to_modify, $template, sprintf($this->getLang('summary'), $ID)); //thanks message with redirect $link = wl($page_to_modify); return sprintf($this->getLang('pleasewait'), "<script type='text/javascript' charset='utf-8'>location.replace('{$link}')</script>", html_wikilink($page_to_modify)); }
public function onInitLangLoad(Doku_Event $event, $param = null) { $id = getID(); if (page_exists($id)) { return; } $page = $this->getActivity($id); if ($page instanceof \SimpleXMLElement && $page->attributes()->redirect == 'true' && !empty($page->attributes()->new_id)) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . wl($page->attributes()->new_id)); die; } // else just notify spiders page does not exist 404, instead of 200 header("HTTP/1.1 404 Not Found"); }
/** * Returns an utf8 encoded Namespace for a Page and input Namespace * @param $NS * @param $PAGE */ function getNamespaceFromID($NS, &$PAGE) { global $conf; // Check current page - if its an NS add the startpage $clean = true; resolve_pageid(getNS($NS), $NS, $clean); if (!page_exists($NS) && array_pop(explode(':', $NS)) != strtolower($conf['start'])) { // Compare to lowercase since clean lowers it. $NS .= ':' . $conf['start']; resolve_pageid(getNS($NS), $NS, $clean); } $PAGE = noNS($NS); $NS = getNS($NS); return utf8_encodeFN(str_replace(':', '/', $NS)); }
/** * Create output * * @param string $format Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * @return bool If rendering was successful. */ function render($format, Doku_Renderer $renderer, $data) { if ($format == 'metadata') { return false; } if ($data[0] != DOKU_LEXER_SPECIAL) { return false; } $hlp = plugin_load('helper', 'rating'); $list = $hlp->best($data[1]['lang'], $data[1]['startdate'], 20); if ($data[1]['tag'] == 'ol') { $renderer->listo_open(); } else { $renderer->listu_open(); } $num_items = 0; foreach ($list as $item) { if (auth_aclcheck($item['page'], '', null) < AUTH_READ) { continue; } if (!page_exists($item['page'])) { continue; } $num_items = $num_items + 1; $renderer->listitem_open(1); if (strpos($item['page'], ':') === false) { $item['page'] = ':' . $item['page']; } $renderer->internallink($item['page']); if ($data[1]['score'] === 'true') { $renderer->cdata(' (' . $item['val'] . ')'); } $renderer->listitem_close(); if ($num_items >= 10) { break; } } if ($data[1]['tag'] == 'ol') { $renderer->listo_close(); } else { $renderer->listu_close(); } return true; }
/** * Prints the navigation * * @author Michael Klier <*****@*****.**> */ function tpl_navigation() { global $ID; global $conf; $navpage = tpl_getConf('navigation_page'); print '<div class="navigation">' . DOKU_LF; if (!page_exists($navpage)) { if (@file_exists(DOKU_TPLINC . 'lang/' . $conf['lang'] . '/nonavigation.txt')) { $out = p_render('xhtml', p_get_instructions(io_readFile(DOKU_TPLINC . 'lang/' . $conf['lang'] . '/nonavigation.txt')), $info); } else { $out = p_render('xhtml', p_get_instructions(io_readFile(DOKU_TPLINC . 'lang/en/nonavigation.txt')), $info); } $link = '<a href="' . wl($navpage) . '" class="wikilink2">' . $navpage . '</a>' . DOKU_LF; print str_replace('LINK', $link, $out); } else { print p_wiki_xhtml($navpage); } print '</div>'; }
/** * Alters login page via HTML_LOGINFORM_OUTPUT event * @param $event * @param $param */ public function alterLoginPageBefore($event, $param) { print '<div class="login container">' . NL; $helpId = $this->getConf(self::CONF_HELP_PAGE); global $conf; if (!empty($conf['lang'])) { $lang = $conf['lang']; if (!empty($conf['plugin']['translation']['translations']) && preg_match("/{$lang}/", $conf['plugin']['translation']['translations'])) { $helpId = ':' . $lang . $helpId; } } if (page_exists($helpId)) { print '<div class="login help">' . p_wiki_xhtml($helpId) . '</div>' . NL; } if (!empty($this->getConf(self::CONF_RENAME_LOCAL))) { /** @var Doku_Form $form */ $form = $event->data; $form->_content[0]['_legend'] = $this->getLang('login_local'); } }
function handle() { if (!isset($_REQUEST['data_go']) || !checkSecurityToken()) { return; } $sqlite = $this->dthlp->_getDB(); if (!$sqlite) { return false; } $res = $sqlite->query("SELECT pid, page FROM pages"); $rows = $sqlite->res2arr($res); $count = 0; foreach ($rows as $row) { if (!page_exists($row['page'])) { $sqlite->query('DELETE FROM data WHERE pid = ?', $row['pid']); $sqlite->query('DELETE FROM pages WHERE pid = ?', $row['pid']); $count++; } } msg(sprintf($this->getLang('pages_del'), $count), 1); }
function driver_getRecommendation($lastJump) { $currentPage = $lastJump['page']; if (isset($lastJump['section'])) { $currentPage = $lastJump['page'] . '#' . sectionId($lastJump['section']) . '=' . $lastJump['section']; } $output = ''; $output .= '<div id=driver_recommendation class=driver_rbox>'; //$output .= '<table class=driver_rbox_table>'; //$output .= '<tr><td class=driver_rbox_table_title_column>Try these...</td></tr>'; //$output .= '<tr><td class=driver_rbox_table_column >'; if (!page_exists($currentPage)) { $output .= '<div align="center" style="font-style:italic"> nowhere yet...</div>'; $output .= '</div>'; return $output; } error_log("currentPage: " . print_r($currentPage, true)); $recommend = driverdb_getMostNextSteps($currentPage); error_log("recommend: " . print_r($recommend, true)); foreach ($recommend as $page => $count) { unset($trailPage); // is it section? $pageParts = explode("#", $page); if (sizeof($pageParts) > 1) { //its section, then parse title $sectionParts = explode("=", $pageParts[1]); $trailPage['section'] = $sectionParts[1]; } $trailPage['id'] = $pageParts[0]; $trailPage['name'] = trimPageTitle(get_first_heading($pageParts[0]), 40); $output .= printTrailPage($trailPage, '_parent', '', '', 'trail_page_recommend', $count); } //$output .= '</td></tr>'; //$output .='</table>'; $output .= '</div>'; return $output; }
/** * Check if the given page can be moved to the given destination * * @param $src * @param $dst * @return bool */ public function checkPage($src, $dst) { // Check we have rights to move this document if (!page_exists($src)) { msg(sprintf($this->getLang('notexist'), $src), -1); return false; } if (auth_quickaclcheck($src) < AUTH_EDIT) { msg(sprintf($this->getLang('norights'), $src), -1); return false; } // Check file is not locked // checklock checks if the page lock hasn't expired and the page hasn't been locked by another user // the file exists check checks if the page is reported unlocked if a lock exists which means that // the page is locked by the current user if (checklock($src) !== false || @file_exists(wikiLockFN($src))) { msg(sprintf($this->getLang('filelocked'), $src), -1); return false; } // Has the document name and/or namespace changed? if ($src == $dst) { msg(sprintf($this->getLang('notchanged'), $src), -1); return false; } // Check the page does not already exist if (page_exists($dst)) { msg(sprintf($this->getLang('exists'), $src, $dst), -1); return false; } // Check if the current user can create the new page if (auth_quickaclcheck($dst) < AUTH_CREATE) { msg(sprintf($this->getLang('notargetperms'), $dst), -1); return false; } return true; }
/** * Handles the AJAX calls * * @author Michael Klier <*****@*****.**> */ function handle_ajax_call(&$event, $param) { global $lang; if ($event->data == 'snippet_preview' or $event->data == 'snippet_insert') { $event->preventDefault(); $event->stopPropagation(); $id = cleanID($_REQUEST['id']); if (page_exists($id)) { if ($event->data == 'snippet_preview') { if (auth_quickaclcheck($id) >= AUTH_READ) { print p_wiki_xhtml($id); } else { print p_locale_xhtml('denied'); } } elseif ($event->data == 'snippet_insert') { if (auth_quickaclcheck($id) >= AUTH_READ) { print "\n\n"; // always start on a new line (just to be safe) print trim(preg_replace('/<snippet>.*?<\\/snippet>/s', '', io_readFile(wikiFN($id)))); } } } } }
/** * Adds/updates the search index for the given page * * Locking is handled internally. * * @param string $page name of the page to index * @param boolean $verbose print status messages * @param boolean $force force reindexing even when the index is up to date * @return boolean the function completed successfully * @author Tom N Harris <*****@*****.**> */ function enhanced_idx_addPage($page, $verbose = false, $force = false) { $idxtag = metaFN($page, '.indexed'); // check if page was deleted but is still in the index if (!page_exists($page)) { if (!@file_exists($idxtag)) { if ($verbose) { print "Indexer: {$page} does not exist, ignoring" . DOKU_LF; } return false; } $Indexer = enhanced_idx_get_indexer(); $result = $Indexer->deletePage($page); if ($result === "locked") { if ($verbose) { print "Indexer: locked" . DOKU_LF; } return false; } @unlink($idxtag); return $result; } // check if indexing needed if (!$force && @file_exists($idxtag)) { if (trim(io_readFile($idxtag)) == idx_get_version()) { $last = @filemtime($idxtag); if ($last > @filemtime(wikiFN($page))) { if ($verbose) { print "Indexer: index for {$page} up to date" . DOKU_LF; } return false; } } } $indexenabled = p_get_metadata($page, 'internal index', METADATA_RENDER_UNLIMITED); if ($indexenabled === false) { $result = false; if (@file_exists($idxtag)) { $Indexer = enhanced_idx_get_indexer(); $result = $Indexer->deletePage($page); if ($result === "locked") { if ($verbose) { print "Indexer: locked" . DOKU_LF; } return false; } @unlink($idxtag); } if ($verbose) { print "Indexer: index disabled for {$page}" . DOKU_LF; } return $result; } $Indexer = enhanced_idx_get_indexer(); $pid = $Indexer->getPID($page); if ($pid === false) { if ($verbose) { print "Indexer: getting the PID failed for {$page}" . DOKU_LF; } return false; } $body = ''; $metadata = array(); $metadata['title'] = p_get_metadata($page, 'title', METADATA_RENDER_UNLIMITED); if (($references = p_get_metadata($page, 'relation references', METADATA_RENDER_UNLIMITED)) !== null) { $metadata['relation_references'] = array_keys($references); } else { $metadata['relation_references'] = array(); } if (($media = p_get_metadata($page, 'relation media', METADATA_RENDER_UNLIMITED)) !== null) { $metadata['relation_media'] = array_keys($media); } else { $metadata['relation_media'] = array(); } $data = compact('page', 'body', 'metadata', 'pid'); $evt = new Doku_Event('INDEXER_PAGE_ADD', $data); if ($evt->advise_before()) { $data['body'] = $data['body'] . " " . rawWiki($page); } $evt->advise_after(); unset($evt); extract($data); $result = $Indexer->addPageWords($page, $body); if ($result === "locked") { if ($verbose) { print "Indexer: locked" . DOKU_LF; } return false; } if ($result) { $result = $Indexer->addMetaKeys($page, $metadata); if ($result === "locked") { if ($verbose) { print "Indexer: locked" . DOKU_LF; } return false; } } if ($result) { io_saveFile(metaFN($page, '.indexed'), idx_get_version()); } if ($verbose) { print "Indexer: finished" . DOKU_LF; return true; } return $result; }
/** * list old revisions * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> * @author Kate Arzamastseva <*****@*****.**> */ function html_revisions($first = 0, $media_id = false) { global $ID; global $INFO; global $conf; global $lang; $id = $ID; /* we need to get one additionally log entry to be able to * decide if this is the last page or is there another one. * see html_recent() */ if (!$media_id) { $revisions = getRevisions($ID, $first, $conf['recent'] + 1); } else { $revisions = getRevisions($media_id, $first, $conf['recent'] + 1, 8192, true); $id = $media_id; } if (count($revisions) == 0 && $first != 0) { $first = 0; if (!$media_id) { $revisions = getRevisions($ID, $first, $conf['recent'] + 1); } else { $revisions = getRevisions($media_id, $first, $conf['recent'] + 1, 8192, true); } } $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'); 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)); } 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($id); $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')); } $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if (!$media_id) { $editor = $INFO['editor']; } else { $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); if ($revinfo['user']) { $editor = $revinfo['user']; } else { $editor = $revinfo['ip']; } } $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); if (!$media_id) { $info = getRevisionInfo($id, $rev, true); $exists = page_exists($id, $rev); } else { $info = getRevisionInfo($id, $rev, true, true); $exists = @file_exists(mediaFN($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($id); $form->addElement(form_makeCloseTag('a')); } else { $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); $form->addElement($id); } 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(htmlspecialchars($info['sum'])); $form->addElement(form_makeCloseTag('span')); } $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if ($info['user']) { $form->addElement(editorinfo($info['user'])); if (auth_ismanager()) { $form->addElement(' (' . $info['ip'] . ')'); } } else { $form->addElement($info['ip']); } $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>'; }
function _ft_pageLookup(&$data) { // split out original parameters $id = $data['id']; if (preg_match('/(?:^| )@(\\w+)/', $id, $matches)) { $ns = cleanID($matches[1]) . ':'; $id = str_replace($matches[0], '', $id); } $in_ns = $data['in_ns']; $in_title = $data['in_title']; $cleaned = cleanID($id); $Indexer = idx_get_indexer(); $page_idx = $Indexer->getPages(); $pages = array(); if ($id !== '' && $cleaned !== '') { foreach ($page_idx as $p_id) { if (strpos($in_ns ? $p_id : noNSorNS($p_id), $cleaned) !== false) { if (!isset($pages[$p_id])) { $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); } } } if ($in_title) { foreach ($Indexer->lookupKey('title', $id, '_ft_pageLookupTitleCompare') as $p_id) { if (!isset($pages[$p_id])) { $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); } } } } if (isset($ns)) { foreach (array_keys($pages) as $p_id) { if (strpos($p_id, $ns) !== 0) { unset($pages[$p_id]); } } } // discard hidden pages // discard nonexistent pages // check ACL permissions foreach (array_keys($pages) as $idx) { if (!isVisiblePage($idx) || !page_exists($idx) || auth_quickaclcheck($idx) < AUTH_READ) { unset($pages[$idx]); } } uksort($pages, 'ft_pagesorter'); return $pages; }
/** * returns the metadata of a page * * @param string $id The id of the page the metadata should be returned from * @param string $key The key of the metdata value that shall be read (by default everything) - separate hierarchies by " " like "date created" * @param int $render If the page should be rendererd - possible values: * METADATA_DONT_RENDER, METADATA_RENDER_USING_SIMPLE_CACHE, METADATA_RENDER_USING_CACHE * METADATA_RENDER_UNLIMITED (also combined with the previous two options), * default: METADATA_RENDER_USING_CACHE * @return mixed The requested metadata fields * * @author Esther Brunner <*****@*****.**> * @author Michael Hamann <*****@*****.**> */ function p_get_metadata($id, $key = '', $render = METADATA_RENDER_USING_CACHE) { global $ID; static $render_count = 0; // track pages that have already been rendered in order to avoid rendering the same page // again static $rendered_pages = array(); // cache the current page // Benchmarking shows the current page's metadata is generally the only page metadata // accessed several times. This may catch a few other pages, but that shouldn't be an issue. $cache = $ID == $id; $meta = p_read_metadata($id, $cache); if (!is_numeric($render)) { if ($render) { $render = METADATA_RENDER_USING_SIMPLE_CACHE; } else { $render = METADATA_DONT_RENDER; } } // prevent recursive calls in the cache static $recursion = false; if (!$recursion && $render != METADATA_DONT_RENDER && !isset($rendered_pages[$id]) && page_exists($id)) { $recursion = true; $cachefile = new cache_renderer($id, wikiFN($id), 'metadata'); $do_render = false; if ($render & METADATA_RENDER_UNLIMITED || $render_count < P_GET_METADATA_RENDER_LIMIT) { if ($render & METADATA_RENDER_USING_SIMPLE_CACHE) { $pagefn = wikiFN($id); $metafn = metaFN($id, '.meta'); if (!@file_exists($metafn) || @filemtime($pagefn) > @filemtime($cachefile->cache)) { $do_render = true; } } elseif (!$cachefile->useCache()) { $do_render = true; } } if ($do_render) { ++$render_count; $rendered_pages[$id] = true; $old_meta = $meta; $meta = p_render_metadata($id, $meta); // only update the file when the metadata has been changed if ($meta == $old_meta || p_save_metadata($id, $meta)) { // store a timestamp in order to make sure that the cachefile is touched $cachefile->storeCache(time()); } elseif ($meta != $old_meta) { msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.', -1); } } $recursion = false; } $val = $meta['current']; // filter by $key foreach (preg_split('/\\s+/', $key, 2, PREG_SPLIT_NO_EMPTY) as $cur_key) { if (!isset($val[$cur_key])) { return null; } $val = $val[$cur_key]; } return $val; }
/** * Gives a list of pages for a given include statement * * @author Michael Hamann <*****@*****.**> */ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { global $conf; $pages = array(); switch($mode) { case 'namespace': $page = cleanID($page); $ns = utf8_encodeFN(str_replace(':', '/', $page)); // depth is absolute depth, not relative depth, but 0 has a special meaning. $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0; search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth), $ns); if (is_array($pagearrays)) { foreach ($pagearrays as $pagearray) { if (!isHiddenPage($pagearray['id'])) // skip hidden pages $pages[] = $pagearray['id']; } } break; case 'tagtopic': if (!$this->taghelper) $this->taghelper =& plugin_load('helper', 'tag'); if(!$this->taghelper) { msg('You have to install the tag plugin to use this functionality!', -1); return array(); } $tag = $page; $sect = ''; $pagearrays = $this->taghelper->getTopic('', null, $tag); foreach ($pagearrays as $pagearray) { $pages[] = $pagearray['id']; } break; default: $page = $this->_apply_macro($page); resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID if (auth_quickaclcheck($page) >= AUTH_READ) $pages[] = $page; } if (count($pages) > 1) { if ($flags['order'] === 'id') { if ($flags['rsort']) { usort($pages, array($this, '_r_strnatcasecmp')); } else { natcasesort($pages); } } else { $ordered_pages = array(); foreach ($pages as $page) { $key = ''; switch ($flags['order']) { case 'title': $key = p_get_first_heading($page); break; case 'created': $key = p_get_metadata($page, 'date created', METADATA_DONT_RENDER); break; case 'modified': $key = p_get_metadata($page, 'date modified', METADATA_DONT_RENDER); break; case 'indexmenu': $key = p_get_metadata($page, 'indexmenu_n', METADATA_RENDER_USING_SIMPLE_CACHE); if ($key === null) $key = ''; break; case 'custom': $key = p_get_metadata($page, 'include_n', METADATA_RENDER_USING_SIMPLE_CACHE); if ($key === null) $key = ''; break; } $key .= '_'.$page; $ordered_pages[$key] = $page; } if ($flags['rsort']) { uksort($ordered_pages, array($this, '_r_strnatcasecmp')); } else { uksort($ordered_pages, 'strnatcasecmp'); } $pages = $ordered_pages; } } $result = array(); foreach ($pages as $page) { $exists = page_exists($page); $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id); } return $result; }
/** * Adds all pages of a specific namespace to the pages array. * * @param pages pre-initialised pages array. * @param ns Namespace in which to look for pages. * @param depth Search depth. * @param use_first_header (optional) Includes the first header as page title. */ function get_pages(&$pages, $ns, $depth = 0, $use_first_header = false) { global $conf; // find pages $search_results = array(); search($search_results, $conf['datadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => true, 'meta' => true), str_replace(':', '/', $ns)); // Start page of the namespace if ($ns && page_exists($ns)) { // Add to the search results $search_results[] = array('id' => $ns, 'ns' => getNS($ns), 'title' => p_get_first_heading($ns, false), 'size' => filesize(wikiFN($ns)), 'mtime' => filemtime(wikiFN($ns)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1); } // loop through the pages while ($item = array_shift($search_results)) { // Check that the user is allowed to read the page if (auth_quickaclcheck($item['id']) > AUTH_READ) { continue; } // Check that the user is allowed to read the page if (auth_quickaclcheck($item['ns']) > AUTH_READ) { continue; } // Get the create time $time = (int) p_get_metadata($item['id'], 'date created', false); if (!$time) { $time = $item['mtime']; } // Get specific language part $lang = $transplugin ? $transplugin->getLangPart($item['id']) : ''; if ($lang) { $item['ns'] = preg_replace('/^' . $lang . '(:|$)/', '', $item['ns']); } if ($use_first_header) { $title = $item['title']; } else { // Use the last part of the id for the name $title = ucwords(substr(strrchr(strtr($item['id'], '_', ' '), ':'), 1)); } // Add the page to the page list $pages[$item['id']] = array('title' => $title, 'ns' => $item['ns'], 'size' => $item['size'], 'time' => $time, 'links' => array(), 'media' => array(), 'lang' => $lang); } }
/** * Check visibility of the page * * @param string $id the page id * @param string $ns the namespace authorized * @return bool if the page is hidden */ function _notVisible($id, $ns = "") { if (isHiddenPage($id)) { return true; } // discard hidden pages // discard if user can't read if (auth_quickaclcheck($id) < AUTH_READ) { return true; } // filter by namespace, root namespace is identified with a dot if ($ns == '.') { // root namespace is specified, discard all pages who lay outside the root namespace if (getNS($id) != false) { return true; } } else { // ("!==0" namespace found at position 0) if ($ns && strpos(':' . getNS($id) . ':', ':' . $ns . ':') !== 0) { return true; } } return !page_exists($id, '', false); }
/** * returns the metadata of a page * * @author Esther Brunner <*****@*****.**> */ function p_get_metadata($id, $key = '', $render = false) { global $ID, $INFO, $cache_metadata; // cache the current page // Benchmarking shows the current page's metadata is generally the only page metadata // accessed several times. This may catch a few other pages, but that shouldn't be an issue. $cache = $ID == $id; $meta = p_read_metadata($id, $cache); // metadata has never been rendered before - do it! (but not for non-existent pages) if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)) { $meta = p_render_metadata($id, $meta); io_saveFile(metaFN($id, '.meta'), serialize($meta)); // sync cached copies, including $INFO metadata if (!empty($cache_metadata[$id])) { $cache_metadata[$id] = $meta; } if (!empty($INFO) && $id == $INFO['id']) { $INFO['meta'] = $meta['current']; } } $val = $meta['current']; // filter by $key foreach (preg_split('/\\s+/', $key, 2, PREG_SPLIT_NO_EMPTY) as $cur_key) { if (!isset($val[$cur_key])) { return null; } $val = $val[$cur_key]; } return $val; }
/** * Returns a list of documents and counts from a index line * * It omits docs with a count of 0 and pages that no longer * exist. * * @param array $page_idx The list of known pages * @param string $line A line from the main index * @author Andreas Gohr <*****@*****.**> */ function idx_parseIndexLine(&$page_idx, $line) { $result = array(); $line = trim($line); if ($line == '') { return $result; } $parts = explode(':', $line); foreach ($parts as $part) { if ($part == '') { continue; } list($doc, $cnt) = explode('*', $part); if (!$cnt) { continue; } $doc = trim($page_idx[$doc]); if (!$doc) { continue; } // make sure the document still exists if (!page_exists($doc, '', false)) { continue; } $result[$doc] = $cnt; } return $result; }
/** * searches for namespace sidebars * * @author Michael Klier <*****@*****.**> */ function _getNsSb($id) { $pname = tpl_getConf('pagename'); $ns_sb = ''; $path = explode(':', $id); $found = false; while (count($path) > 0) { $ns_sb = implode(':', $path) . ':' . $pname; if (@page_exists($ns_sb)) { return $ns_sb; } array_pop($path); } // nothing found return false; }
function _exportPostcontent($exporter) { global $ID, $INFO, $REV, $conf; $exporter->setParameters('Article: ' . $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), $this->_getDokuUrl(), $this->_getDokuUrl() . 'doku.php?', 'utf-8', $this->agentlink); // create user object // $id, $uri, $name, $email, $homepage='', $foaf_uri='', $role=false, $nick='', $sioc_url='', $foaf_url='' $dwuserpage_id = cleanID($this->getConf('userns')) . ($conf['useslash'] ? '/' : ':') . $INFO['editor']; /* if ($INFO['editor'] && $this->getConf('userns')) $pageuser = new SIOCUser($INFO['editor'], normalizeUri(getAbsUrl(exportlink($dwuserpage_id, 'siocxml', array('type'=>'user'), false, '&'))), // user page $INFO['meta']['contributor'][$INFO['editor']], getDwUserInfo($dwuserpage_id,$this,'mail'), '', // no homepage is saved for dokuwiki user '#'.$INFO['editor'], // local uri false, // no roles right now '', // no nick name is saved for dokuwiki user normalizeUri($exporter->siocURL('user', $dwuserpage_id)) ); */ // create wiki page object $wikipage = new SIOCDokuWikiArticle($ID, normalizeUri($exporter->siocURL('post', $ID . ($REV ? $exporter->_urlseparator . 'rev' . $exporter->_urlequal . $REV : ''))), $INFO['meta']['title'] . ($REV ? ' (rev ' . $REV . ')' : ''), rawWiki($ID, $REV)); /* encoded content */ $wikipage->addContentEncoded(p_cached_output(wikiFN($ID, $REV), 'xhtml')); /* created */ if (isset($INFO['meta']['date']['created'])) { $wikipage->addCreated(date('c', $INFO['meta']['date']['created'])); } /* or modified */ if (isset($INFO['meta']['date']['modified'])) { $wikipage->addModified(date('c', $INFO['meta']['date']['modified'])); } /* creator/modifier */ if ($INFO['editor'] && $this->getConf('userns')) { $wikipage->addCreator(array('foaf:maker' => '#' . $INFO['editor'], 'sioc:modifier' => $dwuserpage_id)); } /* is creator */ if (isset($INFO['meta']['date']['created'])) { $wikipage->isCreator(); } /* intern wiki links */ $wikipage->addLinks($INFO['meta']['relation']['references']); // contributors - only for last revision b/c of wrong meta data for older revisions if (!$REV && $this->getConf('userns') && isset($INFO['meta']['contributor'])) { $cont_temp = array(); $cont_ns = $this->getConf('userns') . ($conf['useslash'] ? '/' : ':'); foreach ($INFO['meta']['contributor'] as $cont_id => $cont_name) { $cont_temp[$cont_ns . $cont_id] = $cont_name; } $wikipage->addContributors($cont_temp); } // backlinks - only for last revision if (!$REV) { require_once DOKU_INC . 'inc/fulltext.php'; $backlinks = ft_backlinks($ID); if (count($backlinks) > 0) { $wikipage->addBacklinks($backlinks); } } // TODO: addLinksExtern /* previous and next revision */ $changelog = new PageChangeLog($ID); $pagerevs = $changelog->getRevisions(0, $conf['recent'] + 1); $prevrev = false; $nextrev = false; if (!$REV) { // latest revision, previous rev is on top in array $prevrev = 0; } else { // other revision $currentrev = array_search($REV, $pagerevs); if ($currentrev !== false) { $prevrev = $currentrev + 1; $nextrev = $currentrev - 1; } } if ($prevrev !== false && $prevrev > -1 && page_exists($ID, $pagerevs[$prevrev])) { /* previous revision*/ $wikipage->addVersionPrevious($pagerevs[$prevrev]); } if ($nextrev !== false && $nextrev > -1 && page_exists($ID, $pagerevs[$nextrev])) { /* next revision*/ $wikipage->addVersionNext($pagerevs[$nextrev]); } /* latest revision */ if ($REV) { $wikipage->addVersionLatest(); } // TODO: topics /* has_container */ if ($INFO['namespace']) { $wikipage->addContainer($INFO['namespace']); } /* has_space */ if ($this->getConf('owners')) { $wikipage->addSite($this->getConf('owners')); } // TODO: dc:contributor / has_modifier // TODO: attachment (e.g. pictures in that dwns) // add wiki page to exporter $exporter->addObject($wikipage); //if ($INFO['editor'] && $this->getConf('userns')) $exporter->addObject($pageuser); return $exporter; }
/** * Find pages in the fulltext index containing the words, * * The search words must be pre-tokenized, meaning only letters and * numbers with an optional wildcard * * The returned array will have the original tokens as key. The values * in the returned list is an array with the page names as keys and the * number of times that token appears on the page as value. * * @param array $tokens list of words to search for * @return array list of page names with usage counts * @author Tom N Harris <*****@*****.**> * @author Andreas Gohr <*****@*****.**> */ public function lookup(&$tokens) { $result = array(); $wids = $this->getIndexWords($tokens, $result); if (empty($wids)) { return array(); } // load known words and documents $page_idx = $this->getIndex('page', ''); $docs = array(); foreach (array_keys($wids) as $wlen) { $wids[$wlen] = array_unique($wids[$wlen]); $index = $this->getIndex('i', $wlen); foreach ($wids[$wlen] as $ixid) { if ($ixid < count($index)) { $docs["{$wlen}*{$ixid}"] = $this->parseTuples($page_idx, $index[$ixid]); } } } // merge found pages into final result array $final = array(); foreach ($result as $word => $res) { $final[$word] = array(); foreach ($res as $wid) { // handle the case when ($ixid < count($index)) has been false // and thus $docs[$wid] hasn't been set. if (!isset($docs[$wid])) { continue; } $hits =& $docs[$wid]; foreach ($hits as $hitkey => $hitcnt) { // make sure the document still exists if (!page_exists($hitkey, '', false)) { continue; } if (!isset($final[$word][$hitkey])) { $final[$word][$hitkey] = $hitcnt; } else { $final[$word][$hitkey] += $hitcnt; } } } } return $final; }
/** * Save a wiki page * * @author Michael Klier <*****@*****.**> */ function putPage($id, $text, $params) { global $TEXT; global $lang; $id = $this->resolvePageId($id); $TEXT = cleanText($text); $sum = $params['sum']; $minor = $params['minor']; if (empty($id)) { throw new RemoteException('Empty page ID', 131); } if (!page_exists($id) && trim($TEXT) == '') { throw new RemoteException('Refusing to write an empty new wiki page', 132); } if (auth_quickaclcheck($id) < AUTH_EDIT) { throw new RemoteAccessDeniedException('You are not allowed to edit this page', 112); } // Check, if page is locked if (checklock($id)) { throw new RemoteException('The page is currently locked', 133); } // SPAM check if (checkwordblock()) { throw new RemoteException('Positive wordblock check', 134); } // autoset summary on new pages if (!page_exists($id) && empty($sum)) { $sum = $lang['created']; } // autoset summary on deleted pages if (page_exists($id) && empty($TEXT) && empty($sum)) { $sum = $lang['deleted']; } lock($id); saveWikiText($id, $TEXT, $sum, $minor); unlock($id); // run the indexer if page wasn't indexed yet idx_addPage($id); return 0; }
function _ft_pageLookup(&$data) { // split out original parameterrs $id = $data['id']; $pageonly = $data['pageonly']; global $conf; $id = preg_quote($id, '/'); $pages = file($conf['indexdir'] . '/page.idx'); if ($id) { $pages = array_values(preg_grep('/' . $id . '/', $pages)); } $cnt = count($pages); for ($i = 0; $i < $cnt; $i++) { if ($pageonly) { if (!preg_match('/' . $id . '/', noNS($pages[$i]))) { unset($pages[$i]); continue; } } if (!page_exists($pages[$i])) { unset($pages[$i]); continue; } } $pages = array_filter($pages, 'isVisiblePage'); // discard hidden pages if (!count($pages)) { return array(); } // check ACL permissions foreach (array_keys($pages) as $idx) { if (auth_quickaclcheck(trim($pages[$idx])) < AUTH_READ) { unset($pages[$idx]); } } $pages = array_map('trim', $pages); usort($pages, 'ft_pagesorter'); return $pages; }
/** * Returns a full page id * * @author Andreas Gohr <*****@*****.**> */ function resolve_pageid($ns, &$page, &$exists) { global $conf; $exists = false; //keep hashlink if exists then clean both parts if (strpos($page, '#')) { list($page, $hash) = explode('#', $page, 2); } else { $hash = ''; } $hash = cleanID($hash); $page = resolve_id($ns, $page, false); // resolve but don't clean, yet // get filename (calls clean itself) $file = wikiFN($page); // if ends with colon or slash we have a namespace link if (in_array(substr($page, -1), array(':', ';')) || $conf['useslash'] && substr($page, -1) == '/') { if (page_exists($page . $conf['start'])) { // start page inside namespace $page = $page . $conf['start']; $exists = true; } elseif (page_exists($page . noNS(cleanID($page)))) { // page named like the NS inside the NS $page = $page . noNS(cleanID($page)); $exists = true; } elseif (page_exists($page)) { // page like namespace exists $page = $page; $exists = true; } else { // fall back to default $page = $page . $conf['start']; } } else { //check alternative plural/nonplural form if (!@file_exists($file)) { if ($conf['autoplural']) { if (substr($page, -1) == 's') { $try = substr($page, 0, -1); } else { $try = $page . 's'; } if (page_exists($try)) { $page = $try; $exists = true; } } } else { $exists = true; } } // now make sure we have a clean page $page = cleanID($page); //add hash if any if (!empty($hash)) { $page .= '#' . $hash; } }
/** * Find a page in the current namespace (determined from $ID) or any * higher namespace * * Used for sidebars, but can be used other stuff as well * * @todo add event hook * @param string $page the pagename you're looking for * @return string|false the full page id of the found page, false if any */ function page_findnearest($page) { if (!$page) { return false; } global $ID; $ns = $ID; do { $ns = getNS($ns); $pageid = ltrim("{$ns}:{$page}", ':'); if (page_exists($pageid)) { return $pageid; } } while ($ns); return false; }