]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/TitleSearch.php
better support for case_exact search (not caseexact for consistency),
[SourceForge/phpwiki.git] / lib / plugin / TitleSearch.php
1 <?php // -*-php-*-
2 rcs_id('$Id: TitleSearch.php,v 1.23 2004-11-23 15:17:19 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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 class WikiPlugin_TitleSearch
28 extends WikiPlugin
29 {
30     function getName () {
31         return _("TitleSearch");
32     }
33
34     function getDescription () {
35         return _("Search the titles of all pages in this wiki.");
36     }
37
38     function getVersion() {
39         return preg_replace("/[Revision: $]/", '',
40                             "\$Revision: 1.23 $");
41     }
42
43     function getDefaultArguments() {
44         return array_merge
45             (
46              PageList::supportedArgs(), // paging and more.
47              array('s'             => false,
48                    'auto_redirect' => false,
49                    'noheader'      => false,
50                    'exclude'       => false,
51                    'info'          => false,
52                    'case_exact'     => false
53                    ));
54     }
55     // info arg allows multiple columns
56     // info=mtime,hits,summary,version,author,locked,minor
57     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
58
59     function run($dbi, $argstr, &$request, $basepage) {
60         $args = $this->getArgs($argstr, $request);
61         if (empty($args['s']))
62             return '';
63         extract($args);
64
65         $query = new TextSearchQuery($s, $case_exact);
66         $pages = $dbi->titleSearch($query, $case_exact);
67
68         $pagelist = new PageList($info, $exclude, $args);
69         while ($page = $pages->next()) {
70             $pagelist->addPage($page);
71             $last_name = $page->getName();
72         }
73         // Provide an unknown WikiWord link to allow for page creation
74         // when a search returns no results
75         if (!$noheader)
76             $pagelist->setCaption(fmt("Title search results for '%s'",
77                                       $pagelist->getTotal() == 0
78                                       ? WikiLink($s, 'auto') : $s));
79
80         if ($auto_redirect && ($pagelist->getTotal() == 1)) {
81             return HTML($request->redirect(WikiURL($last_name, false, 'absurl'), false),
82                         $pagelist);
83         }
84
85         return $pagelist;
86     }
87 };
88
89 // $Log: not supported by cvs2svn $
90 // Revision 1.22  2004/11/23 13:35:49  rurban
91 // add case_exact search
92 //
93 // Revision 1.21  2004/02/17 12:11:36  rurban
94 // 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, ...)
95 //
96 // Revision 1.20  2003/11/02 20:42:35  carstenklapp
97 // Allow for easy page creation when search returns no matches.
98 // Based on cuthbertcat's patch, SF#655090 2002-12-17.
99 //
100 // Revision 1.19  2003/03/07 02:50:16  dairiki
101 // Fixes for new javascript redirect.
102 //
103 // Revision 1.18  2003/02/21 04:16:51  dairiki
104 // Don't NORETURN from redirect.
105 //
106 // Revision 1.17  2003/01/18 22:08:01  carstenklapp
107 // Code cleanup:
108 // Reformatting & tabs to spaces;
109 // Added copyleft, getVersion, getDescription, rcs_id.
110 //
111
112 // Local Variables:
113 // mode: php
114 // tab-width: 8
115 // c-basic-offset: 4
116 // c-hanging-comment-ender-p: nil
117 // indent-tabs-mode: nil
118 // End:
119 ?>