]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AllPages.php
Sort by pagename by default
[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 getDescription()
34     {
35         return _("List all pages in this wiki.");
36     }
37
38     function getDefaultArguments()
39     {
40         return array_merge
41         (
42             PageList::supportedArgs(),
43             array(
44                 'noheader' => false,
45                 'include_empty' => false,
46                 'info' => '',
47                 'userpages' => false
48             ));
49     }
50
51     // info arg allows multiple columns
52     // info=mtime,hits,summary,version,author,locked,minor,markup or all
53     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
54     // sortby: [+|-] pagename|mtime|hits
55
56     /**
57      * @param WikiDB $dbi
58      * @param string $argstr
59      * @param WikiRequest $request
60      * @param string $basepage
61      * @return bool
62      */
63     function run($dbi, $argstr, &$request, $basepage)
64     {
65         $args = $this->getArgs($argstr, $request);
66
67         if (empty($args['sortby'])) {
68             $args['sortby'] = 'pagename';
69         }
70
71         $pages = false;
72         // Todo: extend given _GET args
73         $caption = _("All pages in this wiki (%d total):");
74
75         if (!empty($args['userpages'])) {
76             $pages = PageList::allUserPages($args['include_empty'], $args['sortby'], '');
77             $caption = _("List of user-created pages (%d total):");
78             $args['count'] = count($pages);
79         } elseif (!empty($args['owner'])) {
80             $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], '');
81             $args['count'] = count($pages);
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         } elseif (!empty($args['author'])) {
88             $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], '');
89             $args['count'] = count($pages);
90             $caption = fmt("List of pages last edited by %s (%d total):",
91                 WikiLink($args['author'] == '[]'
92                         ? $request->_user->getAuthenticatedId()
93                         : $args['author'],
94                     'if_known'), $args['count']);
95         } elseif (!empty($args['creator'])) {
96             $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], '');
97             $args['count'] = count($pages);
98             $caption = fmt("List of pages created by %s (%d total):",
99                 WikiLink($args['creator'] == '[]'
100                         ? $request->_user->getAuthenticatedId()
101                         : $args['creator'],
102                     'if_known'), $args['count']);
103         } elseif ($pages) {
104             $args['count'] = count($pages);
105         } else {
106             if (!$request->getArg('count'))
107                 $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']);
108             else
109                 $args['count'] = $request->getArg('count');
110         }
111         if (empty($args['count']) and !empty($pages)) {
112             $args['count'] = count($pages);
113         }
114         $pagelist = new PageList($args['info'], $args['exclude'], $args);
115         if (!$args['noheader']) {
116             $pagelist->setCaption($caption);
117         }
118
119         if ($pages !== false)
120             $pagelist->addPageList($pages);
121         else
122             $pagelist->addPages($dbi->getAllPages($args['include_empty'], $args['sortby'],
123                 $args['limit']));
124         return $pagelist;
125     }
126 }
127
128 // Local Variables:
129 // mode: php
130 // tab-width: 8
131 // c-basic-offset: 4
132 // c-hanging-comment-ender-p: nil
133 // indent-tabs-mode: nil
134 // End: