]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminPurge.php
Remove Width and Height preferences modification in Edit Toolbar
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminPurge.php
1 <?php
2
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 along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Usage:   <<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 getDescription()
34     {
35         return _("Permanently purge all selected pages.");
36     }
37
38     /* getDefaultArguments() is inherited from WikiAdminSelect class */
39
40     protected function collectPages(&$list, &$dbi, $sortby, $limit = 0)
41     {
42
43         $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
44         while ($pagehandle = $allPages->next()) {
45             $pagename = $pagehandle->getName();
46             $current = $pagehandle->getCurrentRevision();
47             if ($current->getVersion() < 1) {
48                 continue; // No versions in database
49             }
50             if (empty($list[$pagename])) {
51                 $list[$pagename] = false;
52             }
53         }
54         return $list;
55     }
56
57     private function purgePages(&$request, $pages)
58     {
59         $result = HTML::div();
60         $ul = HTML::ul();
61         $dbi = $request->getDbh();
62         $count = 0;
63         foreach ($pages as $name) {
64             $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
65             if (mayAccessPage('purge', $name)) {
66                 $dbi->purgePage($name);
67                 $ul->pushContent(HTML::li(fmt("Purged page ā€œ%sā€ successfully.", $name)));
68                 $count++;
69             } else {
70                 $ul->pushContent(HTML::li(fmt("Didn't purge page ā€œ%sā€. Access denied.", $name)));
71             }
72         }
73         if ($count) {
74             $dbi->touch();
75             $result->setAttr('class', 'feedback');
76             if ($count == 1) {
77                 $result->pushContent(HTML::p(_("One page has been permanently purged:")));
78             } else {
79                 $result->pushContent(HTML::p(fmt("%d pages have been permanently purged:", $count)));
80             }
81         } else {
82             $result->setAttr('class', 'error');
83             $result->pushContent(HTML::p(_("No pages purged.")));
84         }
85         $result->pushContent($ul);
86         return $result;
87     }
88
89     /**
90      * @param WikiDB $dbi
91      * @param string $argstr
92      * @param WikiRequest $request
93      * @param string $basepage
94      * @return mixed
95      */
96     function run($dbi, $argstr, &$request, $basepage)
97     {
98         if ($request->getArg('action') != 'browse') {
99             if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Purge")) {
100                 return $this->disabled(_("Plugin not run: not in browse mode"));
101             }
102         }
103
104         $args = $this->getArgs($argstr, $request);
105         $this->_args = $args;
106         $this->preSelectS($args, $request);
107
108         $p = $request->getArg('p');
109         if (!$p) $p = $this->_list;
110         $post_args = $request->getArg('admin_purge');
111
112         $next_action = 'select';
113         $pages = array();
114         if ($p && $request->isPost() &&
115             !empty($post_args['purge']) && empty($post_args['cancel'])
116         ) {
117             // without individual PagePermissions:
118             if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
119                 $request->_notAuthorized(WIKIAUTH_ADMIN);
120                 $this->disabled("! user->isAdmin");
121             }
122             if ($post_args['action'] == 'verify') {
123                 // Real purge.
124                 return $this->purgePages($request, array_keys($p));
125             }
126             if ($post_args['action'] == 'select') {
127                 $next_action = 'verify';
128                 foreach ($p as $name => $c) {
129                     $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
130                     $pages[$name] = $c;
131                 }
132             }
133         } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
134             $next_action = 'verify';
135             foreach ($p as $name => $c) {
136                 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
137                 $pages[$name] = $c;
138             }
139             $request->setArg('p', false);
140         }
141         if ($next_action == 'select') {
142             // List all pages to select from.
143             $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
144         }
145
146         $header = HTML::fieldset();
147         if ($next_action == 'verify') {
148             $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
149             $pagelist->addPageList($pages);
150             $button_label = _("Yes");
151             $header->pushContent(HTML::legend(_("Confirm purge")));
152             $header->pushContent(HTML::p(HTML::strong(
153                     _("Are you sure you want to permanently purge the following files?"))));
154         } else {
155             $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
156             $pagelist->addPageList($pages);
157             $button_label = _("Permanently purge selected pages");
158             $header->pushContent(HTML::legend(_("Select the files to purge")));
159         }
160
161         $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'),
162             Button('submit:admin_purge[cancel]', _("Cancel"), 'button'));
163         $header->pushContent($buttons);
164
165         return HTML::form(array('action' => $request->getPostURL(),
166                 'method' => 'post'),
167             $header,
168             $pagelist->getContent(),
169             HiddenInputs($request->getArgs(),
170                 false,
171                 array('admin_purge')),
172             HiddenInputs(array('admin_purge[action]' => $next_action,
173                 'require_authority_for_post' => WIKIAUTH_ADMIN)));
174     }
175 }
176
177 // Local Variables:
178 // mode: php
179 // tab-width: 8
180 // c-basic-offset: 4
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil
183 // End: