]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
Whitespace only
[SourceForge/phpwiki.git] / lib / plugin / AllPages.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 getDefaultArguments() {
42         return array_merge
43             (
44              PageList::supportedArgs(),
45              array(
46                    'noheader'      => false,
47                    'include_empty' => false,
48                    'info'          => '',
49                    'debug'         => false,
50                    'userpages'     => false
51                    ));
52     }
53
54     // info arg allows multiple columns
55     // info=mtime,hits,summary,version,author,locked,minor,markup or all
56     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
57     // sortby: [+|-] pagename|mtime|hits
58
59     // 2004-07-08 22:05:35 rurban: turned off &$request to prevent from strange bug below
60     function run($dbi, $argstr, $request, $basepage) {
61         $args = $this->getArgs($argstr, $request);
62
63         $pages = false;
64         // Todo: extend given _GET args
65         if (DEBUG && $args['debug']) {
66             $timer = new DebugTimer;
67         }
68         $caption = _("All pages in this wiki (%d total):");
69
70         if ( !empty($args['userpages']) ) {
71             $pages = PageList::allUserPages($args['include_empty'],
72                                                $args['sortby'], ''
73                                                );
74             $caption = _("List of user-created pages (%d total):");
75             $args['count'] = $request->getArg('count');
76         } elseif ( !empty($args['owner']) ) {
77             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
78                                                $args['sortby'], ''
79                                                );
80             $args['count'] = $request->getArg('count');
81             if (!$args['count'])
82                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
83             $caption = fmt("List of pages owned by [%s] (%d total):",
84                            WikiLink($args['owner'] == '[]'
85                                     ? $request->_user->getAuthenticatedId()
86                                     : $args['owner'],
87                                     'if_known'), $args['count']);
88             $pages->_options['count'] = $args['count'];
89         } elseif ( !empty($args['author']) ) {
90             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
91                                                 $args['sortby'], ''
92                                                 );
93             $args['count'] = $request->getArg('count');
94             if (!$args['count'])
95                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
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'), $args['count']);
101             $pages->_options['count'] = $args['count'];
102         } elseif ( !empty($args['creator']) ) {
103             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
104                                                  $args['sortby'], ''
105                                                  );
106             $args['count'] = $request->getArg('count');
107             if (!$args['count'])
108                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
109             $caption = fmt("List of pages created by [%s] (%d total):",
110                            WikiLink($args['creator'] == '[]'
111                                     ? $request->_user->getAuthenticatedId()
112                                     : $args['creator'],
113                                     'if_known'), $args['count']);
114             $pages->_options['count'] = $args['count'];
115         //} elseif ($pages) {
116         //    $args['count'] = count($pages);
117         } else {
118             if (! $request->getArg('count'))
119                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
120             else
121                 $args['count'] = $request->getArg('count');
122         }
123         if (empty($args['count']) and !empty($pages))
124             $args['count'] = count($pages);
125         $pagelist = new PageList($args['info'], $args['exclude'], $args);
126         if (!$args['noheader']) $pagelist->setCaption($caption);
127
128         // deleted pages show up as version 0.
129         //if ($args['include_empty'])
130         //    $pagelist->_addColumn('version');
131
132         if ($pages !== false)
133             $pagelist->addPageList($pages);
134         else
135             $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'],
136                                                    $args['limit']) );
137         if (DEBUG && $args['debug']) {
138             return HTML($pagelist,
139                         HTML::p(fmt("Elapsed time: %s s", $timer->getStats())));
140         } else {
141             return $pagelist;
142         }
143     }
144 };
145
146 // Local Variables:
147 // mode: php
148 // tab-width: 8
149 // c-basic-offset: 4
150 // c-hanging-comment-ender-p: nil
151 // indent-tabs-mode: nil
152 // End: