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
31 return _("WantedPages");
34 function getDescription()
36 return _("Lists referenced page names which do not exist yet.");
39 function getDefaultArguments()
41 return array('noheader' => false,
42 'exclude' => _("PgsrcTranslation"),
43 'page' => '[pagename]',
49 // info arg allows multiple columns
50 // info=mtime,hits,summary,version,author,locked,minor,markup or all
51 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
53 function run($dbi, $argstr, &$request, $basepage)
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 memory-efficient way to do this (eg
70 // a tailored SQL query via the backend, but this gets the job
73 $include_empty = false;
74 $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
75 while ($page_handle = $allpages_iter->next()) {
76 $name = $page_handle->getName();
77 if ($name == _("InterWikiMap")) continue;
78 if (!in_array($name, $exclude))
79 $this->_iterateLinks($page_handle, $dbi);
81 } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
82 //only get WantedPages links for one page
83 $page_handle = $dbi->getPage($page);
84 $this->_iterateLinks($page_handle, $dbi);
85 if (!$request->getArg('count')) {
86 $args['count'] = count($this->pagelist);
88 $args['count'] = $request->getArg('count');
91 ksort($this->pagelist);
92 arsort($this->pagelist);
94 $this->_rows = HTML();
96 $this->_messageIfEmpty = _("<none>");
99 // link count always seems to be 1 for a single page so
101 foreach ($this->pagelist as $key => $val) {
102 $row = HTML::li(WikiLink((string)$key, 'unknown'));
103 $this->_rows->pushContent($row);
107 $pagelink = WikiLink($page);
109 $pagelink = WikiLink($page, 'unknown');
110 $c = count($this->pagelist);
111 $caption = fmt("Wanted Pages for %s (%d total):",
114 return $this->_generateList($caption);
117 $spacer = new RawXml(" ");
118 // Clicking on the number in the links column does a
119 // FullTextSearch for the citations of the WantedPage
121 foreach ($this->pagelist as $key => $val) {
122 $key = (string)$key; // TODO: Not sure why, but this
123 // string cast type-coersion
124 // does seem necessary here.
125 // Enclose any FullTextSearch keys containing a space
126 // with quotes in oder to request a defnitive search.
127 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
128 $row = HTML::tr(HTML::td(array('align' => 'right'),
129 Button(array('s' => $searchkey),
130 $val, _("FullTextSearch")),
131 // Alternatively, get BackLinks
134 //Button(array('action'
135 // => _("BackLinks")),
136 // $val, $searchkey),
137 HTML::td(HTML($spacer,
141 $this->_rows->pushContent($row);
143 $c = count($this->pagelist);
145 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
147 $this->_columns = array(_("Count"), _("Page Name"));
149 return $this->_generateTable($caption);
151 return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
155 function _generateTable($caption)
158 if (count($this->pagelist) > 0) {
159 $table = HTML::table(array('cellpadding' => 0,
162 'class' => 'pagelist'));
164 $table->pushContent(HTML::caption(array('align' => 'top'),
168 $spacer = new RawXml(" ");
169 foreach ($this->_columns as $col_heading) {
170 $row->pushContent(HTML::td(HTML($spacer,
171 HTML::u($col_heading))));
172 $table_summary[] = $col_heading;
174 // Table summary for non-visual browsers.
175 $table->setAttr('summary', sprintf(_("Columns: %s."),
176 implode(", ", $table_summary)));
178 $table->pushContent(HTML::thead($row),
179 HTML::tbody(false, $this->_rows));
183 $table->pushContent(HTML::p($caption));
184 $table->pushContent(HTML::p($this->_messageIfEmpty));
190 function _generateList($caption)
193 $c = count($this->pagelist);
195 $list->pushContent(HTML::p($caption));
198 $list->pushContent(HTML::ul($this->_rows));
200 $list->pushContent(HTML::p($this->_messageIfEmpty));
205 function _iterateLinks($page_handle, $dbi)
207 $links_iter = $page_handle->getLinks($reversed = false);
208 while ($link_handle = $links_iter->next()) {
209 if (!$dbi->isWikiPage($linkname = $link_handle->getName()))
210 if (!in_array($linkname, array_keys($this->pagelist)))
211 $this->pagelist[$linkname] = 1;
213 $this->pagelist[$linkname] += 1;
224 // c-hanging-comment-ender-p: nil
225 // indent-tabs-mode: nil