]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
Test 'limit' argument is numeric to avoid SQL injection
[SourceForge/phpwiki.git] / lib / plugin / AllPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999,2000,2001,2002,2004,2005 $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 require_once('lib/PageList.php');
24
25 /**
26  * Supports author=[] (current user), owner=[] and creator=[]
27  * to be able to have the action pages:
28  *   AllPagesCreatedByMe, AllPagesOwnedByMe, AllPagesLastAuthoredByMe
29  */
30 class WikiPlugin_AllPages
31 extends WikiPlugin
32 {
33     function getName () {
34         return _("AllPages");
35     }
36
37     function getDescription () {
38         return _("List all pages in this wiki.");
39     }
40
41     function getVersion() {
42         return preg_replace("/[Revision: $]/", '',
43                             "\$Revision$");
44     }
45
46     function getDefaultArguments() {
47         return array_merge
48             (
49              PageList::supportedArgs(),
50              array(
51                    'noheader'      => false,
52                    'include_empty' => false,
53                    //'pages'         => false, // DONT, this would be ListPages then.
54                    'info'          => '',
55                    'debug'         => false,
56                    'userpages'     => false
57                    ));
58     }
59     
60     // info arg allows multiple columns
61     // info=mtime,hits,summary,version,author,locked,minor,markup or all
62     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
63     // sortby: [+|-] pagename|mtime|hits
64
65     // 2004-07-08 22:05:35 rurban: turned off &$request to prevent from strange bug below
66     function run($dbi, $argstr, $request, $basepage) {
67         $args = $this->getArgs($argstr, $request);
68
69         if (!empty($args['limit']) && !is_numeric($args['limit'])) {
70             return $this->error(_("Illegal 'limit' argument: must be numeric"));
71         }
72
73         $pages = false;
74         // Todo: extend given _GET args
75         if (defined('DEBUG') && DEBUG && $args['debug']) {
76             $timer = new DebugTimer;
77         }
78         $caption = _("All pages in this wiki ({total} total):");
79         
80         if ( !empty($args['userpages']) ) {
81             $pages = PageList::allUserPages($args['include_empty'],
82                                                $args['sortby'], ''
83                                                );
84             $caption = _("List of user-created pages ({total} total):");
85             $args['count'] = $request->getArg('count');
86         } elseif ( !empty($args['owner']) ) {
87             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
88                                                $args['sortby'], ''
89                                                );
90             $caption = fmt("List of pages owned by [%s] ({total} total):", 
91                            WikiLink($args['owner'] == '[]' 
92                                     ? $request->_user->getAuthenticatedId() 
93                                     : $args['owner'], 
94                                     'if_known'));
95             $args['count'] = $request->getArg('count');
96             $pages->_options['count'] = $args['count'];
97         } elseif ( !empty($args['author']) ) {
98             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
99                                                 $args['sortby'], '' 
100                                                 );
101             $caption = fmt("List of pages last edited by [%s] ({total} total):", 
102                            WikiLink($args['author'] == '[]' 
103                                     ? $request->_user->getAuthenticatedId() 
104                                     : $args['author'], 
105                                     'if_known'));
106             $args['count'] = $request->getArg('count');
107             $pages->_options['count'] = $args['count'];
108         } elseif ( !empty($args['creator']) ) {
109             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
110                                                  $args['sortby'], ''
111                                                  );
112             $caption = fmt("List of pages created by [%s] ({total} total):", 
113                            WikiLink($args['creator'] == '[]' 
114                                     ? $request->_user->getAuthenticatedId() 
115                                     : $args['creator'],
116                                     'if_known'));
117             $args['count'] = $request->getArg('count');
118             $pages->_options['count'] = $args['count'];
119         //} elseif ($pages) {
120         //    $args['count'] = count($pages);
121         } else {
122             if (! $request->getArg('count'))  
123                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
124             else 
125                 $args['count'] = $request->getArg('count');
126         }
127         if (empty($args['count']) and !empty($pages))
128             $args['count'] = count($pages);
129         $pagelist = new PageList($args['info'], $args['exclude'], $args);
130         if (!$args['noheader']) $pagelist->setCaption($caption);
131
132         // deleted pages show up as version 0.
133         if ($args['include_empty'])
134             $pagelist->_addColumn('version');
135
136         if ($pages !== false)
137             $pagelist->addPageList($pages);
138         else
139             $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], 
140                                                    $args['limit']) );
141         if (defined('DEBUG') && DEBUG && $args['debug']) {
142             return HTML($pagelist,
143                         HTML::p(fmt("Elapsed time: %s s", $timer->getStats())));
144         } else {
145             return $pagelist;
146         }
147     }
148 };
149
150 // Local Variables:
151 // mode: php
152 // tab-width: 8
153 // c-basic-offset: 4
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil
156 // End:
157 ?>