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