]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPagesOld.php
Use CSS
[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 getDescription()
30     {
31         return _("List referenced page names which do not exist yet.");
32     }
33
34     function getDefaultArguments()
35     {
36         return array('noheader' => false,
37             'exclude' => _("PgsrcTranslation"),
38             'page' => '[pagename]',
39             'sortby' => false,
40             'limit' => 50,
41             'paging' => 'auto');
42     }
43
44     // info arg allows multiple columns
45     // info=mtime,hits,summary,version,author,locked,minor,markup or all
46     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
47
48     function run($dbi, $argstr, &$request, $basepage)
49     {
50         extract($this->getArgs($argstr, $request));
51
52         if ($exclude) {
53             if (!is_array($exclude))
54                 $exclude = explode(',', $exclude);
55         }
56
57         if ($page == _("WantedPages"))
58             $page = "";
59
60         // The PageList class can't handle the 'count' column needed
61         // for this table
62         $this->pagelist = array();
63
64         // There's probably a more memory-efficient way to do this (eg
65         // a tailored SQL query via the backend, but this gets the job
66         // done.
67         if (!$page) {
68             $include_empty = false;
69             $allpages_iter = $dbi->getAllPages($include_empty, $sortby, $limit);
70             while ($page_handle = $allpages_iter->next()) {
71                 $name = $page_handle->getName();
72                 if ($name == __("InterWikiMap")) continue;
73                 if (!in_array($name, $exclude))
74                     $this->iterateLinks($page_handle, $dbi);
75             }
76         } elseif ($page && $pageisWikiPage = $dbi->isWikiPage($page)) {
77             //only get WantedPages links for one page
78             $page_handle = $dbi->getPage($page);
79             $this->iterateLinks($page_handle, $dbi);
80             if (!$request->getArg('count')) {
81                 $args['count'] = count($this->pagelist);
82             } else {
83                 $args['count'] = $request->getArg('count');
84             }
85         }
86         ksort($this->pagelist);
87         arsort($this->pagelist);
88
89         $this->_rows = HTML();
90         $caption = false;
91         $this->_messageIfEmpty = _("None");
92
93         if ($page) {
94             // link count always seems to be 1 for a single page so
95             // omit count column
96             foreach ($this->pagelist as $key => $val) {
97                 $row = HTML::li(WikiLink((string)$key, 'unknown'));
98                 $this->_rows->pushContent($row);
99             }
100             if (!$noheader) {
101                 if ($pageisWikiPage)
102                     $pagelink = WikiLink($page);
103                 else
104                     $pagelink = WikiLink($page, 'unknown');
105                 $c = count($this->pagelist);
106                 $caption = fmt("Wanted Pages for %s (%d total):",
107                     $pagelink, $c);
108             }
109             return $this->generateList($caption);
110
111         } else {
112             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
113             // Clicking on the number in the links column does a
114             // FullTextSearch for the citations of the WantedPage
115             // link.
116             foreach ($this->pagelist as $key => $val) {
117                 $key = (string)$key; // TODO: Not sure why, but this
118                 // string cast type-coersion
119                 // does seem necessary here.
120                 // Enclose any FullTextSearch keys containing a space
121                 // with quotes in oder to request a defnitive search.
122                 $searchkey = (strstr($key, ' ') === false) ? $key : "\"$key\"";
123                 $row = HTML::tr(HTML::td(array('align' => 'right'),
124                     Button(array('s' => $searchkey),
125                         $val, _("FullTextSearch")),
126                     // Alternatively, get BackLinks
127                     // instead.
128                     //
129                     //Button(array('action'
130                     //             => _("BackLinks")),
131                     //       $val, $searchkey),
132                     HTML::td(HTML($spacer,
133                         WikiLink($key,
134                             'unknown')))
135                 ));
136                 $this->_rows->pushContent($row);
137             }
138             $c = count($this->pagelist);
139             if (!$noheader)
140                 $caption = sprintf(_("Wanted Pages in this wiki (%d total):"),
141                     $c);
142             $this->_columns = array(_("Count"), _("Page Name"));
143             if ($c > 0)
144                 return $this->generateTable($caption);
145             else
146                 return HTML(HTML::p($caption), HTML::p($this->_messageIfEmpty));
147         }
148     }
149
150     private function generateTable($caption)
151     {
152
153         if (count($this->pagelist) > 0) {
154             $table = HTML::table(array('class' => 'pagelist'));
155             if ($caption)
156                 $table->pushContent(HTML::caption(array('align' => 'top'),
157                     $caption));
158
159             $row = HTML::tr();
160             $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
161             foreach ($this->_columns as $col_heading) {
162                 $row->pushContent(HTML::td(HTML($spacer,
163                     HTML::u($col_heading))));
164                 $table_summary[] = $col_heading;
165             }
166             // Table summary for non-visual browsers.
167             $table->setAttr('summary', sprintf(_("Columns: %s."),
168                 implode(", ", $table_summary)));
169
170             $table->pushContent(HTML::thead($row),
171                 HTML::tbody(false, $this->_rows));
172         } else {
173             $table = HTML();
174             if ($caption)
175                 $table->pushContent(HTML::p($caption));
176             $table->pushContent(HTML::p($this->_messageIfEmpty));
177         }
178
179         return $table;
180     }
181
182     private function generateList($caption)
183     {
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     private function iterateLinks($page_handle, $dbi)
198     {
199         $links_iter = $page_handle->getLinks($reversed = false);
200         while ($link_handle = $links_iter->next()) {
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 // Local Variables:
211 // mode: php
212 // tab-width: 8
213 // c-basic-offset: 4
214 // c-hanging-comment-ender-p: nil
215 // indent-tabs-mode: nil
216 // End: