]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/TitleSearch.php
Activated Id substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / TitleSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999,2000,2001,2002,2004,2005 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 require_once('lib/TextSearchQuery.php');
24 require_once('lib/PageList.php');
25
26 /**
27  * Display results of pagename search. 
28  * Provides no own input box, just <?plugin-form TitleSearch ?> is enough.
29  * Fancier Inputforms can be made using WikiForm Rich, to support regex and case_exact args.
30  *
31  * If only one pages is found and auto_redirect is true, this page is displayed immediatly, 
32  * otherwise the found pagelist is displayed.
33  * The workhorse TextSearchQuery converts the query string from google-style words 
34  * to the required DB backend expression.
35  *   (word and word) OR word, -word, "two words"
36  * regex=auto tries to detect simple glob-style wildcards and expressions, 
37  * like xx*, *xx, ^xx, xx$, ^word$.
38  */
39 class WikiPlugin_TitleSearch
40 extends WikiPlugin
41 {
42     function getName () {
43         return _("TitleSearch");
44     }
45
46     function getDescription () {
47         return _("Search the titles of all pages in this wiki.");
48     }
49
50     function getVersion() {
51         return preg_replace("/[Revision: $]/", '',
52                             "\$Revision: 1.30 $");
53     }
54
55     function getDefaultArguments() {
56         return array_merge
57             (
58              PageList::supportedArgs(), // paging and more.
59              array('s'             => false,
60                    'auto_redirect' => false,
61                    'noheader'      => false,
62                    'exclude'       => false,
63                    'info'          => false,
64                    'case_exact'    => false,
65                    'regex'         => 'auto',
66                    'format'        => false,
67                    ));
68     }
69     // info arg allows multiple columns
70     // info=mtime,hits,summary,version,author,locked,minor
71     // exclude arg allows multiple pagenames exclude=Php*,RecentChanges
72
73     function run($dbi, $argstr, &$request, $basepage) {
74         $args = $this->getArgs($argstr, $request);
75         if (empty($args['s']))
76             return '';
77
78         $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']);
79         $pages = $dbi->titleSearch($query,$args['sortby'],$args['limit'],$args['exclude']);
80
81         $pagelist = new PageList($args['info'], $args['exclude'], $args);
82         $pagelist->addPages($pages);
83         // this hack will go away
84         if ($args['format'] == 'livesearch') {
85             $request->discardOutput();
86             $request->buffer_output(false);
87             echo '<div class="LSRes">';
88             echo $pagelist->asXml();
89             echo '</div>';
90             if (empty($WikiTheme->DUMP_MODE)) {
91                 unset($GLOBALS['ErrorManager']->_postponed_errors);
92                 $request->finish();
93             }
94         }
95         // Provide an unknown WikiWord link to allow for page creation
96         // when a search returns no results
97         if (!$args['noheader']) {
98             $s = $args['s'];
99             $total = $pagelist->getTotal();
100             if (!$total and !$query->_regex) {
101                 $s = WikiLink($args['s'], 'auto');
102             }
103             if ($total) {
104                 $pagelist->setCaption(fmt("Title search results for '%s' (%d total)", $s, $total));
105             } else {
106                 $pagelist->setCaption(fmt("Title search results for '%s'", $s));
107             }
108         }
109
110         if ($args['auto_redirect'] && ($pagelist->getTotal() == 1)) {
111             $page = $pages->next();
112             return HTML($request->redirect(WikiURL($page->getName(), false, 'absurl'), false),
113                         $pagelist);
114         }
115
116         return $pagelist;
117     }
118 };
119
120 // $Log: not supported by cvs2svn $
121 // Revision 1.29  2007/01/02 13:23:30  rurban
122 // note to deprecate livesearch hack
123 //
124 // Revision 1.28  2005/09/10 21:33:08  rurban
125 // support enhanced API
126 //
127 // Revision 1.27  2005/02/03 05:09:57  rurban
128 // livesearch.js support
129 //
130 // Revision 1.26  2004/11/27 14:39:05  rurban
131 // simpified regex search architecture:
132 //   no db specific node methods anymore,
133 //   new sql() method for each node
134 //   parallel to regexp() (which returns pcre)
135 //   regex types bitmasked (op's not yet)
136 // new regex=sql
137 // clarified WikiDB::quote() backend methods:
138 //   ->quote() adds surrounsing quotes
139 //   ->qstr() (new method) assumes strings and adds no quotes! (in contrast to ADODB)
140 //   pear and adodb have now unified quote methods for all generic queries.
141 //
142 // Revision 1.25  2004/11/26 18:39:02  rurban
143 // new regex search parser and SQL backends (90% complete, glob and pcre backends missing)
144 //
145 // Revision 1.24  2004/11/25 08:30:58  rurban
146 // dont extract args
147 //
148 // Revision 1.23  2004/11/23 15:17:19  rurban
149 // better support for case_exact search (not caseexact for consistency),
150 // plugin args simplification:
151 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
152 //     and exclude in advance (at the sql level if possible)
153 //   handle sortby and limit from request override in WikiPlugin::getArgs
154 // ListSubpages: renamed pages to maxpages
155 //
156 // Revision 1.22  2004/11/23 13:35:49  rurban
157 // add case_exact search
158 //
159 // Revision 1.21  2004/02/17 12:11:36  rurban
160 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
161 //
162 // Revision 1.20  2003/11/02 20:42:35  carstenklapp
163 // Allow for easy page creation when search returns no matches.
164 // Based on cuthbertcat's patch, SF#655090 2002-12-17.
165 //
166 // Revision 1.19  2003/03/07 02:50:16  dairiki
167 // Fixes for new javascript redirect.
168 //
169 // Revision 1.18  2003/02/21 04:16:51  dairiki
170 // Don't NORETURN from redirect.
171 //
172 // Revision 1.17  2003/01/18 22:08:01  carstenklapp
173 // Code cleanup:
174 // Reformatting & tabs to spaces;
175 // Added copyleft, getVersion, getDescription, rcs_id.
176 //
177
178 // Local Variables:
179 // mode: php
180 // tab-width: 8
181 // c-basic-offset: 4
182 // c-hanging-comment-ender-p: nil
183 // indent-tabs-mode: nil
184 // End:
185 ?>