function test_parameters() { saveWikiText('test:links', '[[wiki:syntax?do=export_raw]] [[:web:scripts:add_vhost.sh?do=export_raw]]', 'Init tests'); idx_addPage('test:links'); $this->assertEquals(array('test:links'), ft_backlinks('wiki:syntax')); $this->assertEquals(array('test:links'), ft_backlinks('web:scripts:add_vhost.sh')); }
public function test_safeindex() { global $conf; global $AUTH_ACL; $conf['superuser'] = '******'; $conf['useacl'] = 1; $AUTH_ACL = array('* @ALL 0', '* @user 8', 'public @ALL 1'); $_SERVER['REMOTE_USER'] = '******'; saveWikiText('parent', "{{page>child}}\n\n[[public_link]]\n\n{{page>public}}", 'Test parent created'); saveWikiText('child', "[[foo:private]]", 'Test child created'); saveWikiText('public', "[[foo:public]]", 'Public page created'); idx_addPage('parent'); idx_addPage('child'); idx_addPage('public'); $this->assertEquals(array('parent', 'public'), ft_backlinks('foo:public')); $this->assertEquals(array('child'), ft_backlinks('foo:private')); $this->assertEquals(array('parent'), ft_backlinks('public_link')); }
/** * display backlinks * * @author Andreas Gohr <*****@*****.**> * @author Michael Klier <*****@*****.**> */ function html_backlinks() { global $ID; global $conf; global $lang; print p_locale_xhtml('backlinks'); $data = ft_backlinks($ID); if (!empty($data)) { print '<ul class="idx">'; foreach ($data as $blink) { print '<li><div class="li">'; print html_wikilink(':' . $blink, useHeading('navigation') ? null : $blink); print '</div></li>'; } print '</ul>'; } else { print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; } }
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; }
/** * Return a list of backlinks */ function listBackLinks($id) { return ft_backlinks($this->resolvePageId($id)); }
/** * Saves a wikitext by calling io_writeWikiPage. * Also directs changelog and attic updates. * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> */ function saveWikiText($id, $text, $summary, $minor = false) { /* Note to developers: This code is subtle and delicate. Test the behavior of the attic and changelog with dokuwiki and external edits after any changes. External edits change the wiki page directly without using php or dokuwiki. */ global $conf; global $lang; global $REV; // ignore if no changes were made if ($text == rawWiki($id, '')) { return; } $file = wikiFN($id); $old = @filemtime($file); // from page $wasRemoved = trim($text) == ''; // check for empty or whitespace only $wasCreated = !@file_exists($file); $wasReverted = $REV == true; $newRev = false; $oldRev = getRevisions($id, -1, 1, 1024); // from changelog $oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]); if (!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) { // add old revision to the attic if missing saveOldRevision($id); // add a changelog entry if this edit came from outside dokuwiki if ($old > $oldRev) { addLogEntry($old, $id, DOKU_CHANGE_TYPE_EDIT, $lang['external_edit'], '', array('ExternalEdit' => true)); // remove soon to be stale instructions $cache = new cache_instructions($id, $file); $cache->removeCache(); } } if ($wasRemoved) { // Send "update" event with empty data, so plugins can react to page deletion $data = array(array($file, '', false), getNS($id), noNS($id), false); trigger_event('IO_WIKIPAGE_WRITE', $data); // pre-save deleted revision @touch($file); clearstatcache(); $newRev = saveOldRevision($id); // remove empty file @unlink($file); // don't remove old meta info as it should be saved, plugins can use IO_WIKIPAGE_WRITE for removing their metadata... // purge non-persistant meta data p_purge_metadata($id); $del = true; // autoset summary on deletion if (empty($summary)) { $summary = $lang['deleted']; } // remove empty namespaces io_sweepNS($id, 'datadir'); io_sweepNS($id, 'mediadir'); } else { // save file (namespace dir is created in io_writeWikiPage) io_writeWikiPage($file, $text, $id); // pre-save the revision, to keep the attic in sync $newRev = saveOldRevision($id); $del = false; } // select changelog line type $extra = ''; $type = DOKU_CHANGE_TYPE_EDIT; if ($wasReverted) { $type = DOKU_CHANGE_TYPE_REVERT; $extra = $REV; } else { if ($wasCreated) { $type = DOKU_CHANGE_TYPE_CREATE; } else { if ($wasRemoved) { $type = DOKU_CHANGE_TYPE_DELETE; } else { if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; } } } } //minor edits only for logged in users addLogEntry($newRev, $id, $type, $summary, $extra); // send notify mails notify($id, 'admin', $old, $summary, $minor); notify($id, 'subscribers', $old, $summary, $minor); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
/** * Saves a wikitext by calling io_writeWikiPage. * Also directs changelog and attic updates. * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> * * @param string $id page id * @param string $text wikitext being saved * @param string $summary summary of text update * @param bool $minor mark this saved version as minor update */ function saveWikiText($id, $text, $summary, $minor = false) { /* Note to developers: This code is subtle and delicate. Test the behavior of the attic and changelog with dokuwiki and external edits after any changes. External edits change the wiki page directly without using php or dokuwiki. */ global $conf; global $lang; global $REV; /* @var Input $INPUT */ global $INPUT; // prepare data for event $svdta = array(); $svdta['id'] = $id; $svdta['file'] = wikiFN($id); $svdta['revertFrom'] = $REV; $svdta['oldRevision'] = @filemtime($svdta['file']); $svdta['newRevision'] = 0; $svdta['newContent'] = $text; $svdta['oldContent'] = rawWiki($id); $svdta['summary'] = $summary; $svdta['contentChanged'] = $svdta['newContent'] != $svdta['oldContent']; $svdta['changeInfo'] = ''; $svdta['changeType'] = DOKU_CHANGE_TYPE_EDIT; $svdta['sizechange'] = null; // select changelog line type if ($REV) { $svdta['changeType'] = DOKU_CHANGE_TYPE_REVERT; $svdta['changeInfo'] = $REV; } else { if (!file_exists($svdta['file'])) { $svdta['changeType'] = DOKU_CHANGE_TYPE_CREATE; } else { if (trim($text) == '') { // empty or whitespace only content deletes $svdta['changeType'] = DOKU_CHANGE_TYPE_DELETE; // autoset summary on deletion if (blank($svdta['summary'])) { $svdta['summary'] = $lang['deleted']; } } else { if ($minor && $conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { //minor edits only for logged in users $svdta['changeType'] = DOKU_CHANGE_TYPE_MINOR_EDIT; } } } } $event = new Doku_Event('COMMON_WIKIPAGE_SAVE', $svdta); if (!$event->advise_before()) { return; } // if the content has not been changed, no save happens (plugins may override this) if (!$svdta['contentChanged']) { return; } detectExternalEdit($id); if ($svdta['changeType'] == DOKU_CHANGE_TYPE_CREATE || $svdta['changeType'] == DOKU_CHANGE_TYPE_REVERT && !file_exists($svdta['file'])) { $filesize_old = 0; } else { $filesize_old = filesize($svdta['file']); } if ($svdta['changeType'] == DOKU_CHANGE_TYPE_DELETE) { // Send "update" event with empty data, so plugins can react to page deletion $data = array(array($svdta['file'], '', false), getNS($id), noNS($id), false); trigger_event('IO_WIKIPAGE_WRITE', $data); // pre-save deleted revision @touch($svdta['file']); clearstatcache(); $data['newRevision'] = saveOldRevision($id); // remove empty file @unlink($svdta['file']); $filesize_new = 0; // don't remove old meta info as it should be saved, plugins can use IO_WIKIPAGE_WRITE for removing their metadata... // purge non-persistant meta data p_purge_metadata($id); // remove empty namespaces io_sweepNS($id, 'datadir'); io_sweepNS($id, 'mediadir'); } else { // save file (namespace dir is created in io_writeWikiPage) io_writeWikiPage($svdta['file'], $svdta['newContent'], $id); // pre-save the revision, to keep the attic in sync $svdta['newRevision'] = saveOldRevision($id); $filesize_new = filesize($svdta['file']); } $svdta['sizechange'] = $filesize_new - $filesize_old; $event->advise_after(); addLogEntry($svdta['newRevision'], $svdta['id'], $svdta['changeType'], $svdta['summary'], $svdta['changeInfo'], null, $svdta['sizechange']); // send notify mails notify($svdta['id'], 'admin', $svdta['oldRevision'], $svdta['summary'], $minor); notify($svdta['id'], 'subscribers', $svdta['oldRevision'], $svdta['summary'], $minor); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id, true); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
/** * Handles the actual output creation. */ function render($mode, &$renderer, $data) { global $lang; if ($mode == 'xhtml') { $renderer->info['cache'] = false; @(require_once DOKU_INC . 'inc/fulltext.php'); $backlinks = ft_backlinks($data[0]); $renderer->doc .= '<div id="plugin__backlinks">' . DW_LF; if (!empty($backlinks)) { $renderer->doc .= '<ul class="idx">'; foreach ($backlinks as $backlink) { $name = p_get_metadata($backlink, 'title'); if (empty($name)) { $name = $backlink; } $renderer->doc .= '<li><div class="li">'; $renderer->doc .= html_wikilink(':' . $backlink, $name, ''); $renderer->doc .= '</div></li>'; } $renderer->doc .= '</ul>'; } else { $renderer->doc .= "<strong>Plugin Backlinks: " . $lang['nothingfound'] . "</strong>"; } $renderer->doc .= '</div>' . DW_LF; return true; } return false; }
/** * Return a list of backlinks */ function listBackLinks($id) { return ft_backlinks(cleanID($id)); }
/** * Return a list of backlinks */ function listBackLinks($id) { require_once DOKU_INC . 'inc/fulltext.php'; return ft_backlinks($id); }
/** * display backlinks * * @author Andreas Gohr <*****@*****.**> */ function html_backlinks() { require_once DOKU_INC . 'inc/fulltext.php'; global $ID; global $conf; print p_locale_xhtml('backlinks'); $data = ft_backlinks($ID); print '<ul class="idx">'; foreach ($data as $blink) { print '<li><div class="li">'; print html_wikilink(':' . $blink, $conf['useheading'] ? NULL : $blink); print '</div></li>'; } print '</ul>'; }
/** * fixes link in foreign pages * * in fact, it searches all pages that are referencing to page with $id (they have link [[..]] to it) and replaces with $new_id * * @example * <p> * <b>id</b> = ns1:page1 <br/> * <b>new_id</b> = ns2:page2 * </p> * <p> * link <b>[[ns1:page1...</b> will be replaced with <b>[[ns2:page2...</b> in all wiki pages that had link <b>[[ns1:page1...</b> * </p> * * @param string $pageId * @param string $pageNewId */ protected function fixForeignPageLinks($pageId, $pageNewId) { $foreignPages = ft_backlinks($pageId); foreach ($foreignPages as $foreignId) { $text = rawWiki($foreignId); $text = str_replace("[[{$pageId}", "[[{$pageNewId}", $text); saveWikiText($foreignId, $text, '[yk-tools] automated link fix for ' . $pageId); // i don't know how check if it was success // read wiki again and hope changes match if (strcmp($text, rawWiki($foreignId)) !== 0) { $this->logger('WARNING', "Page '{$foreignId}' failed to update foreign page text. Something went wrong. Continue"); continue; } $this->logger('REFERENCE', "Page '{$foreignId}' was updated."); } return $foreignPages; }
/** * Adds the page data to the index * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_indexer_page_add(Doku_Event &$event, $param) { global $conf; $page = $event->data['page']; $namespace = getNS($page); if (!$namespace) { $namespace = "root"; } $title = str_replace($conf['sepchar'], ' ', noNS($page)); $text = rawWiki($page); $meta = p_get_metadata($page); $data['title'] = $title; $data['namespace'] = $namespace; $data['content'] = $text; $data['references'] = count(ft_backlinks($page, true)); $data['filename'] = wikiFN($page); $data['lastedit'] = $meta['date']['modified']; $this->sphinx->upsert($data); }
/** * Use this tool to reindex your wiki * * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html * @author Abilio Marques <https://github.com/abiliojr> */ if (!defined('DOKU_ROOT')) { define('DOKU_ROOT', realpath(dirname(__FILE__) . '/../../../') . '/'); } define('NOSESSION', 1); require_once DOKU_ROOT . 'inc/init.php'; global $conf; $sphinx = new SphinxSearch(); // clear the index idx_get_indexer()->clear(); // must complete the basic indexing first search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); foreach ($data as $val) { idx_addPage($val['id'], false, true); } // only now the backlinks counters in the dokuwiki index are valid // so lets update sphinxsearch to reflect them $pages = idx_get_indexer()->getPages(); foreach ($pages as $page) { $namespace = getNS($page); if (!$namespace) { $namespace = 'root'; } $title = str_replace($conf['sepchar'], ' ', noNS($page)); $sphinx->updateReferences($namespace, $title, count(ft_backlinks($page, true))); }
function _custom_delete_page($id, $summary) { global $ID, $INFO, $conf; // mark as nonexist to prevent indexerWebBug if ($id == $ID) { $INFO['exists'] = 0; } // delete page, meta and attic $file = wikiFN($id); $old = @filemtime($file); // from page if (file_exists($file)) { unlink($file); } $opts['oldname'] = $this->_FN(noNS($id)); $opts['oldns'] = $this->_FN(getNS($id)); if ($opts['oldns']) { $opts['oldns'] .= '/'; } $this->_locate_filepairs($opts, 'metadir', '/^' . $opts['oldname'] . '\\.(?!mlist)\\w*?$/'); $this->_locate_filepairs($opts, 'olddir', '/^' . $opts['oldname'] . '\\.\\d{10}\\.txt(\\.gz|\\.bz2)?$/'); $this->_apply_deletes($opts); io_sweepNS($id, 'datadir'); io_sweepNS($id, 'metadir'); io_sweepNS($id, 'olddir'); // send notify mails notify($id, 'admin', $old, $summary); notify($id, 'subscribers', $old, $summary); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
/** * display backlinks * * @author Andreas Gohr <*****@*****.**> * @author Michael Klier <*****@*****.**> */ function html_backlinks() { require_once DOKU_INC . 'inc/fulltext.php'; global $ID; global $conf; global $lang; print p_locale_xhtml('backlinks'); $data = ft_backlinks($ID); if (!empty($data)) { print '<ul class="idx">'; foreach ($data as $blink) { print '<li><div class="li">'; print html_wikilink(':' . $blink, $conf['useheading'] ? NULL : $blink); print '</div></li>'; } print '</ul>'; } else { print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; } }