2 rcs_id('$Id: WantedPages.php,v 1.1 2002-02-24 20:18:36 carstenklapp Exp $');
4 This file is part of PhpWiki.
6 PhpWiki is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 PhpWiki is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with PhpWiki; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * A plugin which returns a list of referenced pages which do not exist yet.
25 //require_once('lib/PageList.php');
29 class WikiPlugin_WantedPages
33 return _("WantedPages");
36 function getDescription () {
37 return _("Wanted Pages");
40 function getDefaultArguments() {
41 return array('noheader' => false,
42 'exclude' => _("PgsrcTranslation"),
45 // info arg allows multiple columns info=mtime,hits,summary,version,author,locked,minor,markup or all
46 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
48 function run($dbi, $argstr, $request) {
49 extract($this->getArgs($argstr, $request));
52 if (!is_array($exclude))
53 $exclude = explode(',', $exclude);
56 // The PageList class can't handle the 'count' column needed for this table
59 // There's probably a more efficient way to do this (eg a tailored SQL query via the
60 // backend, but this does the job
62 if ($page) { //only get WantedPages links for one page
63 $page_handle = $dbi->getPage($page);
64 $links_iter = $page_handle->getLinks($reversed = false);
65 while ($link_handle = $links_iter->next())
67 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
68 if (! in_array($linkname, array_keys($pagelist)))
69 $pagelist[$linkname] = 1;
71 $pagelist[$linkname] += 1;
75 $allpages_iter = $dbi->getAllPages($include_empty = false);
76 while ($page_handle = $allpages_iter->next())
78 $name = $page_handle->getName();
79 if (! in_array($name, $exclude))
81 $links_iter = $page_handle->getLinks($reversed = false);
82 while ($link_handle = $links_iter->next())
84 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
85 if (! in_array($linkname, array_keys($pagelist)))
86 $pagelist[$linkname] = 1;
88 $pagelist[$linkname] += 1;
96 if ($page) // link count always seems to be 1 for a single page
97 $this->_columns = array(_("Page Name"));
99 $this->_columns = array(_("Count"), _("Page Name"));
102 $c = count($pagelist);
104 $caption = sprintf(_("Wanted Pages for %s (%d total):"), $page, $c);
106 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"), $c);
110 $this->_rows = HTML();
111 $spacer = new RawXml(" ");
112 foreach ($pagelist as $key => $val) {
114 $row = HTML::li(WikiLink($key, 'unknown'));
116 $row = HTML::tr(HTML::td(array('align' => 'right'), $val),
117 HTML::td(HTML($spacer, WikiLink($key, 'unknown'))));
118 $this->_rows->pushContent($row);
122 return $this->_generateList($caption);
124 return $this->_generateTable($caption);
127 function _generateTable($caption) {
128 $table = HTML::table(array('cellpadding' => 0,
131 'class' => 'pagelist'));
133 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
136 $spacer = new RawXml(" ");
137 foreach ($this->_columns as $col_heading) {
138 $row->pushContent(HTML::td(HTML($spacer, HTML::u($col_heading))));
139 $table_summary[] = $col_heading;
141 // Table summary for non-visual browsers.
142 $table->setAttr('summary', sprintf(_("Columns: %s."), implode(", ", $table_summary)));
144 $table->pushContent(HTML::thead($row),
145 HTML::tbody(false, $this->_rows));
149 function _generateList($caption) {
152 $list->pushContent(HTML::p($caption));
153 $list->pushContent(HTML::ul($this->_rows));
163 // c-hanging-comment-ender-p: nil
164 // indent-tabs-mode: nil