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