]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/LikePages.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / LikePages.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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  */
28 class WikiPlugin_LikePages
29 extends WikiPlugin
30 {
31     function getName() {
32         return _("LikePages");
33     }
34
35     function getDescription() {
36         return sprintf(_("List page names which share an initial or final title word with '%s'."),
37                        '[pagename]');
38     }
39
40     function getVersion() {
41         return preg_replace("/[Revision: $]/", '',
42                             "\$Revision$");
43     }
44
45     function getDefaultArguments() {
46         return array_merge
47             (
48              PageList::supportedArgs(),
49              array('page'     => '[pagename]',
50                    'prefix'   => false,
51                    'suffix'   => false,
52                    'noheader' => 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         extract($args);
62         if (empty($page) && empty($prefix) && empty($suffix))
63             return '';
64
65         if ($prefix) {
66             $suffix = false;
67             $descrip = fmt("Page names with prefix '%s'", $prefix);
68         }
69         elseif ($suffix) {
70             $descrip = fmt("Page names with suffix '%s'", $suffix);
71         }
72         elseif ($page) {
73             $words = preg_split('/[\s:-;.,]+/',
74                                 SplitPagename($page));
75             $words = preg_grep('/\S/', $words);
76
77             $prefix = reset($words);
78             $suffix = end($words);
79
80             $descrip = fmt("These pages share an initial or final title word with '%s'",
81                            WikiLink($page, 'auto'));
82         }
83
84         // Search for pages containing either the suffix or the prefix.
85         $search = $match = array();
86         if (!empty($prefix)) {
87             $search[] = $this->_quote($prefix);
88             $match[]  = '^' . preg_quote($prefix, '/');
89         }
90         if (!empty($suffix)) {
91             $search[] = $this->_quote($suffix);
92             $match[]  = preg_quote($suffix, '/') . '$';
93         }
94
95         if ($search)
96             $query = new TextSearchQuery(join(' OR ', $search));
97         else
98             $query = new NullTextSearchQuery; // matches nothing
99
100         $match_re = '/' . join('|', $match) . '/';
101
102         $pagelist = new PageList($info, $exclude, $args);
103         if (!$noheader)
104             $pagelist->setCaption($descrip);
105         $pages = $dbi->titleSearch($query);
106         while ($page = $pages->next()) {
107             $name = $page->getName();
108             if (!preg_match($match_re, $name))
109                 continue;
110             $pagelist->addPage($page);
111         }
112
113         return $pagelist;
114     }
115
116     function _quote($str) {
117         return "'" . str_replace("'", "''", $str) . "'";
118     }
119 };
120
121 // $Log: not supported by cvs2svn $
122 // Revision 1.21  2004/09/25 16:33:52  rurban
123 // add support for all PageList options
124 //
125 // Revision 1.20  2004/05/18 16:23:40  rurban
126 // rename split_pagename to SplitPagename
127 //
128 // Revision 1.19  2004/02/17 12:11:36  rurban
129 // 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, ...)
130 //
131 // Revision 1.18  2003/01/18 21:48:52  carstenklapp
132 // Code cleanup:
133 // Reformatting & tabs to spaces;
134 // Added copyleft, getVersion, getDescription, rcs_id.
135 //
136
137 // Local Variables:
138 // mode: php
139 // tab-width: 8
140 // c-basic-offset: 4
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil
143 // End:
144 ?>