]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListSubpages.php
Argh .. get rid of silly DOS \rs
[SourceForge/phpwiki.git] / lib / plugin / ListSubpages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ListSubpages.php,v 1.3 2004-02-17 12:11:36 rurban Exp $');
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: 1.3 $");
44     }
45
46     function getDefaultArguments() {
47         return array('noheader' => false, // no header
48                      'pages'    => '',    // maximum number of pages
49                                           //  to include
50                      'exclude'  => '',
51                    /*'relative' => false, */
52                      'info'     => ''
53                      );
54     }
55     // info arg allows multiple columns
56     // info=mtime,hits,summary,version,author,locked,minor
57     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
58
59     function run($dbi, $argstr, &$request, $basepage) {
60         $pagename = $request->getArg('pagename');
61
62
63         // FIXME: explodePageList from stdlib doesn't seem to work as
64         // expected when there are no subpages. (see also
65         // UnfoldSubPages plugin)
66         $subpages = explodePageList($pagename . SUBPAGE_SEPARATOR . '*');
67         if (! $subpages) {
68             return $this->error(_("The current page has no subpages defined."));
69         }
70
71
72         extract($this->getArgs($argstr, $request));
73
74         $content = HTML();
75         $subpages = array_reverse($subpages);
76         if($pages) {
77             $subpages = array_slice ($subpages, 0, $pages);        
78         }
79
80         $descrip = fmt("SubPages of %s:",
81                        WikiLink($pagename, 'auto'));
82         $pagelist = new PageList($info, $exclude);
83         if (!$noheader)
84             $pagelist->setCaption($descrip);
85
86         foreach ($subpages as $page) {
87             // A page cannot include itself. Avoid doublettes.
88             static $included_pages = array();
89             if (in_array($page, $included_pages)) {
90                 $content->pushContent(HTML::p(sprintf(_("recursive inclusion of page %s ignored"),
91                                                       $page)));
92                 continue;
93             }
94             array_push($included_pages, $page);
95             //if ($relative) {
96             // TODO: add relative subpage name display to PageList class
97             //}
98             $pagelist->addPage($page);
99
100             array_pop($included_pages);
101         }
102         $content->pushContent($pagelist);
103         return $content;
104     }
105 };
106
107 // $Log: not supported by cvs2svn $
108 // Revision 1.2  2003/11/30 18:23:48  carstenklapp
109 // Code housekeeping: PEAR coding standards reformatting only.
110 //
111 // Revision 1.1  2003/11/23 16:33:02  carstenklapp
112 // New plugin to list names of SubPages of the currrent
113 // page. (Unfortunately this plugin reveals a bug in
114 // stdlib/explodePageList(), the function doesn't seem to work as
115 // expected when there are no subpages (see also UnfoldSubPages plugin).
116 //
117
118 // For emacs users
119 // Local Variables:
120 // mode: php
121 // tab-width: 8
122 // c-basic-offset: 4
123 // c-hanging-comment-ender-p: nil
124 // indent-tabs-mode: nil
125 // End:
126 ?>