]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / AllPages.php
1 <?php // -*-php-*-
2 /**
3  * Copyright 1999,2000,2001,2002,2004,2005 $ThePhpWikiProgrammingTeam
4  *
5  * This file is part of PhpWiki.
6  *
7  * PhpWiki is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * PhpWiki is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 require_once 'lib/PageList.php';
23
24 /**
25  * Supports author=[] (current user), owner=[] and creator=[]
26  * to be able to have the action pages:
27  *   AllPagesCreatedByMe, AllPagesOwnedByMe, AllPagesLastAuthoredByMe
28  */
29 class WikiPlugin_AllPages
30 extends WikiPlugin
31 {
32     function getName () {
33         return _("AllPages");
34     }
35
36     function getDescription () {
37         return _("List all pages in this wiki.");
38     }
39
40     function getDefaultArguments() {
41         return array_merge
42             (
43              PageList::supportedArgs(),
44              array(
45                    'noheader'      => false,
46                    'include_empty' => false,
47                    'info'          => '',
48                    'debug'         => false,
49                    'userpages'     => false
50                    ));
51     }
52
53     // info arg allows multiple columns
54     // info=mtime,hits,summary,version,author,locked,minor,markup or all
55     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
56     // sortby: [+|-] pagename|mtime|hits
57
58     // 2004-07-08 22:05:35 rurban: turned off &$request to prevent from strange bug below
59     function run($dbi, $argstr, $request, $basepage) {
60         $args = $this->getArgs($argstr, $request);
61
62         $pages = false;
63         // Todo: extend given _GET args
64         if (DEBUG && $args['debug']) {
65             $timer = new DebugTimer;
66         }
67         $caption = _("All pages in this wiki (%d total):");
68
69         if ( !empty($args['userpages']) ) {
70             $pages = PageList::allUserPages($args['include_empty'],
71                                                $args['sortby'], ''
72                                                );
73             $caption = _("List of user-created pages (%d total):");
74             $args['count'] = $request->getArg('count');
75         } elseif ( !empty($args['owner']) ) {
76             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'],
77                                                $args['sortby'], ''
78                                                );
79             $args['count'] = $request->getArg('count');
80             if (!$args['count'])
81                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
82             $caption = fmt("List of pages owned by [%s] (%d total):",
83                            WikiLink($args['owner'] == '[]'
84                                     ? $request->_user->getAuthenticatedId()
85                                     : $args['owner'],
86                                     'if_known'), $args['count']);
87             $pages->_options['count'] = $args['count'];
88         } elseif ( !empty($args['author']) ) {
89             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'],
90                                                 $args['sortby'], ''
91                                                 );
92             $args['count'] = $request->getArg('count');
93             if (!$args['count'])
94                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
95             $caption = fmt("List of pages last edited by [%s] (%d total):",
96                            WikiLink($args['author'] == '[]'
97                                     ? $request->_user->getAuthenticatedId()
98                                     : $args['author'],
99                                     'if_known'), $args['count']);
100             $pages->_options['count'] = $args['count'];
101         } elseif ( !empty($args['creator']) ) {
102             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'],
103                                                  $args['sortby'], ''
104                                                  );
105             $args['count'] = $request->getArg('count');
106             if (!$args['count'])
107                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
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'), $args['count']);
113             $pages->_options['count'] = $args['count'];
114         //} elseif ($pages) {
115         //    $args['count'] = count($pages);
116         } else {
117             if (! $request->getArg('count'))
118                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
119             else
120                 $args['count'] = $request->getArg('count');
121         }
122         if (empty($args['count']) and !empty($pages))
123             $args['count'] = count($pages);
124         $pagelist = new PageList($args['info'], $args['exclude'], $args);
125         if (!$args['noheader']) $pagelist->setCaption($caption);
126
127         // deleted pages show up as version 0.
128         //if ($args['include_empty'])
129         //    $pagelist->_addColumn('version');
130
131         if ($pages !== false)
132             $pagelist->addPageList($pages);
133         else
134             $pagelist->addPages( $dbi->getAllPages($args['include_empty'], $args['sortby'],
135                                                    $args['limit']) );
136         if (DEBUG && $args['debug']) {
137             return HTML($pagelist,
138                         HTML::p(fmt("Elapsed time: %s s", $timer->getStats())));
139         } else {
140             return $pagelist;
141         }
142     }
143 };
144
145 // Local Variables:
146 // mode: php
147 // tab-width: 8
148 // c-basic-offset: 4
149 // c-hanging-comment-ender-p: nil
150 // indent-tabs-mode: nil
151 // End: