2 rcs_id('$Id: WantedPages.php,v 1.15 2004-11-23 13:35:49 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.15 $");
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);
65 if ($page == _("WantedPages")) $page = "";
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
70 // TODO: Move this to backend/dumb/WantedPagesIter.php
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();
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'];
87 if (empty($pagelist->_wpagelist[$wanted]))
88 $pagelist->addPage($wanted);
89 $pagelist->_wpagelist[$wanted][] = $wantedfrom;
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;
108 ksort($this->_wpagelist);
109 arsort($this->_wpagelist);
113 $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
115 $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
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;
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]);
130 function _getValue(&$page, $revision_handle) {
132 foreach($this->parentobj->_wpagelist[$page->getName()] as $page) {
134 $html->pushContent(', ', WikiLink($page));
136 $html = HTML(WikiLink($page));
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()
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
158 // Revision 1.12 2004/10/04 23:39:34 rurban
161 // Revision 1.11 2004/04/20 00:56:00 rurban
162 // more paging support and paging fix for shorter lists
164 // Revision 1.10 2004/04/18 01:44:02 rurban
165 // more sortby+limit support
167 // Revision 1.9 2004/04/10 04:15:06 rurban
168 // sf.net 927122 Suggestion
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, ...)
173 // Revision 1.7 2003/12/19 06:57:49 carstenklapp
174 // Bugfix: Enclose FullTextSearch query with quotes when the [Wiki Word]
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!
181 // Revision 1.5 2003/03/25 21:05:27 dairiki
182 // Ensure pagenames are strings.
184 // Revision 1.4 2003/01/18 22:14:24 carstenklapp
186 // Reformatting & tabs to spaces;
187 // Added copyleft, getVersion, getDescription, rcs_id.
194 // c-hanging-comment-ender-p: nil
195 // indent-tabs-mode: nil