]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
Use backend specific sortby and sortable_columns method, to be able to
[SourceForge/phpwiki.git] / lib / plugin / AllPages.php
1 <?php // -*-php-*-
2 rcs_id('$Id: AllPages.php,v 1.30 2004-07-09 10:06:50 rurban Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002, 2004 $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  * DONE: support author=[] (current user) and owner, creator
27  * to be able to have 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: 1.30 $");
44     }
45
46     function getDefaultArguments() {
47         return array_merge
48             (
49              PageList::supportedArgs(),
50              array(
51                    'noheader'      => false,
52                    'include_empty' => false,
53                    'info'          => '',
54                    'debug'         => false
55                    ));
56     }
57     
58     // info arg allows multiple columns
59     // info=mtime,hits,summary,version,author,locked,minor,markup or all
60     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
61     // sortby: [+|-] pagename|mtime|hits
62
63     // 2004-07-08 22:05:35 rurban: turned off &$request to prevent from strange bug below
64     function run($dbi, $argstr, &$request, $basepage) {
65         $args = $this->getArgs($argstr, $request);
66         // very strange php reference bug: dbi gets destroyed at array_merge with defaults
67         if (!is_object($dbi)) $dbi = $request->getDbh();
68         if (!is_object($request->_dbi)) {
69                 trigger_error("strange php reference bug destroyed request->_dbi", E_USER_WARNING);
70                 return HTML();
71         }
72         //extract($args);
73         $pages = isset($args['pages']) ? $args['pages'] : false;
74         // Todo: extend given _GET args
75         if ($sorted = $request->getArg('sortby'))
76             $args['sortby'] = $sorted;
77         elseif (!empty($args['sortby']))
78             $request->setArg('sortby',$args['sortby']);
79
80         if ($args['debug'])
81             $timer = new DebugTimer;
82         $caption = _("All pages in this wiki (%d total):");
83         if ( !empty($args['owner']) ) {
84             $pages = PageList::allPagesByOwner($args['owner'],$args['include_empty'],$args['sortby'],$args['limit']);
85             if ($args['owner'])
86                 $caption = fmt("List of pages owned by [%s] (%d total):", 
87                                WikiLink($args['owner'], 'if_known'),
88                                count($pages));
89         } elseif ( !empty($args['author']) ) {
90             $pages = PageList::allPagesByAuthor($args['author'],$args['include_empty'],$args['sortby'],$args['limit']);
91             if ($args['author'])
92                 $caption = fmt("List of pages last edited by [%s] (%d total):", 
93                                WikiLink($args['author'], 'if_known'), 
94                                count($pages));
95         } elseif ( !empty($args['creator']) ) {
96             $pages = PageList::allPagesByCreator($args['creator'],$args['include_empty'],$args['sortby'],$args['limit']);
97             if ($args['creator'])
98                 $caption = fmt("List of pages created by [%s] (%d total):", 
99                                WikiLink($args['creator'], 'if_known'), 
100                                count($pages));
101         } else {
102             if (! $request->getArg('count'))  $args['count'] = $dbi->numPages(false,$args['exclude']);
103             else $args['count'] = $request->getArg('count');
104             $pages = false;
105         }
106         if (empty($args['count']) and !empty($pages))
107             $args['count'] = count($pages);
108         $pagelist = new PageList($args['info'], $args['exclude'], $args);
109         if (!$args['noheader']) $pagelist->setCaption($caption);
110
111         // deleted pages show up as version 0.
112         if ($args['include_empty'])
113             $pagelist->_addColumn('version');
114
115         if ($pages !== false)
116             $pagelist->addPageList($pages);
117         else
118             $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit']) );
119         if ($args['debug']) {
120             return HTML($pagelist,
121                         HTML::p(fmt("Elapsed time: %s s", $timer->getStats())));
122         } else {
123             return $pagelist;
124         }
125     }
126
127     function getmicrotime(){
128         list($usec, $sec) = explode(" ",microtime());
129         return (float)$usec + (float)$sec;
130     }
131 };
132
133 // $Log: not supported by cvs2svn $
134 // Revision 1.29  2004/07/08 21:32:36  rurban
135 // Prevent from more warnings, minor db and sort optimizations
136 //
137 // Revision 1.28  2004/07/08 20:30:07  rurban
138 // plugin->run consistency: request as reference, added basepage.
139 // encountered strange bug in AllPages (and the test) which destroys ->_dbi
140 //
141 // Revision 1.27  2004/07/08 17:31:43  rurban
142 // improve numPages for file (fixing AllPagesTest)
143 //
144 // Revision 1.26  2004/06/21 16:22:32  rurban
145 // add DEFAULT_DUMP_DIR and HTML_DUMP_DIR constants, for easier cmdline dumps,
146 // fixed dumping buttons locally (images/buttons/),
147 // support pages arg for dumphtml,
148 // optional directory arg for dumpserial + dumphtml,
149 // fix a AllPages warning,
150 // show dump warnings/errors on DEBUG,
151 // don't warn just ignore on wikilens pagelist columns, if not loaded.
152 // RateIt pagelist column is called "rating", not "ratingwidget" (Dan?)
153 //
154 // Revision 1.25  2004/06/14 11:31:38  rurban
155 // renamed global $Theme to $WikiTheme (gforge nameclash)
156 // inherit PageList default options from PageList
157 //   default sortby=pagename
158 // use options in PageList_Selectable (limit, sortby, ...)
159 // added action revert, with button at action=diff
160 // added option regex to WikiAdminSearchReplace
161 //
162 // Revision 1.24  2004/06/13 16:02:12  rurban
163 // empty list of pages if user=[] and not authenticated.
164 //
165 // Revision 1.23  2004/06/13 15:51:37  rurban
166 // Support pagelist filter for current author,owner,creator by []
167 //
168 // Revision 1.22  2004/06/13 15:33:20  rurban
169 // new support for arguments owner, author, creator in most relevant
170 // PageList plugins. in WikiAdmin* via preSelectS()
171 //
172 // Revision 1.21  2004/04/20 00:06:53  rurban
173 // paging support
174 //
175 // Revision 1.20  2004/02/22 23:20:33  rurban
176 // fixed DumpHtmlToDir,
177 // enhanced sortby handling in PageList
178 //   new button_heading th style (enabled),
179 // added sortby and limit support to the db backends and plugins
180 //   for paging support (<<prev, next>> links on long lists)
181 //
182 // Revision 1.19  2004/02/17 12:11:36  rurban
183 // 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, ...)
184 //
185 // Revision 1.18  2004/01/25 07:58:30  rurban
186 // PageList sortby support in PearDB and ADODB backends
187 //
188 // Revision 1.17  2003/02/27 20:10:30  dairiki
189 // Disable profiling output when DEBUG is defined but false.
190 //
191 // Revision 1.16  2003/02/21 04:08:26  dairiki
192 // New class DebugTimer in prepend.php to help report timing.
193 //
194 // Revision 1.15  2003/01/18 21:19:25  carstenklapp
195 // Code cleanup:
196 // Reformatting; added copyleft, getVersion, getDescription
197 //
198
199 // Local Variables:
200 // mode: php
201 // tab-width: 8
202 // c-basic-offset: 4
203 // c-hanging-comment-ender-p: nil
204 // indent-tabs-mode: nil
205 // End:
206 ?>