2 rcs_id('$Id: WantedPages.php,v 1.3 2002-02-25 01:10:24 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"),
43 'page' => '[pagename]');
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 if ($page == _("WantedPages"))
59 // The PageList class can't handle the 'count' column needed for this table
60 $this->pagelist = array();
62 // There's probably a more efficient way to do this (eg a tailored SQL query via the
63 // backend, but this does the job
66 $allpages_iter = $dbi->getAllPages($include_empty = false);
67 while ($page_handle = $allpages_iter->next()) {
68 $name = $page_handle->getName();
69 if (! in_array($name, $exclude))
70 $this->_iterateLinks($page_handle, $dbi);
72 } else if ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
73 //only get WantedPages links for one page
74 $page_handle = $dbi->getPage($page);
75 $this->_iterateLinks($page_handle, $dbi);
77 ksort($this->pagelist);
78 arsort($this->pagelist);
80 $this->_rows = HTML();
82 $this->_messageIfEmpty = _("<none>");
85 // link count always seems to be 1 for a single page so omit count column
86 foreach ($this->pagelist as $key => $val) {
87 $row = HTML::li(WikiLink($key, 'unknown'));
88 $this->_rows->pushContent($row);
92 $pagelink = WikiLink($page);
94 $pagelink = WikiLink($page, 'unknown');
95 $c = count($this->pagelist);
96 $caption = fmt("Wanted Pages for %s (%d total):", $pagelink, $c);
98 return $this->_generateList($caption);
101 $spacer = new RawXml(" ");
102 foreach ($this->pagelist as $key => $val) {
103 $row = HTML::tr(HTML::td(array('align' => 'right'), $val),
104 HTML::td(HTML($spacer, WikiLink($key, 'unknown'))));
105 $this->_rows->pushContent($row);
107 $c = count($this->pagelist);
109 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"), $c);
110 $this->_columns = array(_("Count"), _("Page Name"));
112 return $this->_generateTable($caption);
114 return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
118 function _generateTable($caption) {
120 if (count($this->pagelist) > 0) {
121 $table = HTML::table(array('cellpadding' => 0,
124 'class' => 'pagelist'));
126 $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
129 $spacer = new RawXml(" ");
130 foreach ($this->_columns as $col_heading) {
131 $row->pushContent(HTML::td(HTML($spacer, HTML::u($col_heading))));
132 $table_summary[] = $col_heading;
134 // Table summary for non-visual browsers.
135 $table->setAttr('summary', sprintf(_("Columns: %s."), implode(", ", $table_summary)));
137 $table->pushContent(HTML::thead($row),
138 HTML::tbody(false, $this->_rows));
142 $table->pushContent(HTML::p($caption));
143 $table->pushContent(HTML::p($this->_messageIfEmpty));
149 function _generateList($caption) {
151 $c = count($this->pagelist);
153 $list->pushContent(HTML::p($caption));
156 $list->pushContent(HTML::ul($this->_rows));
158 $list->pushContent(HTML::p($this->_messageIfEmpty));
163 function _iterateLinks($page_handle, $dbi) {
164 $links_iter = $page_handle->getLinks($reversed = false);
165 while ($link_handle = $links_iter->next())
167 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
168 if (! in_array($linkname, array_keys($this->pagelist)))
169 $this->pagelist[$linkname] = 1;
171 $this->pagelist[$linkname] += 1;
182 // c-hanging-comment-ender-p: nil
183 // indent-tabs-mode: nil