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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 ?>
28 require_once('lib/PageList.php');
30 class WikiPlugin_ListSubpages
34 return _("ListSubpages");
37 function getDescription () {
38 return _("Lists the names of all SubPages of the current page.");
41 function getVersion() {
42 return preg_replace("/[Revision: $]/", '',
46 function getDefaultArguments() {
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
54 /*'relative' => false, */
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
62 function run($dbi, $argstr, &$request, $basepage) {
63 $args = $this->getArgs($argstr, $request);
64 if ($args['basepage'])
65 $pagename = $args['basepage'];
67 $pagename = $request->getArg('pagename');
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 . '*');
74 return $this->error(_("The current page has no subpages defined."));
79 //$subpages = array_reverse($subpages); // TODO: why?
81 $subpages = array_slice ($subpages, 0, $maxpages);
84 $descrip = fmt("SubPages of %s:",
85 WikiLink($pagename, 'auto'));
87 $info = explode(",", $info);
88 if (in_array('count',$info))
89 $args['types']['count'] = new _PageList_Column_ListSubpages_count('count', _("#"), 'center');
91 $pagelist = new PageList($info, $exclude, $args);
93 $pagelist->setCaption($descrip);
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"),
103 array_push($included_pages, $page);
105 // TODO: add relative subpage name display to PageList class
107 $pagelist->addPage($page);
109 array_pop($included_pages);
111 $content->pushContent($pagelist);
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();
125 // $Log: not supported by cvs2svn $
126 // Revision 1.6 2004/11/23 15:17:19 rurban
127 // better support for case_exact search (not caseexact for consistency),
128 // plugin args simplification:
129 // handle and explode exclude and pages argument in WikiPlugin::getArgs
130 // and exclude in advance (at the sql level if possible)
131 // handle sortby and limit from request override in WikiPlugin::getArgs
132 // ListSubpages: renamed pages to maxpages
134 // Revision 1.5 2004/09/13 14:59:56 rurban
135 // info=count: number of backlinks for this subpage
137 // Revision 1.4 2004/08/18 11:15:11 rurban
138 // added basepage argument. Default current
140 // Revision 1.3 2004/02/17 12:11:36 rurban
141 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
143 // Revision 1.2 2003/11/30 18:23:48 carstenklapp
144 // Code housekeeping: PEAR coding standards reformatting only.
146 // Revision 1.1 2003/11/23 16:33:02 carstenklapp
147 // New plugin to list names of SubPages of the currrent
148 // page. (Unfortunately this plugin reveals a bug in
149 // stdlib/explodePageList(), the function doesn't seem to work as
150 // expected when there are no subpages (see also UnfoldSubPages plugin).
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil