Beispiel #1
0
 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);
 }
Beispiel #2
0
/**
 * Extract keywords from Category* links on page.
 */
function GleanKeywords($page)
{
    if (!defined('KEYWORDS')) {
        return '';
    }
    require_once "lib/TextSearchQuery.php";
    $search = new TextSearchQuery(KEYWORDS, true);
    $KeywordLinkRegexp = $search->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()) {
        $m = array();
        if (preg_match($KeywordLinkRegexp, $link->getName(), $m)) {
            $keywords[] = SplitPagename($m[0]);
        }
    }
    $keywords[] = WIKI_NAME;
    return join(', ', $keywords);
}
Beispiel #3
0
 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;
 }
Beispiel #4
0
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();
}
Beispiel #5
0
 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 run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $this->_supported_operators = array(':=', '<', '<=', '>', '>=', '!=', '==', '=~');
     $args = $this->getArgs($argstr, $request);
     $posted = $request->getArg('semsearch');
     $request->setArg('semsearch', false);
     if ($request->isPost() and isset($posted['help'])) {
         $request->redirect(WikiURL(_("Help/SemanticSearchAdvancedPlugin"), array('redirectfrom' => $basepage), true));
     }
     $allrelations = $dbi->listRelations();
     $form = $this->showForm($dbi, $request, $args, $allrelations);
     if (isset($this->_norelations_warning)) {
         $form->pushContent(HTML::div(array('class' => 'warning'), _("Warning:") . $this->_norelations_warning));
     }
     extract($args);
     // For convenience, peace and harmony we allow GET requests also.
     if (!$args['s']) {
         // check for good GET request
         return $form;
     }
     // nobody called us, so just display our form
     // In reality we have to iterate over all found pages.
     // To makes things shorter extract the next AND required expr and
     // iterate only over this, then recurse into the next AND expr.
     // => Split into an AND and OR expression tree.
     $parsed_relations = $this->detectRelationsAndAttributes($args['s']);
     $regex = '';
     if ($parsed_relations) {
         $regex = preg_grep("/[\\*\\?]/", $parsed_relations);
     } else {
         $this->error("Invalid query: No relations or attributes in the query {$s} found");
     }
     $pagelist = new PageList($args['info'], $args['exclude'], $args);
     if (!$noheader) {
         $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("Semantic %s Search Result for \"%s\" in pages \"%s\"", '', $s, $page)));
     }
     if (!$regex and $missing = array_diff($parsed_relations, $allrelations)) {
         return $pagelist;
     }
     $relquery = new TextSearchQuery(join(" ", $parsed_relations));
     if (!$relquery->match(join(" ", $allrelations))) {
         return $pagelist;
     }
     $pagequery = new TextSearchQuery($page, $args['case_exact'], $args['regex']);
     // if we have only numeric or text ops we can optimize.
     //$parsed_attr_ops = $this->detectAttrOps($args['s']);
     //TODO: writeme
     $linkquery = new TextSearchQuery($s, $args['case_exact'], $args['regex']);
     $links = $dbi->linkSearch($pagequery, $linkquery, 'relation', $relquery);
     $pagelist->_links = array();
     while ($link = $links->next()) {
         $pagelist->addPage($link['pagename']);
         $pagelist->_links[] = $link;
     }
     $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('relation', _("Relation"), $pagelist));
     $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('link', _("Link"), $pagelist));
     return $pagelist;
 }
Beispiel #7
0
 function _search($what, $callback_fn, $query, $order = '')
 {
     include_once "lib/TextSearchQuery.php";
     // $dbh = $GLOBALS['request']->getDbh();
     //TODO: check if the db is mysql resp. capable of google like search.
     //      postgresql tsearch2 for example
     // See TextSearchQuery.php
     $search = new TextSearchQuery($what);
     $callback = new WikiMethodCb($this, $callback_fn);
     $search_clause = $search->makeSqlClause($callback);
     $result = $this->_dbh->genericSqlIter($query . " " . $search_clause . " " . $order);
 }
Beispiel #8
0
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();
}