is enough. * Fancier Inputforms can be made using WikiForm Rich, to support regex and case_exact args. * * If only one pages is found and auto_redirect is true, this page is displayed immediatly, * otherwise the found pagelist is displayed. * The workhorse TextSearchQuery converts the query string from google-style words * to the required DB backend expression. * (word and word) OR word, -word, "two words" * regex=auto tries to detect simple glob-style wildcards and expressions, * like xx*, *xx, ^xx, xx$, ^word$. */ class WikiPlugin_TitleSearch extends WikiPlugin { function getName () { return _("TitleSearch"); } function getDescription () { return _("Search the titles of all pages in this wiki."); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision$"); } function getDefaultArguments() { return array_merge ( PageList::supportedArgs(), // paging and more. array('s' => false, 'auto_redirect' => false, 'noheader' => false, 'exclude' => false, 'info' => false, 'case_exact' => false, 'regex' => 'auto', 'format' => false, )); } // info arg allows multiple columns // info=mtime,hits,summary,version,author,locked,minor // exclude arg allows multiple pagenames exclude=Php*,RecentChanges function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); if (empty($args['s'])) { return HTML::div(array('class' => "error"), "Please provide 's' argument to the plugin."); } $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']); $pages = $dbi->titleSearch($query,$args['sortby'],$args['limit'],$args['exclude']); $pagelist = new PageList($args['info'], $args['exclude'], $args); $pagelist->addPages($pages); // this hack will go away if ($args['format'] == 'livesearch') { $request->discardOutput(); $request->buffer_output(false); echo '
'; echo $pagelist->asXml(); echo '
'; if (empty($WikiTheme->DUMP_MODE)) { unset($GLOBALS['ErrorManager']->_postponed_errors); $request->finish(); } } // Provide an unknown WikiWord link to allow for page creation // when a search returns no results if (!$args['noheader']) { $s = $args['s']; $total = $pagelist->getTotal(); if (!$total and !$query->_regex) { $s = WikiLink($args['s'], 'auto'); } if ($total) { $pagelist->setCaption(fmt("Title search results for '%s' (%d total)", $s, $total)); } else { $pagelist->setCaption(fmt("Title search results for '%s'", $s)); } } if ($args['auto_redirect'] && ($pagelist->getTotal() == 1)) { $page = $pages->next(); return HTML($request->redirect(WikiURL($page->getName(), false, 'absurl'), false), $pagelist); } return $pagelist; } }; // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>