]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListSubpages.php
Normalize header
[SourceForge/phpwiki.git] / lib / plugin / ListSubpages.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  * Copyright 2002 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * ListSubpages:  Lists the names of all SubPages of the current page.
25  *                Based on UnfoldSubpages.
26  * Usage:   <?plugin ListSubpages noheader=1 info=pagename,hits,mtime ?>
27  */
28 require_once('lib/PageList.php');
29
30 class WikiPlugin_ListSubpages
31 extends WikiPlugin
32 {
33     function getName() {
34         return _("ListSubpages");
35     }
36
37     function getDescription () {
38         return _("Lists the names of all SubPages of the current page.");
39     }
40
41     function getVersion() {
42         return preg_replace("/[Revision: $]/", '',
43                             "\$Revision$");
44     }
45
46     function getDefaultArguments() {
47         return array_merge
48             (
49              PageList::supportedArgs(),
50                array('noheader' => false, // no header
51                      'basepage' => false, // subpages of which page, default: current
52                      'maxpages' => '',    // maximum number of pages to include, change that to limit
53                      //'exclude'  => '',
54                      /*'relative' => false, */
55                      'info'     => ''
56                      ));
57     }
58     // info arg allows multiple columns
59     // info=mtime,hits,summary,version,author,locked,minor,count
60     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
61
62     function run($dbi, $argstr, &$request, $basepage) {
63         $args = $this->getArgs($argstr, $request);
64         if ($args['basepage'])
65             $pagename = $args['basepage'];
66         else
67             $pagename = $request->getArg('pagename');
68
69         // FIXME: explodePageList from stdlib doesn't seem to work as
70         // expected when there are no subpages. (see also
71         // UnfoldSubPages plugin)
72         $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
73         if (! $subpages) {
74             return $this->error(_("The current page has no subpages defined."));
75         }
76         extract($args);
77
78         $content = HTML();
79         //$subpages = array_reverse($subpages); // TODO: why?
80         if ($maxpages) {
81             $subpages = array_slice ($subpages, 0, $maxpages);
82         }
83
84         $descrip = fmt("SubPages of %s:",
85                        WikiLink($pagename, 'auto'));
86         if ($info) {
87             $info = explode(",", $info);
88             if (in_array('count',$info))
89                 $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
90         }
91         $pagelist = new PageList($info, $exclude, $args);
92         if (!$noheader)
93             $pagelist->setCaption($descrip);
94
95         foreach ($subpages as $page) {
96             // A page cannot include itself. Avoid doublettes.
97             static $included_pages = array();
98             if (in_array($page, $included_pages)) {
99                 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
100                                                       $page)));
101                 continue;
102             }
103             array_push($included_pages, $page);
104             //if ($relative) {
105             // TODO: add relative subpage name display to PageList class
106             //}
107             $pagelist->addPage($page);
108
109             array_pop($included_pages);
110         }
111         $content->pushContent($pagelist);
112         return $content;
113     }
114 };
115
116 // how many backlinks for this subpage
117 class _PageList_Column_ListSubpages_count extends _PageList_Column {
118     function _getValue($page, &$revision_handle) {
119         $iter = $page->getBackLinks();
120         $count = $iter->count();
121         return $count;
122     }
123 }
124
125 // For emacs users
126 // Local Variables:
127 // mode: php
128 // tab-width: 8
129 // c-basic-offset: 4
130 // c-hanging-comment-ender-p: nil
131 // indent-tabs-mode: nil
132 // End:
133 ?>