]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WantedPages.php
New plugin.
[SourceForge/phpwiki.git] / lib / plugin / WantedPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WantedPages.php,v 1.1 2002-02-24 20:18:36 carstenklapp 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 //require_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 _("Wanted Pages");
38     }
39
40     function getDefaultArguments() {
41         return array('noheader' => false,
42                      'exclude'  => _("PgsrcTranslation"),
43                      'page'     => '');
44     }
45     // info arg allows multiple columns 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) {
49         extract($this->getArgs($argstr, $request));
50
51         if ($exclude) {
52             if (!is_array($exclude))
53                 $exclude = explode(',', $exclude);
54         }
55
56         // The PageList class can't handle the 'count' column needed for this table
57         $pagelist = array();
58
59         // There's probably a more efficient way to do this (eg a tailored SQL query via the
60         // backend, but this does the job
61
62         if ($page) { //only get WantedPages links for one page
63             $page_handle = $dbi->getPage($page);
64             $links_iter = $page_handle->getLinks($reversed = false);
65             while ($link_handle = $links_iter->next())
66             {
67                 if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
68                     if (! in_array($linkname, array_keys($pagelist)))
69                         $pagelist[$linkname] = 1;
70                     else
71                         $pagelist[$linkname] += 1;
72             }
73         }
74         else {
75             $allpages_iter = $dbi->getAllPages($include_empty = false);
76             while ($page_handle = $allpages_iter->next())
77             {
78                 $name = $page_handle->getName();
79                 if (! in_array($name, $exclude))
80                 {
81                     $links_iter = $page_handle->getLinks($reversed = false);
82                     while ($link_handle = $links_iter->next())
83                     {
84                         if (! $dbi->isWikiPage($linkname = $link_handle->getName()))
85                             if (! in_array($linkname, array_keys($pagelist)))
86                                 $pagelist[$linkname] = 1;
87                             else
88                                 $pagelist[$linkname] += 1;
89                     }
90                 }
91             }
92         }
93         ksort($pagelist);
94         arsort($pagelist);
95
96         if ($page) // link count always seems to be 1 for a single page
97             $this->_columns = array(_("Page Name"));
98         else
99             $this->_columns = array(_("Count"), _("Page Name"));
100
101         if (!$noheader) {
102             $c = count($pagelist);
103             if ($page)
104                 $caption = sprintf(_("Wanted Pages for %s (%d total):"), $page, $c);
105             else
106             $caption = sprintf(_("Wanted Pages in this wiki (%d total):"), $c);
107         } else
108             $caption = false;
109
110         $this->_rows = HTML();
111         $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
112         foreach ($pagelist as $key => $val) {
113             if ($page)
114                 $row = HTML::li(WikiLink($key, 'unknown'));
115             else
116                 $row = HTML::tr(HTML::td(array('align' => 'right'), $val),
117                                 HTML::td(HTML($spacer, WikiLink($key, 'unknown'))));
118             $this->_rows->pushContent($row);
119         }
120
121         if ($page)
122             return $this->_generateList($caption);
123         else
124             return $this->_generateTable($caption);
125     }
126
127     function _generateTable($caption) {
128         $table = HTML::table(array('cellpadding' => 0,
129                                    'cellspacing' => 1,
130                                    'border'      => 0,
131                                    'class'       => 'pagelist'));
132         if ($caption)
133             $table->pushContent(HTML::caption(array('align'=>'top'), $caption));
134
135         $row = HTML::tr();
136         $spacer = new RawXml("&nbsp;&nbsp;&nbsp;&nbsp;");
137         foreach ($this->_columns as $col_heading) {
138             $row->pushContent(HTML::td(HTML($spacer, HTML::u($col_heading))));
139             $table_summary[] = $col_heading;
140         }
141         // Table summary for non-visual browsers.
142         $table->setAttr('summary', sprintf(_("Columns: %s."), implode(", ", $table_summary)));
143
144         $table->pushContent(HTML::thead($row),
145                             HTML::tbody(false, $this->_rows));
146         return $table;
147     }
148
149     function _generateList($caption) {
150         $list = HTML();
151         if ($caption)
152             $list->pushContent(HTML::p($caption));
153         $list->pushContent(HTML::ul($this->_rows));
154         return $list;
155     }
156 };
157
158
159 // Local Variables:
160 // mode: php
161 // tab-width: 8
162 // c-basic-offset: 4
163 // c-hanging-comment-ender-p: nil
164 // indent-tabs-mode: nil
165 // End:
166 ?>