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 along
17 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * A plugin which returns a list of referenced pages which do not exist yet.
26 class WikiPlugin_WantedPagesOld
29 function getDescription()
31 return _("List referenced page names which do not exist yet.");
34 function getDefaultArguments()
36 return array('noheader' => false,
37 'exclude' => _("PgsrcTranslation"),
38 'page' => '[pagename]',
44 // info arg allows multiple columns
45 // 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, $basepage)
50 extract($this->getArgs($argstr, $request));
53 if (!is_array($exclude))
54 $exclude = explode(',', $exclude);
57 if ($page == _("WantedPages"))
60 // The PageList class can't handle the 'count' column needed
62 $this->pagelist = array();
64 // There's probably a more memory-efficient way to do this (eg
65 // a tailored SQL query via the backend, but this gets the job
68 $include_empty = false;
69 $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
70 while ($page_handle = $allpages_iter->next()) {
71 $name = $page_handle->getName();
72 if ($name == __("InterWikiMap")) continue;
73 if (!in_array($name, $exclude))
74 $this->iterateLinks($page_handle, $dbi);
76 } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
77 //only get WantedPages links for one page
78 $page_handle = $dbi->getPage($page);
79 $this->iterateLinks($page_handle, $dbi);
80 if (!$request->getArg('count')) {
81 $args['count'] = count($this->pagelist);
83 $args['count'] = $request->getArg('count');
86 ksort($this->pagelist);
87 arsort($this->pagelist);
89 $this->_rows = HTML();
91 $this->_messageIfEmpty = _("None");
94 // link count always seems to be 1 for a single page so
96 foreach ($this->pagelist as $key => $val) {
97 $row = HTML::li(WikiLink((string)$key, 'unknown'));
98 $this->_rows->pushContent($row);
102 $pagelink = WikiLink($page);
104 $pagelink = WikiLink($page, 'unknown');
105 $c = count($this->pagelist);
106 $caption = fmt("Wanted Pages for %s (%d total):",
109 return $this->generateList($caption);
112 $spacer = new RawXml(" ");
113 // Clicking on the number in the links column does a
114 // FullTextSearch for the citations of the WantedPage
116 foreach ($this->pagelist as $key => $val) {
117 $key = (string)$key; // TODO: Not sure why, but this
118 // string cast type-coersion
119 // does seem necessary here.
120 // Enclose any FullTextSearch keys containing a space
121 // with quotes in oder to request a defnitive search.
122 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
123 $row = HTML::tr(HTML::td(array('align' => 'right'),
124 Button(array('s' => $searchkey),
125 $val, _("FullTextSearch")),
126 // Alternatively, get BackLinks
129 //Button(array('action'
130 // => _("BackLinks")),
131 // $val, $searchkey),
132 HTML::td(HTML($spacer,
136 $this->_rows->pushContent($row);
138 $c = count($this->pagelist);
140 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
142 $this->_columns = array(_("Count"), _("Page Name"));
144 return $this->generateTable($caption);
146 return HTML(HTML::p($caption), HTML::p($this->_messageIfEmpty));
150 private function generateTable($caption)
153 if (count($this->pagelist) > 0) {
154 $table = HTML::table(array('cellpadding' => 0,
157 'class' => 'pagelist'));
159 $table->pushContent(HTML::caption(array('align' => 'top'),
163 $spacer = new RawXml(" ");
164 foreach ($this->_columns as $col_heading) {
165 $row->pushContent(HTML::td(HTML($spacer,
166 HTML::u($col_heading))));
167 $table_summary[] = $col_heading;
169 // Table summary for non-visual browsers.
170 $table->setAttr('summary', sprintf(_("Columns: %s."),
171 implode(", ", $table_summary)));
173 $table->pushContent(HTML::thead($row),
174 HTML::tbody(false, $this->_rows));
178 $table->pushContent(HTML::p($caption));
179 $table->pushContent(HTML::p($this->_messageIfEmpty));
185 private function generateList($caption)
188 $c = count($this->pagelist);
190 $list->pushContent(HTML::p($caption));
193 $list->pushContent(HTML::ul($this->_rows));
195 $list->pushContent(HTML::p($this->_messageIfEmpty));
200 private function iterateLinks($page_handle, $dbi)
202 $links_iter = $page_handle->getLinks($reversed = false);
203 while ($link_handle = $links_iter->next()) {
204 if (!$dbi->isWikiPage($linkname = $link_handle->getName()))
205 if (!in_array($linkname, array_keys($this->pagelist)))
206 $this->pagelist[$linkname] = 1;
208 $this->pagelist[$linkname] += 1;
217 // c-hanging-comment-ender-p: nil
218 // indent-tabs-mode: nil