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