]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPagesOld.php
Revert: function _extract_page_data is public
[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     public $pagelist;
30     public $_rows;
31     private $_messageIfEmpty;
32     public $_columns;
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     /**
54      * @param WikiDB $dbi
55      * @param string $argstr
56      * @param WikiRequest $request
57      * @param string $basepage
58      * @return mixed
59      */
60     function run($dbi, $argstr, &$request, $basepage)
61     {
62         extract($this->getArgs($argstr, $request));
63
64         if (isset($limit) && !is_limit($limit)) {
65             return HTML::p(array('class' => "error"),
66                            _("Illegal “limit” argument: must be an integer or two integers separated by comma"));
67         }
68
69         if ($exclude) {
70             if (!is_array($exclude))
71                 $exclude = explode(',', $exclude);
72         }
73
74         if ($page == _("WantedPages"))
75             $page = "";
76
77         // The PageList class can't handle the 'count' column needed
78         // for this table
79         $this->pagelist = array();
80
81         // There's probably a more memory-efficient way to do this (eg
82         // a tailored SQL query via the backend, but this gets the job
83         // done.
84         if (!$page) {
85             $include_empty = false;
86             $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
87             while ($page_handle = $allpages_iter->next()) {
88                 $name = $page_handle->getName();
89                 if ($name == __("InterWikiMap")) continue;
90                 if (!in_array($name, $exclude))
91                     $this->iterateLinks($page_handle, $dbi);
92             }
93         } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
94             //only get WantedPages links for one page
95             $page_handle = $dbi->getPage($page);
96             $this->iterateLinks($page_handle, $dbi);
97             if (!$request->getArg('count')) {
98                 $args['count'] = count($this->pagelist);
99             } else {
100                 $args['count'] = $request->getArg('count');
101             }
102         }
103         ksort($this->pagelist);
104         arsort($this->pagelist);
105
106         $this->_rows = HTML();
107         $caption = false;
108         $this->_messageIfEmpty = _("None");
109
110         if ($page) {
111             // link count always seems to be 1 for a single page so
112             // omit count column
113             foreach ($this->pagelist as $key => $val) {
114                 $row = HTML::li(WikiLink((string)$key, 'unknown'));
115                 $this->_rows->pushContent($row);
116             }
117             if (!$noheader) {
118                 if ($pageisWikiPage)
119                     $pagelink = WikiLink($page);
120                 else
121                     $pagelink = WikiLink($page, 'unknown');
122                 $c = count($this->pagelist);
123                 $caption = fmt("Wanted Pages for %s (%d total):",
124                     $pagelink, $c);
125             }
126             return $this->generateList($caption);
127
128         } else {
129             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
130             // Clicking on the number in the links column does a
131             // FullTextSearch for the citations of the WantedPage
132             // link.
133             foreach ($this->pagelist as $key => $val) {
134                 $key = (string)$key; // TODO: Not sure why, but this
135                 // string cast type-coersion
136                 // does seem necessary here.
137                 // Enclose any FullTextSearch keys containing a space
138                 // with quotes in oder to request a defnitive search.
139                 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
140                 $row = HTML::tr(HTML::td(array('class' => 'align-right'),
141                     Button(array('s' => $searchkey),
142                         $val, _("FullTextSearch")),
143                     // Alternatively, get BackLinks
144                     // instead.
145                     //
146                     //Button(array('action'
147                     //             => _("BackLinks")),
148                     //       $val, $searchkey),
149                     HTML::td(HTML($spacer,
150                         WikiLink($key,
151                             'unknown')))
152                 ));
153                 $this->_rows->pushContent($row);
154             }
155             $c = count($this->pagelist);
156             if (!$noheader)
157                 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
158                     $c);
159             $this->_columns = array(_("Count"), _("Page Name"));
160             if ($c > 0)
161                 return $this->generateTable($caption);
162             else
163                 return HTML(HTML::p($caption), HTML::p($this->_messageIfEmpty));
164         }
165     }
166
167     private function generateTable($caption)
168     {
169
170         if (count($this->pagelist) > 0) {
171             $table = HTML::table(array('class' => 'pagelist'));
172             if ($caption)
173                 $table->pushContent(HTML::caption(array('style' => 'caption-side:top'),
174                     $caption));
175
176             $row = HTML::tr();
177             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
178             foreach ($this->_columns as $col_heading) {
179                 $row->pushContent(HTML::td(HTML($spacer,
180                     HTML::u($col_heading))));
181                 $table_summary[] = $col_heading;
182             }
183             // Table summary for non-visual browsers.
184             $table->setAttr('summary', sprintf(_("Columns: %s."),
185                 implode(", ", $table_summary)));
186
187             $table->pushContent(HTML::thead($row),
188                 HTML::tbody(false, $this->_rows));
189         } else {
190             $table = HTML();
191             if ($caption)
192                 $table->pushContent(HTML::p($caption));
193             $table->pushContent(HTML::p($this->_messageIfEmpty));
194         }
195
196         return $table;
197     }
198
199     private function generateList($caption)
200     {
201         $list = HTML();
202         $c = count($this->pagelist);
203         if ($caption)
204             $list->pushContent(HTML::p($caption));
205
206         if ($c > 0)
207             $list->pushContent(HTML::ul($this->_rows));
208         else
209             $list->pushContent(HTML::p($this->_messageIfEmpty));
210
211         return $list;
212     }
213
214     private function iterateLinks($page_handle, $dbi)
215     {
216         $links_iter = $page_handle->getLinks($reversed = false);
217         while ($link_handle = $links_iter->next()) {
218             if (!$dbi->isWikiPage($linkname = $link_handle->getName()))
219                 if (!in_array($linkname, array_keys($this->pagelist)))
220                     $this->pagelist[$linkname] = 1;
221                 else
222                     $this->pagelist[$linkname] += 1;
223         }
224     }
225 }
226
227 // Local Variables:
228 // mode: php
229 // tab-width: 8
230 // c-basic-offset: 4
231 // c-hanging-comment-ender-p: nil
232 // indent-tabs-mode: nil
233 // End: