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