]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPages.php
add case_exact search
[SourceForge/phpwiki.git] / lib / plugin / WantedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WantedPages.php,v 1.15 2004-11-23 13:35:49 rurban Exp $');
3 /*
4  Copyright (C) 2002, 2004 $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 /**
24  * Rewrite of WantedPages, which uses PageList and prints the references, not just the count.
25  * It disables r1.6 but is more explicit, and of comparable convenience.
26  *
27  * A plugin which returns a list of referenced pages which do not exist yet.
28  * All empty pages which are linked from any page - with an ending question mark,
29  * or for just a single page, when the page argument is present.
30  *
31  * TODO: sort pagename col: disable backend fallback
32  **/
33 include_once('lib/PageList.php');
34
35 class WikiPlugin_WantedPages
36 extends WikiPlugin
37 {
38     function getName () {
39         return _("WantedPages");
40     }
41     function getDescription () {
42         return _("Lists referenced page names which do not exist yet.");
43     }
44     function getVersion() {
45         return preg_replace("/[Revision: $]/", '',
46                             "\$Revision: 1.15 $");
47     }
48     function getDefaultArguments() {
49         return array_merge
50             (
51              PageList::supportedArgs(),
52              array('page'     => '[pagename]', // just for a single page.
53                    'noheader' => false,
54                    'exclude_from'  => _("PgsrcTranslation").','._("InterWikiMap"),
55                    'limit'    => '100',
56                    'paging'   => 'auto'));
57     }
58
59     // info arg allows multiple columns
60     // info=mtime,hits,summary,version,author,locked,minor,markup or all
61     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
62     function run($dbi, $argstr, &$request, $basepage) {
63         $args = $this->getArgs($argstr, $request);
64         extract($args);
65         if ($page == _("WantedPages")) $page = "";
66
67         // There's probably a more memory-efficient way to do this (eg
68         // a tailored SQL query via the backend, but this gets the job
69         // done.
70         // TODO: Move this to backend/dumb/WantedPagesIter.php
71
72         if (!$page)
73             $GLOBALS['WikiTheme']->addPageListColumn(
74                 array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left')));
75         $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args); // search button?
76         if ($exclude_from) $exclude_from = $pagelist->explodePageList($exclude_from);
77         else $exclude_from = array();
78         $pagelist->_wpagelist = array();
79
80         if (!$page) {
81             list($offset, $maxcount) = $pagelist->limit($limit);
82             $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit);
83             while ($row = $wanted_iter->next()) {
84                 $wanted = $row['pagename'];
85                 $wantedfrom = $row['wantedfrom'];
86                 // ignore duplicates:
87                 if (empty($pagelist->_wpagelist[$wanted]))
88                     $pagelist->addPage($wanted);
89                 $pagelist->_wpagelist[$wanted][] = $wantedfrom;
90             }
91             $wanted_iter->free();
92             // update limit, but it's still a hack.
93             $pagelist->_options['limit'] = "$offset," . min($pagelist->getTotal(), $maxcount);
94         } elseif ($dbi->isWikiPage($page)) {
95             //only get WantedPages links for one page
96             $page_handle = $dbi->getPage($page);
97             $links = $page_handle->getPageLinks(true); // include_empty
98             while ($link_handle = $links->next()) {
99                 if (! $dbi->isWikiPage($linkname = $link_handle->getName())) {
100                     $pagelist->addPage($linkname);
101                     //if (!array_key_exists($linkname, $this->_wpagelist))
102                     $pagelist->_wpagelist[$linkname][] = 1;
103                 }
104             }
105         }
106         /*
107         if ($sortby) {
108             ksort($this->_wpagelist);
109             arsort($this->_wpagelist);
110         }*/
111         if (!$noheader) {
112             if ($page)
113                 $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
114             else
115                 $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
116         }
117         // reference obviously doesn't work, so force an update to add _wpagelist to parentobj
118         if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted')
119             $pagelist->_columns[1]->parentobj =& $pagelist;
120         return $pagelist;
121     }
122 };
123
124 // which links to the missing page
125 class _PageList_Column_WantedPages_wanted extends _PageList_Column {
126     function _PageList_Column_WantedPages_wanted (&$params) {
127         $this->parentobj =& $params[3];
128         $this->_PageList_Column($params[0],$params[1],$params[2]);
129     }
130     function _getValue(&$page, $revision_handle) {
131         $html = false;
132         foreach($this->parentobj->_wpagelist[$page->getName()] as $page) {
133             if ($html)
134                 $html->pushContent(', ', WikiLink($page));
135             else 
136                 $html = HTML(WikiLink($page));
137         }
138         return $html;
139     }
140 }
141
142 // $Log: not supported by cvs2svn $
143 // Revision 1.14  2004/11/20 17:35:58  rurban
144 // improved WantedPages SQL backends
145 // PageList::sortby new 3rd arg valid_fields (override db fields)
146 // WantedPages sql pager inexact for performance reasons:
147 //   assume 3 wantedfrom per page, to be correct, no getTotal()
148 // support exclude argument for get_all_pages, new _sql_set()
149 //
150 // Revision 1.13  2004/11/20 11:28:49  rurban
151 // fix a yet unused PageList customPageListColumns bug (merge class not decl to _types)
152 // change WantedPages to use PageList
153 // change WantedPages to print the list of referenced pages, not just the count.
154 //   the old version was renamed to WantedPagesOld
155 //   fix and add handling of most standard PageList arguments (limit, exclude, ...)
156 // TODO: pagename sorting, dumb/WantedPagesIter and SQL optimization
157 //
158 // Revision 1.12  2004/10/04 23:39:34  rurban
159 // just aesthetics
160 //
161 // Revision 1.11  2004/04/20 00:56:00  rurban
162 // more paging support and paging fix for shorter lists
163 //
164 // Revision 1.10  2004/04/18 01:44:02  rurban
165 // more sortby+limit support
166 //
167 // Revision 1.9  2004/04/10 04:15:06  rurban
168 // sf.net 927122 Suggestion
169 //
170 // Revision 1.8  2004/02/17 12:11:36  rurban
171 // 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, ...)
172 //
173 // Revision 1.7  2003/12/19 06:57:49  carstenklapp
174 // Bugfix: Enclose FullTextSearch query with quotes when the [Wiki Word]
175 // contains spaces.
176 //
177 // Revision 1.6  2003/11/19 17:08:23  carstenklapp
178 // New feature: Clicking on the number of citations in the links column
179 // now does a FullTextSearch for the WantedPage link!
180 //
181 // Revision 1.5  2003/03/25 21:05:27  dairiki
182 // Ensure pagenames are strings.
183 //
184 // Revision 1.4  2003/01/18 22:14:24  carstenklapp
185 // Code cleanup:
186 // Reformatting & tabs to spaces;
187 // Added copyleft, getVersion, getDescription, rcs_id.
188 //
189
190 // Local Variables:
191 // mode: php
192 // tab-width: 8
193 // c-basic-offset: 4
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil
196 // End:
197 ?>