2 // $Id: WantedPagesOld.php 7955 2011-03-03 16:41:35Z vargenau $
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 this program; 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
30 return _("WantedPages");
33 function getDescription () {
34 return _("Lists referenced page names which do not exist yet.");
37 function getDefaultArguments() {
38 return array('noheader' => false,
39 'exclude' => _("PgsrcTranslation"),
40 'page' => '[pagename]',
46 // info arg allows multiple columns
47 // info=mtime,hits,summary,version,author,locked,minor,markup or all
48 // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
50 function run($dbi, $argstr, &$request, $basepage) {
51 extract($this->getArgs($argstr, $request));
54 if (!is_array($exclude))
55 $exclude = explode(',', $exclude);
58 if ($page == _("WantedPages"))
61 // The PageList class can't handle the 'count' column needed
63 $this->pagelist = array();
65 // There's probably a more memory-efficient way to do this (eg
66 // a tailored SQL query via the backend, but this gets the job
69 $include_empty = false;
70 $allpages_iter = $dbi->getAllPages($include_empty,$sortby,$limit);
71 while ($page_handle = $allpages_iter->next()) {
72 $name = $page_handle->getName();
73 if ($name == _("InterWikiMap")) continue;
74 if (! in_array($name, $exclude))
75 $this->_iterateLinks($page_handle, $dbi);
77 } else if ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
78 //only get WantedPages links for one page
79 $page_handle = $dbi->getPage($page);
80 $this->_iterateLinks($page_handle, $dbi);
81 if (! $request->getArg('count')) {
82 $args['count'] = count($this->pagelist);
84 $args['count'] = $request->getArg('count');
87 ksort($this->pagelist);
88 arsort($this->pagelist);
90 $this->_rows = HTML();
92 $this->_messageIfEmpty = _("<none>");
95 // link count always seems to be 1 for a single page so
97 foreach ($this->pagelist as $key => $val) {
98 $row = HTML::li(WikiLink((string)$key, 'unknown'));
99 $this->_rows->pushContent($row);
103 $pagelink = WikiLink($page);
105 $pagelink = WikiLink($page, 'unknown');
106 $c = count($this->pagelist);
107 $caption = fmt("Wanted Pages for %s (%d total):",
110 return $this->_generateList($caption);
113 $spacer = new RawXml(" ");
114 // Clicking on the number in the links column does a
115 // FullTextSearch for the citations of the WantedPage
117 foreach ($this->pagelist as $key => $val) {
118 $key = (string) $key; // TODO: Not sure why, but this
119 // string cast type-coersion
120 // does seem necessary here.
121 // Enclose any FullTextSearch keys containing a space
122 // with quotes in oder to request a defnitive search.
123 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
124 $row = HTML::tr(HTML::td(array('align' => 'right'),
125 Button(array('s' => $searchkey),
126 $val, _("FullTextSearch")),
127 // Alternatively, get BackLinks
130 //Button(array('action'
131 // => _("BackLinks")),
132 // $val, $searchkey),
133 HTML::td(HTML($spacer,
137 $this->_rows->pushContent($row);
139 $c = count($this->pagelist);
141 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
143 $this->_columns = array(_("Count"), _("Page Name"));
145 return $this->_generateTable($caption);
147 return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
151 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 function _generateList($caption) {
187 $c = count($this->pagelist);
189 $list->pushContent(HTML::p($caption));
192 $list->pushContent(HTML::ul($this->_rows));
194 $list->pushContent(HTML::p($this->_messageIfEmpty));
199 function _iterateLinks($page_handle, $dbi) {
200 $links_iter = $page_handle->getLinks($reversed = false);
201 while ($link_handle = $links_iter->next())
203 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
204 if (! in_array($linkname, array_keys($this->pagelist)))
205 $this->pagelist[$linkname] = 1;
207 $this->pagelist[$linkname] += 1;
216 // c-hanging-comment-ender-p: nil
217 // indent-tabs-mode: nil