]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPagesOld.php
No underscore for private function
[SourceForge/phpwiki.git] / lib / plugin / WantedPagesOld.php
1 <?php
2
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 along
17  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 /**
22  * A plugin which returns a list of referenced pages which do not exist yet.
23  *
24  **/
25
26 class WikiPlugin_WantedPagesOld
27     extends WikiPlugin
28 {
29     function getName()
30     {
31         return _("WantedPages");
32     }
33
34     function getDescription()
35     {
36         return _("List referenced page names which do not exist yet.");
37     }
38
39     function getDefaultArguments()
40     {
41         return array('noheader' => false,
42             'exclude' => _("PgsrcTranslation"),
43             'page' => '[pagename]',
44             'sortby' => false,
45             'limit' => 50,
46             'paging' => 'auto');
47     }
48
49     // info arg allows multiple columns
50     // info=mtime,hits,summary,version,author,locked,minor,markup or all
51     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
52
53     function run($dbi, $argstr, &$request, $basepage)
54     {
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             $include_empty = false;
74             $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
75             while ($page_handle = $allpages_iter->next()) {
76                 $name = $page_handle->getName();
77                 if ($name == __("InterWikiMap")) continue;
78                 if (!in_array($name, $exclude))
79                     $this->iterateLinks($page_handle, $dbi);
80             }
81         } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
82             //only get WantedPages links for one page
83             $page_handle = $dbi->getPage($page);
84             $this->iterateLinks($page_handle, $dbi);
85             if (!$request->getArg('count')) {
86                 $args['count'] = count($this->pagelist);
87             } else {
88                 $args['count'] = $request->getArg('count');
89             }
90         }
91         ksort($this->pagelist);
92         arsort($this->pagelist);
93
94         $this->_rows = HTML();
95         $caption = false;
96         $this->_messageIfEmpty = _("None");
97
98         if ($page) {
99             // link count always seems to be 1 for a single page so
100             // omit count column
101             foreach ($this->pagelist as $key => $val) {
102                 $row = HTML::li(WikiLink((string)$key, 'unknown'));
103                 $this->_rows->pushContent($row);
104             }
105             if (!$noheader) {
106                 if ($pageisWikiPage)
107                     $pagelink = WikiLink($page);
108                 else
109                     $pagelink = WikiLink($page, 'unknown');
110                 $c = count($this->pagelist);
111                 $caption = fmt("Wanted Pages for %s (%d total):",
112                     $pagelink, $c);
113             }
114             return $this->generateList($caption);
115
116         } else {
117             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
118             // Clicking on the number in the links column does a
119             // FullTextSearch for the citations of the WantedPage
120             // link.
121             foreach ($this->pagelist as $key => $val) {
122                 $key = (string)$key; // TODO: Not sure why, but this
123                 // string cast type-coersion
124                 // does seem necessary here.
125                 // Enclose any FullTextSearch keys containing a space
126                 // with quotes in oder to request a defnitive search.
127                 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
128                 $row = HTML::tr(HTML::td(array('align' => 'right'),
129                     Button(array('s' => $searchkey),
130                         $val, _("FullTextSearch")),
131                     // Alternatively, get BackLinks
132                     // instead.
133                     //
134                     //Button(array('action'
135                     //             => _("BackLinks")),
136                     //       $val, $searchkey),
137                     HTML::td(HTML($spacer,
138                         WikiLink($key,
139                             'unknown')))
140                 ));
141                 $this->_rows->pushContent($row);
142             }
143             $c = count($this->pagelist);
144             if (!$noheader)
145                 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
146                     $c);
147             $this->_columns = array(_("Count"), _("Page Name"));
148             if ($c > 0)
149                 return $this->generateTable($caption);
150             else
151                 return HTML(HTML::p($caption), HTML::p($this->_messageIfEmpty));
152         }
153     }
154
155     private function generateTable($caption)
156     {
157
158         if (count($this->pagelist) > 0) {
159             $table = HTML::table(array('cellpadding' => 0,
160                 'cellspacing' => 1,
161                 'border' => 0,
162                 'class' => 'pagelist'));
163             if ($caption)
164                 $table->pushContent(HTML::caption(array('align' => 'top'),
165                     $caption));
166
167             $row = HTML::tr();
168             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
169             foreach ($this->_columns as $col_heading) {
170                 $row->pushContent(HTML::td(HTML($spacer,
171                     HTML::u($col_heading))));
172                 $table_summary[] = $col_heading;
173             }
174             // Table summary for non-visual browsers.
175             $table->setAttr('summary', sprintf(_("Columns: %s."),
176                 implode(", ", $table_summary)));
177
178             $table->pushContent(HTML::thead($row),
179                 HTML::tbody(false, $this->_rows));
180         } else {
181             $table = HTML();
182             if ($caption)
183                 $table->pushContent(HTML::p($caption));
184             $table->pushContent(HTML::p($this->_messageIfEmpty));
185         }
186
187         return $table;
188     }
189
190     private function generateList($caption)
191     {
192         $list = HTML();
193         $c = count($this->pagelist);
194         if ($caption)
195             $list->pushContent(HTML::p($caption));
196
197         if ($c > 0)
198             $list->pushContent(HTML::ul($this->_rows));
199         else
200             $list->pushContent(HTML::p($this->_messageIfEmpty));
201
202         return $list;
203     }
204
205     private function iterateLinks($page_handle, $dbi)
206     {
207         $links_iter = $page_handle->getLinks($reversed = false);
208         while ($link_handle = $links_iter->next()) {
209             if (!$dbi->isWikiPage($linkname = $link_handle->getName()))
210                 if (!in_array($linkname, array_keys($this->pagelist)))
211                     $this->pagelist[$linkname] = 1;
212                 else
213                     $this->pagelist[$linkname] += 1;
214         }
215     }
216 }
217
218 // Local Variables:
219 // mode: php
220 // tab-width: 8
221 // c-basic-offset: 4
222 // c-hanging-comment-ender-p: nil
223 // indent-tabs-mode: nil
224 // End: