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 private $_messageIfEmpty;
34 function getDescription()
36 return _("List 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
55 * @param string $argstr
56 * @param WikiRequest $request
57 * @param string $basepage
60 function run($dbi, $argstr, &$request, $basepage)
62 extract($this->getArgs($argstr, $request));
64 if (isset($limit) && !is_limit($limit)) {
65 return HTML::p(array('class' => "error"),
66 _("Illegal “limit” argument: must be an integer or two integers separated by comma"));
70 if (!is_array($exclude))
71 $exclude = explode(',', $exclude);
74 if ($page == _("WantedPages"))
77 // The PageList class can't handle the 'count' column needed
79 $this->pagelist = array();
81 // There's probably a more memory-efficient way to do this (eg
82 // a tailored SQL query via the backend, but this gets the job
85 $include_empty = false;
86 $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
87 while ($page_handle = $allpages_iter->next()) {
88 $name = $page_handle->getName();
89 if ($name == __("InterWikiMap")) continue;
90 if (!in_array($name, $exclude))
91 $this->iterateLinks($page_handle, $dbi);
93 } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
94 //only get WantedPages links for one page
95 $page_handle = $dbi->getPage($page);
96 $this->iterateLinks($page_handle, $dbi);
97 if (!$request->getArg('count')) {
98 $args['count'] = count($this->pagelist);
100 $args['count'] = $request->getArg('count');
103 ksort($this->pagelist);
104 arsort($this->pagelist);
106 $this->_rows = HTML();
108 $this->_messageIfEmpty = _("None");
111 // link count always seems to be 1 for a single page so
113 foreach ($this->pagelist as $key => $val) {
114 $row = HTML::li(WikiLink((string)$key, 'unknown'));
115 $this->_rows->pushContent($row);
119 $pagelink = WikiLink($page);
121 $pagelink = WikiLink($page, 'unknown');
122 $c = count($this->pagelist);
123 $caption = fmt("Wanted Pages for %s (%d total):",
126 return $this->generateList($caption);
129 $spacer = new RawXml(" ");
130 // Clicking on the number in the links column does a
131 // FullTextSearch for the citations of the WantedPage
133 foreach ($this->pagelist as $key => $val) {
134 $key = (string)$key; // TODO: Not sure why, but this
135 // string cast type-coersion
136 // does seem necessary here.
137 // Enclose any FullTextSearch keys containing a space
138 // with quotes in oder to request a defnitive search.
139 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
140 $row = HTML::tr(HTML::td(array('class' => 'align-right'),
141 Button(array('s' => $searchkey),
142 $val, _("FullTextSearch")),
143 // Alternatively, get BackLinks
146 //Button(array('action'
147 // => _("BackLinks")),
148 // $val, $searchkey),
149 HTML::td(HTML($spacer,
153 $this->_rows->pushContent($row);
155 $c = count($this->pagelist);
157 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
159 $this->_columns = array(_("Count"), _("Page Name"));
161 return $this->generateTable($caption);
163 return HTML(HTML::p($caption), HTML::p($this->_messageIfEmpty));
167 private function generateTable($caption)
170 if (count($this->pagelist) > 0) {
171 $table = HTML::table(array('class' => 'pagelist'));
173 $table->pushContent(HTML::caption(array('style' => 'caption-side:top'),
177 $spacer = new RawXml(" ");
178 foreach ($this->_columns as $col_heading) {
179 $row->pushContent(HTML::td(HTML($spacer,
180 HTML::u($col_heading))));
181 $table_summary[] = $col_heading;
183 // Table summary for non-visual browsers.
184 $table->setAttr('summary', sprintf(_("Columns: %s."),
185 implode(", ", $table_summary)));
187 $table->pushContent(HTML::thead($row),
188 HTML::tbody(false, $this->_rows));
192 $table->pushContent(HTML::p($caption));
193 $table->pushContent(HTML::p($this->_messageIfEmpty));
199 private function generateList($caption)
202 $c = count($this->pagelist);
204 $list->pushContent(HTML::p($caption));
207 $list->pushContent(HTML::ul($this->_rows));
209 $list->pushContent(HTML::p($this->_messageIfEmpty));
214 private function iterateLinks($page_handle, $dbi)
216 $links_iter = $page_handle->getLinks($reversed = false);
217 while ($link_handle = $links_iter->next()) {
218 if (!$dbi->isWikiPage($linkname = $link_handle->getName()))
219 if (!in_array($linkname, array_keys($this->pagelist)))
220 $this->pagelist[$linkname] = 1;
222 $this->pagelist[$linkname] += 1;
231 // c-hanging-comment-ender-p: nil
232 // indent-tabs-mode: nil