]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
New action page: AllUserPages
[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         $pages = false;
69         // Todo: extend given _GET args
70         if ($args['debug'])
71             $timer = new DebugTimer;
72         $caption = _("All pages in this wiki (%d total):");
73         
74         if ( !empty($args['userpages']) ) {
75             $pages = PageList::allUserPages($args['include_empty'],
76                                                $args['sortby'], ''
77                                                );
78             $caption = fmt("List of user-created pages (%d total):", count($pages));
79             $args['count'] = $request->getArg('count');
80         } elseif ( !empty($args['owner']) ) {
81             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
82                                                $args['sortby'], ''
83                                                );
84             $caption = fmt("List of pages owned by [%s] (%d total):", 
85                            WikiLink($args['owner'] == '[]' 
86                                     ? $request->_user->getAuthenticatedId() 
87                                     : $args['owner'], 
88                                     'if_known'),
89                            count($pages));
90             $args['count'] = $request->getArg('count');
91             $pages->_options['count'] = $args['count'];
92         } elseif ( !empty($args['author']) ) {
93             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
94                                                 $args['sortby'], '' 
95                                                 );
96             $caption = fmt("List of pages last edited by [%s] (%d total):", 
97                            WikiLink($args['author'] == '[]' 
98                                     ? $request->_user->getAuthenticatedId() 
99                                     : $args['author'], 
100                                     'if_known'), 
101                            count($pages));
102             $args['count'] = $request->getArg('count');
103             $pages->_options['count'] = $args['count'];
104         } elseif ( !empty($args['creator']) ) {
105             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
106                                                  $args['sortby'], ''
107                                                  );
108             $caption = fmt("List of pages created by [%s] (%d total):", 
109                            WikiLink($args['creator'] == '[]' 
110                                     ? $request->_user->getAuthenticatedId() 
111                                     : $args['creator'],
112                                     'if_known'), 
113                            count($pages));
114             $args['count'] = $request->getArg('count');
115             $pages->_options['count'] = $args['count'];
116         //} elseif ($pages) {
117         //    $args['count'] = count($pages);
118         } else {
119             if (! $request->getArg('count'))  
120                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
121             else 
122                 $args['count'] = $request->getArg('count');
123         }
124         if (empty($args['count']) and !empty($pages))
125             $args['count'] = count($pages);
126         $pagelist = new PageList($args['info'], $args['exclude'], $args);
127         if (!$args['noheader']) $pagelist->setCaption($caption);
128
129         // deleted pages show up as version 0.
130         if ($args['include_empty'])
131             $pagelist->_addColumn('version');
132
133         if ($pages !== false)
134             $pagelist->addPageList($pages);
135         else
136             $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], 
137                                                    $args['limit']) );
138         if ($args['debug']) {
139             return HTML($pagelist,
140                         HTML::p(fmt("Elapsed time: %s s", $timer->getStats())));
141         } else {
142             return $pagelist;
143         }
144     }
145
146     function getmicrotime(){
147         list($usec, $sec) = explode(" ",microtime());
148         return (float)$usec + (float)$sec;
149     }
150 };
151
152 // $Log: not supported by cvs2svn $
153 // Revision 1.36  2005/01/28 12:08:42  rurban
154 // dont print [] as user
155 //
156 // Revision 1.35  2004/12/06 19:50:04  rurban
157 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
158 // renamed delete_page to purge_page.
159 // enable action=edit&version=-1 to force creation of a new version.
160 // added BABYCART_PATH config
161 // fixed magiqc in adodb.inc.php
162 // and some more docs
163 //
164 // Revision 1.34  2004/11/23 15:17:19  rurban
165 // better support for case_exact search (not caseexact for consistency),
166 // plugin args simplification:
167 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
168 //     and exclude in advance (at the sql level if possible)
169 //   handle sortby and limit from request override in WikiPlugin::getArgs
170 // ListSubpages: renamed pages to maxpages
171 //
172 // Revision 1.33  2004/11/01 10:43:59  rurban
173 // seperate PassUser methods into seperate dir (memory usage)
174 // fix WikiUser (old) overlarge data session
175 // remove wikidb arg from various page class methods, use global ->_dbi instead
176 // ...
177 //
178 // Revision 1.32  2004/10/05 17:00:04  rurban
179 // support paging for simple lists
180 // fix RatingDb sql backend.
181 // remove pages from AllPages (this is ListPages then)
182 //
183 // Revision 1.31  2004/09/17 14:25:45  rurban
184 // update comments
185 //
186 // Revision 1.30  2004/07/09 10:06:50  rurban
187 // Use backend specific sortby and sortable_columns method, to be able to
188 // select between native (Db backend) and custom (PageList) sorting.
189 // Fixed PageList::AddPageList (missed the first)
190 // Added the author/creator.. name to AllPagesBy...
191 //   display no pages if none matched.
192 // Improved dba and file sortby().
193 // Use &$request reference
194 //
195 // Revision 1.29  2004/07/08 21:32:36  rurban
196 // Prevent from more warnings, minor db and sort optimizations
197 //
198 // Revision 1.28  2004/07/08 20:30:07  rurban
199 // plugin->run consistency: request as reference, added basepage.
200 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
201 //
202 // Revision 1.27  2004/07/08 17:31:43  rurban
203 // improve numPages for file (fixing AllPagesTest)
204 //
205 // Revision 1.26  2004/06/21 16:22:32  rurban
206 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
207 // fixed dumping buttons locally (images/buttons/),
208 // support pages arg for dumphtml,
209 // optional directory arg for dumpserial + dumphtml,
210 // fix a AllPages warning,
211 // show dump warnings/errors on DEBUG,
212 // don't warn just ignore on wikilens pagelist columns, if not loaded.
213 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
214 //
215 // Revision 1.25  2004/06/14 11:31:38  rurban
216 // renamed global $Theme to $WikiTheme (gforge nameclash)
217 // inherit PageList default options from PageList
218 //   default sortby=pagename
219 // use options in PageList_Selectable (limit, sortby, ...)
220 // added action revert, with button at action=diff
221 // added option regex to WikiAdminSearchReplace
222 //
223 // Revision 1.24  2004/06/13 16:02:12  rurban
224 // empty list of pages if user=[] and not authenticated.
225 //
226 // Revision 1.23  2004/06/13 15:51:37  rurban
227 // Support pagelist filter for current author,owner,creator by []
228 //
229 // Revision 1.22  2004/06/13 15:33:20  rurban
230 // new support for arguments owner, author, creator in most relevant
231 // PageList plugins. in WikiAdmin* via preSelectS()
232 //
233 // Revision 1.21  2004/04/20 00:06:53  rurban
234 // paging support
235 //
236 // Revision 1.20  2004/02/22 23:20:33  rurban
237 // fixed DumpHtmlToDir,
238 // enhanced sortby handling in PageList
239 //   new button_heading th style (enabled),
240 // added sortby and limit support to the db backends and plugins
241 //   for paging support (<<prev, next>> links on long lists)
242 //
243 // Revision 1.19  2004/02/17 12:11:36  rurban
244 // 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, ...)
245 //
246 // Revision 1.18  2004/01/25 07:58:30  rurban
247 // PageList sortby support in PearDB and ADODB backends
248 //
249 // Revision 1.17  2003/02/27 20:10:30  dairiki
250 // Disable profiling output when DEBUG is defined but false.
251 //
252 // Revision 1.16  2003/02/21 04:08:26  dairiki
253 // New class DebugTimer in prepend.php to help report timing.
254 //
255 // Revision 1.15  2003/01/18 21:19:25  carstenklapp
256 // Code cleanup:
257 // Reformatting; added copyleft, getVersion, getDescription
258 //
259
260 // Local Variables:
261 // mode: php
262 // tab-width: 8
263 // c-basic-offset: 4
264 // c-hanging-comment-ender-p: nil
265 // indent-tabs-mode: nil
266 // End:
267 ?>