]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListSubpages.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / ListSubpages.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * ListSubpages:  Lists the names of all SubPages of the current page.
25  *                Based on UnfoldSubpages.
26  * Usage:   <<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 getDescription()
34     {
35         return _("Lists the names of all SubPages of the current page.");
36     }
37
38     function getDefaultArguments()
39     {
40         return array_merge
41         (
42             PageList::supportedArgs(),
43             array('noheader' => false, // no header
44                 'basepage' => false, // subpages of which page, default: current
45                 'maxpages' => '', // maximum number of pages to include, change that to limit
46                 //'exclude'  => '',
47                 /*'relative' => false, */
48                 'info' => ''
49             ));
50     }
51
52     // info arg allows multiple columns
53     // info=mtime,hits,summary,version,author,locked,minor,count
54     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
55
56     function run($dbi, $argstr, &$request, $basepage)
57     {
58         $args = $this->getArgs($argstr, $request);
59         if ($args['basepage'])
60             $pagename = $args['basepage'];
61         else
62             $pagename = $request->getArg('pagename');
63
64         // FIXME: explodePageList from stdlib doesn't seem to work as
65         // expected when there are no subpages. (see also
66         // UnfoldSubPages plugin)
67         $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
68         if (!$subpages) {
69             return $this->error(_("The current page has no subpages defined."));
70         }
71         extract($args);
72
73         $content = HTML();
74         //$subpages = array_reverse($subpages); // TODO: why?
75         if ($maxpages) {
76             $subpages = array_slice($subpages, 0, $maxpages);
77         }
78
79         $descrip = fmt("SubPages of %s:",
80             WikiLink($pagename, 'auto'));
81         if ($info) {
82             $info = explode(",", $info);
83             if (in_array('count', $info))
84                 $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
85         }
86         $pagelist = new PageList($info, $exclude, $args);
87         if (!$noheader)
88             $pagelist->setCaption($descrip);
89
90         foreach ($subpages as $page) {
91             // A page cannot include itself. Avoid doublettes.
92             static $included_pages = array();
93             if (in_array($page, $included_pages)) {
94                 $content->pushContent(HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
95                     $page)));
96                 continue;
97             }
98             array_push($included_pages, $page);
99             //if ($relative) {
100             // TODO: add relative subpage name display to PageList class
101             //}
102             $pagelist->addPage($page);
103
104             array_pop($included_pages);
105         }
106         $content->pushContent($pagelist);
107         return $content;
108     }
109 }
110
111 // how many backlinks for this subpage
112 class _PageList_Column_ListSubpages_count extends _PageList_Column
113 {
114     function _getValue($page, &$revision_handle)
115     {
116         $iter = $page->getBackLinks();
117         $count = $iter->count();
118         return $count;
119     }
120 }
121
122 // Local Variables:
123 // mode: php
124 // tab-width: 8
125 // c-basic-offset: 4
126 // c-hanging-comment-ender-p: nil
127 // indent-tabs-mode: nil
128 // End: