2 rcs_id('$Id: WantedPages.php,v 1.5 2003-03-25 21:05:27 dairiki 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 _("Lists referenced page names which do not exist yet.");
40 function getVersion() {
41 return preg_replace("/[Revision: $]/", '',
45 function getDefaultArguments() {
46 return array('noheader' => false,
47 'exclude' => _("PgsrcTranslation"),
48 'page' => '[pagename]');
50 // info arg allows multiple columns
51 // info=mtime,hits,summary,version,author,locked,minor,markup or all
52 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
54 function run($dbi, $argstr, $request) {
55 extract($this->getArgs($argstr, $request));
58 if (!is_array($exclude))
59 $exclude = explode(',', $exclude);
62 if ($page == _("WantedPages"))
65 // The PageList class can't handle the 'count' column needed
67 $this->pagelist = array();
69 // There's probably a more efficient way to do this (eg a
70 // tailored SQL query via the backend, but this does the job
73 $allpages_iter = $dbi->getAllPages($include_empty = false);
74 while ($page_handle = $allpages_iter->next()) {
75 $name = $page_handle->getName();
76 if (! in_array($name, $exclude))
77 $this->_iterateLinks($page_handle, $dbi);
79 } else if ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
80 //only get WantedPages links for one page
81 $page_handle = $dbi->getPage($page);
82 $this->_iterateLinks($page_handle, $dbi);
84 ksort($this->pagelist);
85 arsort($this->pagelist);
87 $this->_rows = HTML();
89 $this->_messageIfEmpty = _("<none>");
92 // link count always seems to be 1 for a single page so
94 foreach ($this->pagelist as $key => $val) {
95 $row = HTML::li(WikiLink((string)$key, 'unknown'));
96 $this->_rows->pushContent($row);
100 $pagelink = WikiLink($page);
102 $pagelink = WikiLink($page, 'unknown');
103 $c = count($this->pagelist);
104 $caption = fmt("Wanted Pages for %s (%d total):",
107 return $this->_generateList($caption);
110 $spacer = new RawXml(" ");
111 foreach ($this->pagelist as $key => $val) {
112 $row = HTML::tr(HTML::td(array('align' => 'right'), $val),
113 HTML::td(HTML($spacer,
114 WikiLink((string)$key, 'unknown'))));
115 $this->_rows->pushContent($row);
117 $c = count($this->pagelist);
119 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
121 $this->_columns = array(_("Count"), _("Page Name"));
123 return $this->_generateTable($caption);
125 return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
129 function _generateTable($caption) {
131 if (count($this->pagelist) > 0) {
132 $table = HTML::table(array('cellpadding' => 0,
135 'class' => 'pagelist'));
137 $table->pushContent(HTML::caption(array('align'=>'top'),
141 $spacer = new RawXml(" ");
142 foreach ($this->_columns as $col_heading) {
143 $row->pushContent(HTML::td(HTML($spacer,
144 HTML::u($col_heading))));
145 $table_summary[] = $col_heading;
147 // Table summary for non-visual browsers.
148 $table->setAttr('summary', sprintf(_("Columns: %s."),
149 implode(", ", $table_summary)));
151 $table->pushContent(HTML::thead($row),
152 HTML::tbody(false, $this->_rows));
156 $table->pushContent(HTML::p($caption));
157 $table->pushContent(HTML::p($this->_messageIfEmpty));
163 function _generateList($caption) {
165 $c = count($this->pagelist);
167 $list->pushContent(HTML::p($caption));
170 $list->pushContent(HTML::ul($this->_rows));
172 $list->pushContent(HTML::p($this->_messageIfEmpty));
177 function _iterateLinks($page_handle, $dbi) {
178 $links_iter = $page_handle->getLinks($reversed = false);
179 while ($link_handle = $links_iter->next())
181 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
182 if (! in_array($linkname, array_keys($this->pagelist)))
183 $this->pagelist[$linkname] = 1;
185 $this->pagelist[$linkname] += 1;
190 // $Log: not supported by cvs2svn $
191 // Revision 1.4 2003/01/18 22:14:24 carstenklapp
193 // Reformatting & tabs to spaces;
194 // Added copyleft, getVersion, getDescription, rcs_id.
201 // c-hanging-comment-ender-p: nil
202 // indent-tabs-mode: nil