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: $]/", '',
48 function getDefaultArguments() {
51 PageList::supportedArgs(),
52 array('page' => '[pagename]', // just for a single page.
55 'exclude_from' => _("PgsrcTranslation").','._("InterWikiMap"),
60 // info arg allows multiple columns
61 // info=mtime,hits,summary,version,author,locked,minor,markup or all
62 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
63 function run($dbi, $argstr, &$request, $basepage) {
64 $args = $this->getArgs($argstr, $request);
66 if (!empty($args['limit']) && !is_numeric($args['limit'])) {
67 return $this->error(_("Illegal 'limit' argument: must be numeric"));
70 if (!empty($args['exclude_from']))
71 $args['exclude_from'] = is_string($args['exclude_from'])
72 ? explodePageList($args['exclude_from'])
73 : $args['exclude_from']; // <! plugin-list !>
75 if ($page == _("WantedPages")) $page = "";
77 // There's probably a more memory-efficient way to do this (eg
78 // a tailored SQL query via the backend, but this gets the job
80 // TODO: Move this to backend/dumb/WantedPagesIter.php
82 if (!$page and $withlinks) {
83 $GLOBALS['WikiTheme']->addPageListColumn(
84 array('wanted' => array('_PageList_Column_WantedPages_wanted', 'custom:wanted', _("Wanted From"), 'left')));
85 $info = "pagename,wanted";
87 //only get WantedPages links for one page
91 $GLOBALS['WikiTheme']->addPageListColumn(
92 array('links' => array('_PageList_Column_WantedPages_links', 'custom:links', _("Links"), 'left')));
93 $info = "pagename,links";
95 $pagelist = new PageList($info, $exclude, $args); // search button?
96 $pagelist->_wpagelist = array();
99 list($offset, $maxcount) = $pagelist->limit($limit);
100 $wanted_iter = $dbi->wantedPages($exclude_from, $exclude, $sortby, $limit);
101 while ($row = $wanted_iter->next()) {
102 $wantedfrom = $row['pagename'];
103 $wanted = $row['wantedfrom'];
104 // ignore duplicates:
105 if (empty($pagelist->_wpagelist[$wanted]))
106 $pagelist->addPage($wanted);
107 if (!isset($pagelist->_wpagelist[$wanted]))
108 $pagelist->_wpagelist[$wanted][] = $wantedfrom;
109 elseif (!in_array($wantedfrom, $pagelist->_wpagelist[$wanted]))
110 $pagelist->_wpagelist[$wanted][] = $wantedfrom;
112 $wanted_iter->free();
114 // update limit, but it's still a hack.
115 $pagelist->_options['limit'] = "$offset," . min($pagelist->getTotal(), $maxcount);
116 } elseif ($dbi->isWikiPage($page)) {
117 //only get WantedPages links for one page
118 $page_handle = $dbi->getPage($page);
119 $links = $page_handle->getPageLinks(true); // include_empty
120 while ($link_handle = $links->next()) {
121 $linkname = $link_handle->getName();
122 if (! $dbi->isWikiPage($linkname)) {
123 $pagelist->addPage($linkname);
124 //if (!array_key_exists($linkname, $this->_wpagelist))
125 $pagelist->_wpagelist[$linkname][] = 1;
131 ksort($this->_wpagelist);
132 arsort($this->_wpagelist);
136 $pagelist->setCaption(sprintf(_("Wanted Pages for %s:"), $page));
138 $pagelist->setCaption(sprintf(_("Wanted Pages in this wiki:")));
140 // reference obviously doesn't work, so force an update to add _wpagelist to parentobj
141 if (isset($pagelist->_columns[1])
142 and in_array($pagelist->_columns[1]->_field, array('wanted','links')))
143 $pagelist->_columns[1]->parentobj =& $pagelist;
148 // which links to the missing page
149 class _PageList_Column_WantedPages_wanted extends _PageList_Column {
150 function _PageList_Column_WantedPages_wanted (&$params) {
151 $this->parentobj =& $params[3];
152 $this->_PageList_Column($params[0],$params[1],$params[2]);
154 function _getValue(&$page, $revision_handle) {
156 $pagename = $page->getName();
157 foreach ($this->parentobj->_wpagelist[$pagename] as $page) {
159 $html->pushContent(', ', WikiLink($page));
161 $html = HTML(WikiLink($page));
168 * List of Links and link to ListLinks
170 class _PageList_Column_WantedPages_links extends _PageList_Column {
171 function _PageList_Column_WantedPages_links (&$params) {
172 $this->parentobj =& $params[3];
173 $this->_PageList_Column($params[0],$params[1],$params[2]);
175 function _getValue(&$page, $revision_handle) {
177 $pagename = $page->getName();
178 $count = count($this->parentobj->_wpagelist[$pagename]);
179 return LinkURL(WikiURL($page, array('action' => 'BackLinks'), false),
180 fmt("(%d Links)", $count));
188 // c-hanging-comment-ender-p: nil
189 // indent-tabs-mode: nil