]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminPurge.php
WikiAdminPurge
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminPurge.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminPurge.php 6286 2008-10-02 10:01:29Z vargenau $');
3 /*
4  Copyright 2002,2004 $ThePhpWikiProgrammingTeam
5  Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
6
7  This file is part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 /**
25  * Usage:   <?plugin WikiAdminPurge?>
26  */
27 require_once('lib/PageList.php');
28 require_once('lib/plugin/WikiAdminSelect.php');
29
30 class WikiPlugin_WikiAdminPurge
31 extends WikiPlugin_WikiAdminSelect
32 {
33     function getName() {
34         return _("WikiAdminPurge");
35     }
36
37     function getDescription() {
38         return _("Permanently purge all selected pages.");
39     }
40
41     function getVersion() {
42         return preg_replace("/[Revision: $]/", '',
43                             "\$Revision: 6286 $");
44     }
45
46     function getDefaultArguments() {
47         return array_merge
48             (
49              PageList::supportedArgs(),
50              array(
51                    's'  => false,
52                      /* Columns to include in listing */
53                      'info'     => 'most',
54                    ));
55     }
56
57     function collectPages(&$list, &$dbi, $sortby, $limit=0) {
58         return $list;
59     }
60
61     function purgePages(&$request, $pages) {
62         $ul = HTML::ul();
63         $dbi = $request->getDbh(); $count = 0;
64         foreach ($pages as $name) {
65             $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
66             if (mayAccessPage('purge',$name)) {
67                 $dbi->purgePage($name);
68                 $ul->pushContent(HTML::li(fmt("Purged page '%s' successfully.", $name)));
69                 $count++;
70             } else {
71                 $ul->pushContent(HTML::li(fmt("Didn't purge page '%s'. Access denied.", $name)));
72             }
73         }
74         if ($count) $dbi->touch();
75         return HTML($ul,
76                     HTML::p(fmt("%d pages have been permanently purged.",$count)));
77     }
78     
79     function run($dbi, $argstr, &$request, $basepage) {
80         if ($request->getArg('action') != 'browse')
81             if ($request->getArg('action') != _("PhpWikiAdministration/Purge"))
82                 return $this->disabled("(action != 'browse')");
83         
84         $args = $this->getArgs($argstr, $request);
85         $this->_args =& $args;
86         $this->preSelectS($args, $request);
87
88         $p = $request->getArg('p');
89         if (!$p) $p = $this->_list;
90         $post_args = $request->getArg('admin_purge');
91
92         $next_action = 'select';
93         $pages = array();
94         if ($p && $request->isPost() &&
95             !empty($post_args['purge']) && empty($post_args['cancel'])) {
96
97             // check individual PagePermissions
98             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
99                 $request->_notAuthorized(WIKIAUTH_ADMIN);
100                 $this->disabled("! user->isAdmin");
101             }
102             if ($post_args['action'] == 'verify') {
103                 // Real purge.
104                 return $this->purgePages($request, array_keys($p));
105             }
106
107             if ($post_args['action'] == 'select') {
108                 $next_action = 'verify';
109                 foreach ($p as $name => $c) {
110                     $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
111                     $pages[$name] = $c;
112                 }
113             }
114         } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
115             $next_action = 'verify';
116             foreach ($p as $name => $c) {
117                 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
118                 $pages[$name] = $c;
119             }
120             $request->setArg('p',false);
121         }
122         if ($next_action == 'select') {
123             // List all pages to select from.
124             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
125         }
126         $pagelist = new PageList_UnSelectable($args['info'], $args['exclude'], array());
127         $pagelist->addPageList($pages);
128
129         $header = HTML::p();
130         if ($next_action == 'verify') {
131             $button_label = _("Yes");
132             $header->pushContent(HTML::strong(
133                 _("Are you sure you want to permanently purge the following files?")));
134         }
135         else {
136             $button_label = _("Purge selected pages");
137             $header->pushContent(_("Permanently purge the selected files:"),HTML::br());
138         }
139
140         $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'),
141                            Button('submit:admin_purge[cancel]', _("Cancel"), 'button'));
142
143         // TODO: quick select by regex javascript?
144         return HTML::form(array('action' => $request->getPostURL(),
145                                 'method' => 'post'),
146                           $header,
147                           $buttons,
148                           $pagelist->getContent(),
149                           HiddenInputs($request->getArgs(),
150                                         false,
151                                         array('admin_purge')),
152                           HiddenInputs(array('admin_purge[action]' => $next_action,
153                                              'require_authority_for_post' => WIKIAUTH_ADMIN)));
154     }
155 }
156
157 // Local Variables:
158 // mode: php
159 // tab-width: 8
160 // c-basic-offset: 4
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil
163 // End:
164 ?>