is enough. * Fancier Inputforms can be made using <> 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 getDescription() { return _("Search the titles of all pages in this wiki."); } 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(); } // ^S != S* ^ matches only beginning of phrase, not of word. // x* matches any word beginning with x $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); // 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 = $pagelist->first(); $request->redirect(WikiURL($page->getName(), false, 'absurl'), false); } return $pagelist; } } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: