4 * Copyright 2002,2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
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.
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.
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.
25 * Usage: <<WikiAdminRemove>>
26 * Author: Reini Urban <rurban@x-ray.at>
29 * Currently we must be Admin.
30 * Future versions will support PagePermissions.
32 // maybe display more attributes with this class...
33 require_once 'lib/PageList.php';
34 require_once 'lib/plugin/WikiAdminSelect.php';
36 class WikiPlugin_WikiAdminRemove
37 extends WikiPlugin_WikiAdminSelect
41 return _("WikiAdminRemove");
44 function getDescription()
46 return _("Permanently remove all selected pages.");
49 function getDefaultArguments()
53 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
56 * Show only pages which have been 'deleted' this
57 * long (in days). (negative or non-numeric
58 * means show all pages, even non-deleted ones.)
60 * FIXME: could use a better name.
65 * Automatically check the checkboxes for files
66 * which have been 'deleted' this long (in days).
68 * FIXME: could use a better name.
71 /* Columns to include in listing */
76 function collectPages(&$list, &$dbi, $sortby, $limit = 0)
78 extract($this->_args);
82 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
83 while ($pagehandle = $allPages->next()) {
84 $pagename = $pagehandle->getName();
85 $current = $pagehandle->getCurrentRevision();
86 if ($current->getVersion() < 1)
87 continue; // No versions in database
89 $empty = $current->hasDefaultContents();
91 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
92 $checked = $age >= $max_age;
98 if ($age >= $min_age) {
99 if (empty($list[$pagename]))
100 $list[$pagename] = $checked;
106 function removePages(&$request, $pages)
108 $result = HTML::div();
110 $dbi = $request->getDbh();
112 foreach ($pages as $name) {
113 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
114 if (mayAccessPage('remove', $name)) {
115 $dbi->deletePage($name);
116 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
119 $ul->pushContent(HTML::li(fmt("Didn't remove page '%s'. Access denied.", $name)));
124 $result->setAttr('class', 'feedback');
126 $result->pushContent(HTML::p(_("One page has been removed:")));
128 $result->pushContent(HTML::p(fmt("%d pages have been removed:", $count)));
130 $result->pushContent($ul);
133 $result->setAttr('class', 'error');
134 $result->pushContent(HTML::p(_("No pages removed.")));
139 function run($dbi, $argstr, &$request, $basepage)
141 if ($request->getArg('action') != 'browse') {
142 if ($request->getArg('action') != _("PhpWikiAdministration/Remove")) {
143 return $this->disabled(_("Plugin not run: not in browse mode"));
147 $args = $this->getArgs($argstr, $request);
148 if (!is_numeric($args['min_age']))
149 $args['min_age'] = -1;
150 $this->_args =& $args;
151 /*if (!empty($args['exclude']))
152 $exclude = explodePageList($args['exclude']);
155 $this->preSelectS($args, $request);
157 $p = $request->getArg('p');
158 if (!$p) $p = $this->_list;
159 $post_args = $request->getArg('admin_remove');
161 $next_action = 'select';
163 if ($p && $request->isPost() &&
164 !empty($post_args['remove']) && empty($post_args['cancel'])
167 // check individual PagePermissions
168 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
169 $request->_notAuthorized(WIKIAUTH_ADMIN);
170 $this->disabled("! user->isAdmin");
172 if ($post_args['action'] == 'verify') {
174 return $this->removePages($request, array_keys($p));
177 if ($post_args['action'] == 'select') {
178 $next_action = 'verify';
179 foreach ($p as $name => $c) {
180 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
184 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
185 $next_action = 'verify';
186 foreach ($p as $name => $c) {
187 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
190 $request->setArg('p', false);
192 if ($next_action == 'select') {
193 // List all pages to select from.
194 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
196 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
199 => new _PageList_Column_remove('remove', _("Remove")))));
200 $pagelist->addPageList($pages);
202 $header = HTML::fieldset();
203 if ($next_action == 'verify') {
204 $button_label = _("Yes");
205 $header->pushContent(HTML::legend(_("Confirm removal")));
206 $header->pushContent(HTML::p(HTML::strong(
207 _("Are you sure you want to remove the selected files?"))));
209 $button_label = _("Remove selected pages");
210 $header->pushContent(HTML::legend(_("Select the files to remove")));
211 if ($args['min_age'] > 0) {
212 $header->pushContent(
213 fmt("Also pages which have been deleted at least %s days.",
217 if ($args['max_age'] > 0) {
218 $header->pushContent(
220 fmt("Pages which have been deleted at least %s days are already checked.",
225 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
226 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
227 $header->pushContent($buttons);
229 // TODO: quick select by regex javascript?
230 return HTML::form(array('action' => $request->getPostURL(),
233 $pagelist->getContent(),
234 HiddenInputs($request->getArgs(),
236 array('admin_remove')),
237 HiddenInputs(array('admin_remove[action]' => $next_action,
238 'require_authority_for_post' => WIKIAUTH_ADMIN)));
242 class _PageList_Column_remove extends _PageList_Column
244 function _getValue($page_handle, &$revision_handle)
246 return Button(array('action' => 'remove'), _("Remove"),
247 $page_handle->getName());
257 // c-hanging-comment-ender-p: nil
258 // indent-tabs-mode: nil