2 rcs_id('$Id: WantedPages.php,v 1.16 2004-11-23 15:17:19 rurban Exp $');
4 Copyright (C) 2002, 2004 $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
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.
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.
31 * TODO: sort pagename col: disable backend fallback
33 include_once('lib/PageList.php');
35 class WikiPlugin_WantedPages
39 return _("WantedPages");
41 function getDescription () {
42 return _("Lists referenced page names which do not exist yet.");
44 function getVersion() {
45 return preg_replace("/[Revision: $]/", '',
46 "\$Revision: 1.16 $");
48 function getDefaultArguments() {
51 PageList::supportedArgs(),
52 array('page' => '[pagename]', // just for a single page.
54 'exclude_from' => _("PgsrcTranslation").','._("InterWikiMap"),
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 if (!empty($args['exclude_from']))
65 $args['exclude_from'] = is_string($args['exclude_from'])
66 ? explodePageList($args['exclude_from'])
67 : $args['exclude_from']; // <! plugin-list !>
69 if ($page == _("WantedPages")) $page = "";
71 // There's probably a more memory-efficient way to do this (eg
72 // a tailored SQL query via the backend, but this gets the job
74 // TODO: Move this to backend/dumb/WantedPagesIter.php
77 $GLOBALS['WikiTheme']->addPageListColumn(
78 array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left')));
79 $pagelist = new PageList($page ? '' : 'pagename,wanted', $exclude, $args); // search button?
80 $pagelist->_wpagelist = array();
83 list($offset, $maxcount) = $pagelist->limit($limit);
84 $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit);
85 while ($row = $wanted_iter->next()) {
86 $wanted = $row['pagename'];
87 $wantedfrom = $row['wantedfrom'];
89 if (empty($pagelist->_wpagelist[$wanted]))
90 $pagelist->addPage($wanted);
91 $pagelist->_wpagelist[$wanted][] = $wantedfrom;
94 // update limit, but it's still a hack.
95 $pagelist->_options['limit'] = "$offset," . min($pagelist->getTotal(), $maxcount);
96 } elseif ($dbi->isWikiPage($page)) {
97 //only get WantedPages links for one page
98 $page_handle = $dbi->getPage($page);
99 $links = $page_handle->getPageLinks(true); // include_empty
100 while ($link_handle = $links->next()) {
101 if (! $dbi->isWikiPage($linkname = $link_handle->getName())) {
102 $pagelist->addPage($linkname);
103 //if (!array_key_exists($linkname, $this->_wpagelist))
104 $pagelist->_wpagelist[$linkname][] = 1;
110 ksort($this->_wpagelist);
111 arsort($this->_wpagelist);
115 $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
117 $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
119 // reference obviously doesn't work, so force an update to add _wpagelist to parentobj
120 if (isset($pagelist->_columns[1]) and $pagelist->_columns[1]->_field == 'wanted')
121 $pagelist->_columns[1]->parentobj =& $pagelist;
126 // which links to the missing page
127 class _PageList_Column_WantedPages_wanted extends _PageList_Column {
128 function _PageList_Column_WantedPages_wanted (&$params) {
129 $this->parentobj =& $params[3];
130 $this->_PageList_Column($params[0],$params[1],$params[2]);
132 function _getValue(&$page, $revision_handle) {
134 foreach($this->parentobj->_wpagelist[$page->getName()] as $page) {
136 $html->pushContent(', ', WikiLink($page));
138 $html = HTML(WikiLink($page));
144 // $Log: not supported by cvs2svn $
145 // Revision 1.15 2004/11/23 13:35:49 rurban
146 // add case_exact search
148 // Revision 1.14 2004/11/20 17:35:58 rurban
149 // improved WantedPages SQL backends
150 // PageList::sortby new 3rd arg valid_fields (override db fields)
151 // WantedPages sql pager inexact for performance reasons:
152 // assume 3 wantedfrom per page, to be correct, no getTotal()
153 // support exclude argument for get_all_pages, new _sql_set()
155 // Revision 1.13 2004/11/20 11:28:49 rurban
156 // fix a yet unused PageList customPageListColumns bug (merge class not decl to _types)
157 // change WantedPages to use PageList
158 // change WantedPages to print the list of referenced pages, not just the count.
159 // the old version was renamed to WantedPagesOld
160 // fix and add handling of most standard PageList arguments (limit, exclude, ...)
161 // TODO: pagename sorting, dumb/WantedPagesIter and SQL optimization
163 // Revision 1.12 2004/10/04 23:39:34 rurban
166 // Revision 1.11 2004/04/20 00:56:00 rurban
167 // more paging support and paging fix for shorter lists
169 // Revision 1.10 2004/04/18 01:44:02 rurban
170 // more sortby+limit support
172 // Revision 1.9 2004/04/10 04:15:06 rurban
173 // sf.net 927122 Suggestion
175 // Revision 1.8 2004/02/17 12:11:36 rurban
176 // 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, ...)
178 // Revision 1.7 2003/12/19 06:57:49 carstenklapp
179 // Bugfix: Enclose FullTextSearch query with quotes when the [Wiki Word]
182 // Revision 1.6 2003/11/19 17:08:23 carstenklapp
183 // New feature: Clicking on the number of citations in the links column
184 // now does a FullTextSearch for the WantedPage link!
186 // Revision 1.5 2003/03/25 21:05:27 dairiki
187 // Ensure pagenames are strings.
189 // Revision 1.4 2003/01/18 22:14:24 carstenklapp
191 // Reformatting & tabs to spaces;
192 // Added copyleft, getVersion, getDescription, rcs_id.
199 // c-hanging-comment-ender-p: nil
200 // indent-tabs-mode: nil