asRegexp(); // iterate over the pagelinks (could be a large number) [15ms on PluginManager] // or do a titleSearch and check the categories if they are linked? $links = $page->getPageLinks(); $keywords[] = SplitPagename($page->getName()); while ($link = $links->next()) { if (preg_match($KeywordLinkRegexp, $link->getName(), $m)) $keywords[] = SplitPagename($m[0]); } $keywords[] = WIKI_NAME; return join(', ', $keywords); } /** Make a link back to redirecting page. * * @param $pagename string Name of redirecting page. * @return XmlContent Link to the redirecting page. */ function RedirectorLink($pagename) { $url = WikiURL($pagename, array('redirectfrom' => '')); return HTML::a(array('class' => 'redirectfrom wiki', 'href' => $url), $pagename); } function actionPage(&$request, $action) { global $WikiTheme; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); $revision = $page->getCurrentRevision(); $dbi = $request->getDbh(); $actionpage = $dbi->getPage($action); $actionrev = $actionpage->getCurrentRevision(); $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version))); $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime'))); $transformedContent = $actionrev->getTransformedContent(); $template = Template('browse', array('CONTENT' => $transformedContent)); /* if (!headers_sent()) { //FIXME: does not work yet. document.write not supported (signout button) // http://www.w3.org/People/mimasa/test/xhtml/media-types/results if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ GeneratePage($template, $pagetitle, $revision); $request->checkValidators(); flush(); } function displayPage(&$request, $template=false) { global $WikiTheme; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) NoSuchRevision($request, $page, $version); } else { $revision = $page->getCurrentRevision(); } if (isSubPage($pagename)) { $pages = explode(SUBPAGE_SEPARATOR, $pagename); $last_page = array_pop($pages); // deletes last element from array as side-effect $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle' ), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR))); $first_pages = $pages[0] . SUBPAGE_SEPARATOR; array_shift($pages); foreach ($pages as $p) { $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); $first_pages .= $p . SUBPAGE_SEPARATOR; } $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); $pageheader->pushContent($backlink); } else { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); if ($request->getArg('frame')) $pageheader->setAttr('target', '_top'); } $pagetitle = SplitPagename($pagename); if (($redirect_from = $request->getArg('redirectfrom'))) { $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from))); // abuse the $redirected template var for some status update notice } elseif ($request->getArg('errormsg')) { $redirect_message = $request->getArg('errormsg'); $request->setArg('errormsg', false); } $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); /* // FIXME: This is also in the template... if ($request->getArg('action') != 'pdf' and !headers_sent()) { // FIXME: enable MathML/SVG/... support if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ $page_content = $revision->getTransformedContent(); // if external searchengine (google) referrer, highlight the searchterm // FIXME: move that to the transformer? // OR: add the searchhightplugin line to the content? if ($result = isExternalReferrer($request)) { if (DEBUG and !empty($result['query'])) { //$GLOBALS['SearchHighlightQuery'] = $result['query']; /* simply add the SearchHighlight plugin to the top of the page. This just parses the wikitext, and doesn't highlight the markup */ include_once('lib/WikiPlugin.php'); $loader = new WikiPluginLoader; $xml = $loader->expandPI('<'.'?plugin SearchHighlight s="'.$result['query'].'"?'.'>', $request, $markup); if ($xml and is_array($xml)) { foreach (array_reverse($xml) as $line) { array_unshift($page_content->_content, $line); } array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query']))); } if (0) { /* Parse the transformed (mixed HTML links + strings) lines? This looks like overkill. */ require_once("lib/TextSearchQuery.php"); $query = new TextSearchQuery($result['query']); $hilight_re = $query->getHighlightRegexp(); //$matches = preg_grep("/$hilight_re/i", $revision->getContent()); // FIXME! for ($i=0; $i < count($page_content->_content); $i++) { $found = false; $line = $page_content->_content[$i]; if (is_string($line)) { while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) { $found = true; $line = substr($line, strlen($m[0])); $html[] = $m[1]; // prematch $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match } } if ($found) { $html[] = $line; // postmatch $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html); } } } } } $toks['CONTENT'] = new Template('browse', $request, $page_content); $toks['TITLE'] = $pagetitle; //