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
39 function getDescription()
41 return _("Permanently remove all selected pages.");
44 function getDefaultArguments()
48 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
51 * Show only pages which have been 'deleted' this
52 * long (in days). (negative or non-numeric
53 * means show all pages, even non-deleted ones.)
55 * FIXME: could use a better name.
60 * Automatically check the checkboxes for files
61 * which have been 'deleted' this long (in days).
63 * FIXME: could use a better name.
66 /* Columns to include in listing */
71 function collectPages(&$list, &$dbi, $sortby, $limit = 0)
73 extract($this->_args);
77 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
78 while ($pagehandle = $allPages->next()) {
79 $pagename = $pagehandle->getName();
80 $current = $pagehandle->getCurrentRevision();
81 if ($current->getVersion() < 1)
82 continue; // No versions in database
84 $empty = $current->hasDefaultContents();
86 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
87 $checked = $age >= $max_age;
93 if ($age >= $min_age) {
94 if (empty($list[$pagename]))
95 $list[$pagename] = $checked;
101 function removePages(&$request, $pages)
103 $result = HTML::div();
105 $dbi = $request->getDbh();
107 foreach ($pages as $name) {
108 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
109 if (mayAccessPage('remove', $name)) {
110 $dbi->deletePage($name);
111 $ul->pushContent(HTML::li(fmt("Removed page ā%sā successfully.", $name)));
114 $ul->pushContent(HTML::li(fmt("Didn't remove page ā%sā. Access denied.", $name)));
119 $result->setAttr('class', 'feedback');
121 $result->pushContent(HTML::p(_("One page has been removed:")));
123 $result->pushContent(HTML::p(fmt("%d pages have been removed:", $count)));
125 $result->pushContent($ul);
128 $result->setAttr('class', 'error');
129 $result->pushContent(HTML::p(_("No pages removed.")));
134 function run($dbi, $argstr, &$request, $basepage)
136 if ($request->getArg('action') != 'browse') {
137 if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Remove")) {
138 return $this->disabled(_("Plugin not run: not in browse mode"));
142 $args = $this->getArgs($argstr, $request);
143 if (!is_numeric($args['min_age']))
144 $args['min_age'] = -1;
145 $this->_args =& $args;
146 /*if (!empty($args['exclude']))
147 $exclude = explodePageList($args['exclude']);
150 $this->preSelectS($args, $request);
152 $p = $request->getArg('p');
153 if (!$p) $p = $this->_list;
154 $post_args = $request->getArg('admin_remove');
156 $next_action = 'select';
158 if ($p && $request->isPost() &&
159 !empty($post_args['remove']) && empty($post_args['cancel'])
162 // check individual PagePermissions
163 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
164 $request->_notAuthorized(WIKIAUTH_ADMIN);
165 $this->disabled("! user->isAdmin");
167 if ($post_args['action'] == 'verify') {
169 return $this->removePages($request, array_keys($p));
172 if ($post_args['action'] == 'select') {
173 $next_action = 'verify';
174 foreach ($p as $name => $c) {
175 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
179 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
180 $next_action = 'verify';
181 foreach ($p as $name => $c) {
182 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
185 $request->setArg('p', false);
187 if ($next_action == 'select') {
188 // List all pages to select from.
189 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
191 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
194 => new _PageList_Column_remove('remove', _("Remove")))));
195 $pagelist->addPageList($pages);
197 $header = HTML::fieldset();
198 if ($next_action == 'verify') {
199 $button_label = _("Yes");
200 $header->pushContent(HTML::legend(_("Confirm removal")));
201 $header->pushContent(HTML::p(HTML::strong(
202 _("Are you sure you want to remove the selected files?"))));
204 $button_label = _("Remove selected pages");
205 $header->pushContent(HTML::legend(_("Select the files to remove")));
206 if ($args['min_age'] > 0) {
207 $header->pushContent(
208 fmt("Also pages which have been deleted at least %s days.",
212 if ($args['max_age'] > 0) {
213 $header->pushContent(
215 fmt("Pages which have been deleted at least %s days are already checked.",
220 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
221 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
222 $header->pushContent($buttons);
224 // TODO: quick select by regex javascript?
225 return HTML::form(array('action' => $request->getPostURL(),
228 $pagelist->getContent(),
229 HiddenInputs($request->getArgs(),
231 array('admin_remove')),
232 HiddenInputs(array('admin_remove[action]' => $next_action,
233 'require_authority_for_post' => WIKIAUTH_ADMIN)));
237 class _PageList_Column_remove extends _PageList_Column
239 function _getValue($page_handle, &$revision_handle)
241 return Button(array('action' => 'remove'), _("Remove"),
242 $page_handle->getName());
250 // c-hanging-comment-ender-p: nil
251 // indent-tabs-mode: nil