4 * Copyright 1999,2000,2001,2002,2004,2005 $ThePhpWikiProgrammingTeam
5 * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 require_once('lib/TextSearchQuery.php');
25 require_once('lib/PageList.php');
28 * Display results of pagename search.
29 * Provides no own input box, just <?plugin-form TitleSearch ?> is enough.
30 * Fancier Inputforms can be made using WikiForm Rich, to support regex and case_exact args.
32 * If only one pages is found and auto_redirect is true, this page is displayed immediatly,
33 * otherwise the found pagelist is displayed.
34 * The workhorse TextSearchQuery converts the query string from google-style words
35 * to the required DB backend expression.
36 * (word and word) OR word, -word, "two words"
37 * regex=auto tries to detect simple glob-style wildcards and expressions,
38 * like xx*, *xx, ^xx, xx$, ^word$.
40 class WikiPlugin_TitleSearch
44 return _("TitleSearch");
47 function getDescription () {
48 return _("Search the titles of all pages in this wiki.");
51 function getVersion() {
52 return preg_replace("/[Revision: $]/", '',
56 function getDefaultArguments() {
59 PageList::supportedArgs(), // paging and more.
61 'auto_redirect' => false,
65 'case_exact' => false,
70 // info arg allows multiple columns
71 // info=mtime,hits,summary,version,author,locked,minor
72 // exclude arg allows multiple pagenames exclude=Php*,RecentChanges
74 function run($dbi, $argstr, &$request, $basepage) {
75 $args = $this->getArgs($argstr, $request);
76 if (empty($args['s'])) {
80 // ^S != S* ^ matches only beginning of phrase, not of word.
81 // x* matches any word beginning with x
82 $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']);
83 $pages = $dbi->titleSearch($query,$args['sortby'],$args['limit'],$args['exclude']);
85 $pagelist = new PageList($args['info'], $args['exclude'], $args);
86 $pagelist->addPages($pages);
87 // this hack will go away
88 if ($args['format'] == 'livesearch') {
89 $request->discardOutput();
90 $request->buffer_output(false);
91 echo '<div class="LSRes">';
92 echo $pagelist->asXml();
94 if (empty($WikiTheme->DUMP_MODE)) {
95 unset($GLOBALS['ErrorManager']->_postponed_errors);
99 // Provide an unknown WikiWord link to allow for page creation
100 // when a search returns no results
101 if (!$args['noheader']) {
103 $total = $pagelist->getTotal();
104 if (!$total and !$query->_regex) {
105 $s = WikiLink($args['s'], 'auto');
108 $pagelist->setCaption(fmt("Title search results for '%s' (%d total)", $s, $total));
110 $pagelist->setCaption(fmt("Title search results for '%s'", $s));
114 if ($args['auto_redirect'] && ($pagelist->getTotal() == 1)) {
115 $page = $pages->next();
116 return HTML($request->redirect(WikiURL($page->getName(), false, 'absurl'), false),
128 // c-hanging-comment-ender-p: nil
129 // indent-tabs-mode: nil