2 rcs_id('$Id: TitleSearch.php,v 1.25 2004-11-26 18:39:02 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
23 require_once('lib/TextSearchQuery.php');
24 require_once('lib/PageList.php');
27 class WikiPlugin_TitleSearch
31 return _("TitleSearch");
34 function getDescription () {
35 return _("Search the titles of all pages in this wiki.");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
40 "\$Revision: 1.25 $");
43 function getDefaultArguments() {
46 PageList::supportedArgs(), // paging and more.
48 'auto_redirect' => false,
52 'case_exact' => false,
56 // info arg allows multiple columns
57 // info=mtime,hits,summary,version,author,locked,minor
58 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
60 function run($dbi, $argstr, &$request, $basepage) {
61 $args = $this->getArgs($argstr, $request);
62 if (empty($args['s']))
66 $query = new TextSearchQuery($args['s'], $args['case_exact'], $args['regex']);
67 $pages = $dbi->titleSearch($query);
69 $pagelist = new PageList($args['info'], $args['exclude'], $args);
70 while ($page = $pages->next()) {
71 $pagelist->addPage($page);
72 $last_name = $page->getName();
74 // Provide an unknown WikiWord link to allow for page creation
75 // when a search returns no results
76 if (!$args['noheader'])
77 $pagelist->setCaption(fmt("Title search results for '%s'",
78 $pagelist->getTotal() == 0
79 ? WikiLink($args['s'], 'auto') : $args['s']));
81 if ($args['auto_redirect'] && ($pagelist->getTotal() == 1)) {
82 return HTML($request->redirect(WikiURL($last_name, false, 'absurl'), false),
90 // $Log: not supported by cvs2svn $
91 // Revision 1.24 2004/11/25 08:30:58 rurban
94 // Revision 1.23 2004/11/23 15:17:19 rurban
95 // better support for case_exact search (not caseexact for consistency),
96 // plugin args simplification:
97 // handle and explode exclude and pages argument in WikiPlugin::getArgs
98 // and exclude in advance (at the sql level if possible)
99 // handle sortby and limit from request override in WikiPlugin::getArgs
100 // ListSubpages: renamed pages to maxpages
102 // Revision 1.22 2004/11/23 13:35:49 rurban
103 // add case_exact search
105 // Revision 1.21 2004/02/17 12:11:36 rurban
106 // 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, ...)
108 // Revision 1.20 2003/11/02 20:42:35 carstenklapp
109 // Allow for easy page creation when search returns no matches.
110 // Based on cuthbertcat's patch, SF#655090 2002-12-17.
112 // Revision 1.19 2003/03/07 02:50:16 dairiki
113 // Fixes for new javascript redirect.
115 // Revision 1.18 2003/02/21 04:16:51 dairiki
116 // Don't NORETURN from redirect.
118 // Revision 1.17 2003/01/18 22:08:01 carstenklapp
120 // Reformatting & tabs to spaces;
121 // Added copyleft, getVersion, getDescription, rcs_id.
128 // c-hanging-comment-ender-p: nil
129 // indent-tabs-mode: nil