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
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Usage: <?plugin WikiAdminRemove?>
26 * Author: Reini Urban <rurban@x-ray.at>
29 * Currently we must be Admin.
30 * Future versions will support PagePermissions.
31 * requires PHP 4.2 so far.
33 // maybe display more attributes with this class...
34 require_once('lib/PageList.php');
35 require_once('lib/plugin/WikiAdminSelect.php');
37 class WikiPlugin_WikiAdminRemove
38 extends WikiPlugin_WikiAdminSelect
41 return _("WikiAdminRemove");
44 function getDescription() {
45 return _("Permanently remove all selected pages.");
48 function getDefaultArguments() {
51 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
54 * Show only pages which have been 'deleted' this
55 * long (in days). (negative or non-numeric
56 * means show all pages, even non-deleted ones.)
58 * FIXME: could use a better name.
63 * Automatically check the checkboxes for files
64 * which have been 'deleted' this long (in days).
66 * FIXME: could use a better name.
69 /* Columns to include in listing */
74 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
75 extract($this->_args);
79 $allPages = $dbi->getAllPages('include_empty',$sortby,$limit);
80 while ($pagehandle = $allPages->next()) {
81 $pagename = $pagehandle->getName();
82 $current = $pagehandle->getCurrentRevision();
83 if ($current->getVersion() < 1)
84 continue; // No versions in database
86 $empty = $current->hasDefaultContents();
88 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
89 $checked = $age >= $max_age;
96 if ($age >= $min_age) {
97 if (empty($list[$pagename]))
98 $list[$pagename] = $checked;
104 function removePages(&$request, $pages) {
105 $result = HTML::div();
107 $dbi = $request->getDbh(); $count = 0;
108 foreach ($pages as $name) {
109 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
110 if (mayAccessPage('remove',$name)) {
111 $dbi->deletePage($name);
112 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
115 $ul->pushContent(HTML::li(fmt("Didn't remove page '%s'. Access denied.", $name)));
120 $result->setAttr('class', 'feedback');
122 $result->pushContent(HTML::p("One page has been permanently removed:"));
124 $result->pushContent(HTML::p(fmt("%s pages have been permanently removed:", $count)));
126 $result->pushContent($ul);
129 $result->setAttr('class', 'error');
130 $result->pushContent(HTML::p("No pages removed."));
135 function run($dbi, $argstr, &$request, $basepage) {
136 if ($request->getArg('action') != 'browse')
137 if ($request->getArg('action') != _("PhpWikiAdministration/Remove"))
138 return $this->disabled("(action != 'browse')");
140 $args = $this->getArgs($argstr, $request);
141 if (!is_numeric($args['min_age']))
142 $args['min_age'] = -1;
143 $this->_args =& $args;
144 /*if (!empty($args['exclude']))
145 $exclude = explodePageList($args['exclude']);
148 $this->preSelectS($args, $request);
150 $p = $request->getArg('p');
151 if (!$p) $p = $this->_list;
152 $post_args = $request->getArg('admin_remove');
154 $next_action = 'select';
156 if ($p && $request->isPost() &&
157 !empty($post_args['remove']) && empty($post_args['cancel'])) {
159 // check individual PagePermissions
160 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
161 $request->_notAuthorized(WIKIAUTH_ADMIN);
162 $this->disabled("! user->isAdmin");
164 if ($post_args['action'] == 'verify') {
166 return $this->removePages($request, array_keys($p));
169 if ($post_args['action'] == 'select') {
170 $next_action = 'verify';
171 foreach ($p as $name => $c) {
172 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
176 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
177 $next_action = 'verify';
178 foreach ($p as $name => $c) {
179 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
182 $request->setArg('p',false);
184 if ($next_action == 'select') {
185 // List all pages to select from.
186 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
188 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
191 => new _PageList_Column_remove('remove', _("Remove")))));
192 $pagelist->addPageList($pages);
194 $header = HTML::fieldset();
195 if ($next_action == 'verify') {
196 $button_label = _("Yes");
197 $header->pushContent(HTML::p(HTML::strong(
198 _("Are you sure you want to permanently remove the selected files?"))));
201 $button_label = _("Remove selected pages");
202 $header->pushContent(HTML::legend(_("Select the files to remove")));
203 if ($args['min_age'] > 0) {
204 $header->pushContent(
205 fmt("Also pages which have been deleted at least %s days.",
209 if ($args['max_age'] > 0) {
210 $header->pushContent(
212 fmt("Pages which have been deleted at least %s days are already checked.",
217 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
218 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
219 $header->pushContent($buttons);
221 // TODO: quick select by regex javascript?
222 return HTML::form(array('action' => $request->getPostURL(),
225 $pagelist->getContent(),
226 HiddenInputs($request->getArgs(),
228 array('admin_remove')),
229 HiddenInputs(array('admin_remove[action]' => $next_action,
230 'require_authority_for_post' => WIKIAUTH_ADMIN)));
234 class _PageList_Column_remove extends _PageList_Column {
235 function _getValue ($page_handle, &$revision_handle) {
236 return Button(array('action' => 'remove'), _("Remove"),
237 $page_handle->getName());
245 // c-hanging-comment-ender-p: nil
246 // indent-tabs-mode: nil