]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPages.php
more paging support and paging fix for shorter lists
[SourceForge/phpwiki.git] / lib / plugin / WantedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WantedPages.php,v 1.11 2004-04-20 00:56:00 rurban Exp $');
3 /*
4  This file is part of PhpWiki.
5
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.
10
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.
15
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
19  */
20
21 /**
22  * A plugin which returns a list of referenced pages which do not exist yet.
23  *
24  **/
25 //include_once('lib/PageList.php');
26
27 /**
28  */
29 class WikiPlugin_WantedPages
30 extends WikiPlugin
31 {
32     function getName () {
33         return _("WantedPages");
34     }
35
36     function getDescription () {
37         return _("Lists referenced page names which do not exist yet.");
38     }
39
40     function getVersion() {
41         return preg_replace("/[Revision: $]/", '',
42                             "\$Revision: 1.11 $");
43     }
44
45     function getDefaultArguments() {
46         return array('noheader' => false,
47                      'exclude'  => _("PgsrcTranslation"),
48                      'page'     => '[pagename]',
49                      'sortby'   => false,
50                      'limit'    => 50,
51                      'paging'   => 'auto');
52     }
53     // info arg allows multiple columns
54     // info=mtime,hits,summary,version,author,locked,minor,markup or all
55     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
56
57     function run($dbi, $argstr, &$request, $basepage) {
58         extract($this->getArgs($argstr, $request));
59
60         if ($exclude) {
61             if (!is_array($exclude))
62                 $exclude = explode(',', $exclude);
63         }
64
65         if ($page == _("WantedPages"))
66             $page = "";
67
68         // The PageList class can't handle the 'count' column needed
69         // for this table
70         $this->pagelist = array();
71
72         // There's probably a more memory-efficient way to do this (eg
73         // a tailored SQL query via the backend, but this gets the job
74         // done.
75         if (!$page) {
76             $include_empty = false;
77             $allpages_iter = $dbi->getAllPages($include_empty,$sortby,$limit);
78             while ($page_handle = $allpages_iter->next()) {
79                 $name = $page_handle->getName();
80                 if ($name == _("InterWikiMap")) continue;
81                 if (! in_array($name, $exclude))
82                     $this->_iterateLinks($page_handle, $dbi);
83             }
84         } else if ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
85             //only get WantedPages links for one page
86             $page_handle = $dbi->getPage($page);
87             $this->_iterateLinks($page_handle, $dbi);
88             if (! $request->getArg('count')) {
89                 $args['count'] = count($this->pagelist);
90             } else {
91                 $args['count'] = $request->getArg('count');
92             }
93         }
94         ksort($this->pagelist);
95         arsort($this->pagelist);
96
97         $this->_rows = HTML();
98         $caption = false;
99         $this->_messageIfEmpty = _("<none>");
100
101         if ($page) {
102             // link count always seems to be 1 for a single page so
103             // omit count column
104             foreach ($this->pagelist as $key => $val) {
105                 $row = HTML::li(WikiLink((string)$key, 'unknown'));
106                 $this->_rows->pushContent($row);
107             }
108             if (!$noheader) {
109                 if ($pageisWikiPage)
110                     $pagelink = WikiLink($page);
111                 else
112                     $pagelink = WikiLink($page, 'unknown');
113                 $c = count($this->pagelist);
114                 $caption = fmt("Wanted Pages for %s (%d total):",
115                                $pagelink, $c);
116             }
117             return $this->_generateList($caption);
118
119         } else {
120             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
121             // Clicking on the number in the links column does a
122             // FullTextSearch for the citations of the WantedPage
123             // link.
124             foreach ($this->pagelist as $key => $val) {
125                 $key = (string) $key; // TODO: Not sure why, but this
126                                       // string cast type-coersion
127                                       // does seem necessary here.
128                 // Enclose any FullTextSearch keys containing a space
129                 // with quotes in oder to request a defnitive search.
130                 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
131                 $row = HTML::tr(HTML::td(array('align' => 'right'),
132                                          Button(array('s' => $searchkey),
133                                                 $val, _("FullTextSearch")),
134                                          // Alternatively, get BackLinks
135                                          // instead.
136                                          //
137                                          //Button(array('action'
138                                          //             => _("BackLinks")),
139                                          //       $val, $searchkey),
140                                          HTML::td(HTML($spacer,
141                                                        WikiLink($key,
142                                                                 'unknown')))
143                                          ));
144                 $this->_rows->pushContent($row);
145             }
146             $c = count($this->pagelist);
147             if (!$noheader)
148                 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
149                                    $c);
150             $this->_columns = array(_("Count"), _("Page Name"));
151             if ($c > 0)
152                 return $this->_generateTable($caption);
153             else
154                 return HTML(HTML::p($caption), HTML::p($messageIfEmpty));
155         }
156     }
157
158     function _generateTable($caption) {
159
160         if (count($this->pagelist) > 0) {
161             $table = HTML::table(array('cellpadding' => 0,
162                                        'cellspacing' => 1,
163                                        'border'      => 0,
164                                        'class'       => 'pagelist'));
165             if ($caption)
166                 $table->pushContent(HTML::caption(array('align'=>'top'),
167                                                   $caption));
168
169             $row = HTML::tr();
170             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
171             foreach ($this->_columns as $col_heading) {
172                 $row->pushContent(HTML::td(HTML($spacer,
173                                                 HTML::u($col_heading))));
174                 $table_summary[] = $col_heading;
175             }
176             // Table summary for non-visual browsers.
177             $table->setAttr('summary', sprintf(_("Columns: %s."),
178                                                implode(", ", $table_summary)));
179
180             $table->pushContent(HTML::thead($row),
181                                 HTML::tbody(false, $this->_rows));
182         } else {
183             $table = HTML();
184             if ($caption)
185                 $table->pushContent(HTML::p($caption));
186             $table->pushContent(HTML::p($this->_messageIfEmpty));
187         }
188
189         return $table;
190     }
191
192     function _generateList($caption) {
193         $list = HTML();
194         $c = count($this->pagelist);
195         if ($caption)
196             $list->pushContent(HTML::p($caption));
197
198         if ($c > 0)
199             $list->pushContent(HTML::ul($this->_rows));
200         else
201             $list->pushContent(HTML::p($this->_messageIfEmpty));
202
203         return $list;
204     }
205
206     function _iterateLinks($page_handle, $dbi) {
207         $links_iter = $page_handle->getLinks($reversed = false);
208         while ($link_handle = $links_iter->next())
209         {
210             if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
211                 if (! in_array($linkname, array_keys($this->pagelist)))
212                     $this->pagelist[$linkname] = 1;
213                 else
214                     $this->pagelist[$linkname] += 1;
215         }
216     }
217 };
218
219 // $Log: not supported by cvs2svn $
220 // Revision 1.10  2004/04/18 01:44:02  rurban
221 // more sortby+limit support
222 //
223 // Revision 1.9  2004/04/10 04:15:06  rurban
224 // sf.net 927122 Suggestion
225 //
226 // Revision 1.8  2004/02/17 12:11:36  rurban
227 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
228 //
229 // Revision 1.7  2003/12/19 06:57:49  carstenklapp
230 // Bugfix: Enclose FullTextSearch query with quotes when the [Wiki Word]
231 // contains spaces.
232 //
233 // Revision 1.6  2003/11/19 17:08:23  carstenklapp
234 // New feature: Clicking on the number of citations in the links column
235 // now does a FullTextSearch for the WantedPage link!
236 //
237 // Revision 1.5  2003/03/25 21:05:27  dairiki
238 // Ensure pagenames are strings.
239 //
240 // Revision 1.4  2003/01/18 22:14:24  carstenklapp
241 // Code cleanup:
242 // Reformatting & tabs to spaces;
243 // Added copyleft, getVersion, getDescription, rcs_id.
244 //
245
246 // Local Variables:
247 // mode: php
248 // tab-width: 8
249 // c-basic-offset: 4
250 // c-hanging-comment-ender-p: nil
251 // indent-tabs-mode: nil
252 // End:
253 ?>