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