4 * Copyright 2002 $ThePhpWikiProgrammingTeam
6 * This file is part of PhpWiki.
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.
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.
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.
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 >>
28 require_once 'lib/PageList.php';
30 class WikiPlugin_ListSubpages
33 function getDescription()
35 return _("Lists the names of all SubPages of the current page.");
38 function getDefaultArguments()
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
47 /*'relative' => false, */
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
58 * @param string $argstr
59 * @param WikiRequest $request
60 * @param string $basepage
63 function run($dbi, $argstr, &$request, $basepage)
65 $args = $this->getArgs($argstr, $request);
67 if (isset($args['limit']) && !is_limit($args['limit'])) {
68 return HTML::p(array('class' => "error"),
69 _("Illegal “limit” argument: must be an integer or two integers separated by comma"));
72 if ($args['basepage'])
73 $pagename = $args['basepage'];
75 $pagename = $request->getArg('pagename');
77 // FIXME: explodePageList from stdlib doesn't seem to work as
78 // expected when there are no subpages. (see also
79 // UnfoldSubPages plugin)
80 $subpages = explodePageList($pagename . '/' . '*');
82 return HTML::p(array('class' => 'warning'),
83 sprintf(_("%s has no subpages defined."), $pagename));
88 //$subpages = array_reverse($subpages); // TODO: why?
90 $subpages = array_slice($subpages, 0, $maxpages);
93 $descrip = fmt("SubPages of %s:",
94 WikiLink($pagename, 'auto'));
96 $info = explode(",", $info);
97 if (in_array('count', $info))
98 $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
100 $pagelist = new PageList($info, $exclude, $args);
102 $pagelist->setCaption($descrip);
104 foreach ($subpages as $page) {
105 // A page cannot include itself. Avoid doublettes.
106 static $included_pages = array();
107 if (in_array($page, $included_pages)) {
108 $content->pushContent(HTML::p(sprintf(_("Recursive inclusion of page %s ignored"),
112 array_push($included_pages, $page);
114 // TODO: add relative subpage name display to PageList class
116 $pagelist->addPage($page);
118 array_pop($included_pages);
120 $content->pushContent($pagelist);
125 // how many backlinks for this subpage
126 class _PageList_Column_ListSubpages_count extends _PageList_Column
128 function _getValue($page, &$revision_handle)
130 $iter = $page->getBackLinks();
131 $count = $iter->count();
140 // c-hanging-comment-ender-p: nil
141 // indent-tabs-mode: nil