]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListSubpages.php
function run: @return mixed
[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     /**
57      * @param WikiDB $dbi
58      * @param string $argstr
59      * @param WikiRequest $request
60      * @param string $basepage
61      * @return mixed
62      */
63     function run($dbi, $argstr, &$request, $basepage)
64     {
65         $args = $this->getArgs($argstr, $request);
66         if ($args['basepage'])
67             $pagename = $args['basepage'];
68         else
69             $pagename = $request->getArg('pagename');
70
71         // FIXME: explodePageList from stdlib doesn't seem to work as
72         // expected when there are no subpages. (see also
73         // UnfoldSubPages plugin)
74         $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
75         if (!$subpages) {
76             return HTML::p(array('class' => 'warning'),
77                 sprintf(_("%s has no subpages defined."), $pagename));
78         }
79         extract($args);
80
81         $content = HTML();
82         //$subpages = array_reverse($subpages); // TODO: why?
83         if ($maxpages) {
84             $subpages = array_slice($subpages, 0, $maxpages);
85         }
86
87         $descrip = fmt("SubPages of %s:",
88             WikiLink($pagename, 'auto'));
89         if ($info) {
90             $info = explode(",", $info);
91             if (in_array('count', $info))
92                 $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
93         }
94         $pagelist = new PageList($info, $exclude, $args);
95         if (!$noheader)
96             $pagelist->setCaption($descrip);
97
98         foreach ($subpages as $page) {
99             // A page cannot include itself. Avoid doublettes.
100             static $included_pages = array();
101             if (in_array($page, $included_pages)) {
102                 $content->pushContent(HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
103                     $page)));
104                 continue;
105             }
106             array_push($included_pages, $page);
107             //if ($relative) {
108             // TODO: add relative subpage name display to PageList class
109             //}
110             $pagelist->addPage($page);
111
112             array_pop($included_pages);
113         }
114         $content->pushContent($pagelist);
115         return $content;
116     }
117 }
118
119 // how many backlinks for this subpage
120 class _PageList_Column_ListSubpages_count extends _PageList_Column
121 {
122     function _getValue($page, &$revision_handle)
123     {
124         $iter = $page->getBackLinks();
125         $count = $iter->count();
126         return $count;
127     }
128 }
129
130 // Local Variables:
131 // mode: php
132 // tab-width: 8
133 // c-basic-offset: 4
134 // c-hanging-comment-ender-p: nil
135 // indent-tabs-mode: nil
136 // End: