function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) { return ''; } extract($args); $query = new TextSearchQuery($s, $case_exact, $regex); //$pages = $dbi->fullSearch($query); $lines = array(); $hilight_re = $query->getHighlightRegexp(); $page = $request->getPage(); return $this->showhits($page, $hilight_re); }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s']) and isset($request->_searchhighlight)) { $args['s'] = $request->_searchhighlight['query']; } if (empty($args['s'])) { return ''; } extract($args); $html = HTML(); if (!$noheader and isset($request->_searchhighlight)) { $engine = $request->_searchhighlight['engine']; $html->pushContent(HTML::div(array('class' => 'search-context'), fmt("%s: Found %s through %s", $basepage, $request->_searchhighlight['query'], $engine))); } if ($hits) { $query = new TextSearchQuery($s, $case_exact, $regex); $lines = array(); $hilight_re = $query->getHighlightRegexp(); $page = $request->getPage(); $html->pushContent($this->showhits($page, $hilight_re)); } return $html; }
function displayPage(&$request, $template = false) { global $WikiTheme, $pv; $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) { if ($pv != 2) { //Add the Backlink in page title $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); } else { // Remove Backlinks $pageheader->pushContent(HTML::h1($pagename)); } $first_pages .= $p . SUBPAGE_SEPARATOR; } if ($pv != 2) { $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $backlink = HTML::h1($pagename); } $pageheader->pushContent($backlink); } else { if ($pv != 2) { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $pageheader = HTML::h1($pagename); //Remove Backlinks } if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } // {{{ Codendi hook to insert stuff between navbar and header $eM =& EventManager::instance(); $ref_html = ''; $crossref_fact = new CrossReferenceFactory($pagename, ReferenceManager::REFERENCE_NATURE_WIKIPAGE, GROUP_ID); $crossref_fact->fetchDatas(); if ($crossref_fact->getNbReferences() > 0) { $ref_html .= '<h3>' . $GLOBALS['Language']->getText('cross_ref_fact_include', 'references') . '</h3>'; $ref_html .= $crossref_fact->getHTMLDisplayCrossRefs(); } $additional_html = false; $eM->processEvent('wiki_before_content', array('html' => &$additional_html, 'group_id' => GROUP_ID, 'wiki_page' => $pagename)); if ($additional_html) { $beforeHeader = HTML(); $beforeHeader->pushContent($additional_html); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } else { $beforeHeader = HTML(); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } // }}} /Codendi hook $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; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } $toks['ROBOTS_META'] = 'index,follow'; $toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } $template->printExpansion($toks); $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); } flush(); }
function Markup_searchhighlight() { $result = $GLOBALS['request']->_searchhighlight; require_once "lib/TextSearchQuery.php"; $query = new TextSearchQuery($result['query']); $this->hilight_re = $query->getHighlightRegexp(); $this->engine = $result['engine']; }
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); } /* Tell Google (and others) to ignore old versions of pages */ $toks['ROBOTS_META'] = "noindex,nofollow"; } 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); } } } } } /* Check for special pagenames */ /* if ( $pagename == _("RecentChanges") || $pagename == _("RecentEdits") || $pagename == _("RecentVisitors")) { $toks['ROBOTS_META']="noindex,follow"; } else */ if ($pagename == _("SandBox")) { $toks['ROBOTS_META'] = "noindex,nofollow"; } else { if (!isset($toks['ROBOTS_META'])) { $toks['ROBOTS_META'] = "index,follow"; } } $toks['CONTENT'] = new Template('browse', $request, $page_content); $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } $toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } $template->printExpansion($toks); $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); } flush(); }