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 getVersion() {
49 return preg_replace("/[Revision: $]/", '',
53 function getDefaultArguments() {
56 PageList::supportedArgs(),
60 * Show only pages which have been 'deleted' this
61 * long (in days). (negative or non-numeric
62 * means show all pages, even non-deleted ones.)
64 * FIXME: could use a better name.
69 * Automatically check the checkboxes for files
70 * which have been 'deleted' this long (in days).
72 * FIXME: could use a better name.
75 /* Columns to include in listing */
80 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
81 extract($this->_args);
85 $allPages = $dbi->getAllPages('include_empty',$sortby,$limit);
86 while ($pagehandle = $allPages->next()) {
87 $pagename = $pagehandle->getName();
88 $current = $pagehandle->getCurrentRevision();
89 if ($current->getVersion() < 1)
90 continue; // No versions in database
92 $empty = $current->hasDefaultContents();
94 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
95 $checked = $age >= $max_age;
102 if ($age >= $min_age) {
103 if (empty($list[$pagename]))
104 $list[$pagename] = $checked;
110 function removePages(&$request, $pages) {
111 $result = HTML::div();
113 $dbi = $request->getDbh(); $count = 0;
114 foreach ($pages as $name) {
115 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
116 if (mayAccessPage('remove',$name)) {
117 $dbi->deletePage($name);
118 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
121 $ul->pushContent(HTML::li(fmt("Didn't remove page '%s'. Access denied.", $name)));
126 $result->setAttr('class', 'feedback');
128 $result->pushContent(HTML::p("One page has been permanently removed:"));
130 $result->pushContent(HTML::p(fmt("%s pages have been permanently removed:", $count)));
132 $result->pushContent($ul);
135 $result->setAttr('class', 'error');
136 $result->pushContent(HTML::p("No pages removed."));
141 function run($dbi, $argstr, &$request, $basepage) {
142 if ($request->getArg('action') != 'browse')
143 if ($request->getArg('action') != _("PhpWikiAdministration/Remove"))
144 return $this->disabled("(action != 'browse')");
146 $args = $this->getArgs($argstr, $request);
147 if (!is_numeric($args['min_age']))
148 $args['min_age'] = -1;
149 $this->_args =& $args;
150 /*if (!empty($args['exclude']))
151 $exclude = explodePageList($args['exclude']);
154 $this->preSelectS($args, $request);
156 $p = $request->getArg('p');
157 if (!$p) $p = $this->_list;
158 $post_args = $request->getArg('admin_remove');
160 $next_action = 'select';
162 if ($p && $request->isPost() &&
163 !empty($post_args['remove']) && empty($post_args['cancel'])) {
165 // check individual PagePermissions
166 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
167 $request->_notAuthorized(WIKIAUTH_ADMIN);
168 $this->disabled("! user->isAdmin");
170 if ($post_args['action'] == 'verify') {
172 return $this->removePages($request, array_keys($p));
175 if ($post_args['action'] == 'select') {
176 $next_action = 'verify';
177 foreach ($p as $name => $c) {
178 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
182 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
183 $next_action = 'verify';
184 foreach ($p as $name => $c) {
185 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
188 $request->setArg('p',false);
190 if ($next_action == 'select') {
191 // List all pages to select from.
192 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
194 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
197 => new _PageList_Column_remove('remove', _("Remove")))));
198 $pagelist->addPageList($pages);
200 $header = HTML::fieldset();
201 if ($next_action == 'verify') {
202 $button_label = _("Yes");
203 $header->pushContent(HTML::p(HTML::strong(
204 _("Are you sure you want to permanently remove the selected files?"))));
207 $button_label = _("Remove selected pages");
208 $header->pushContent(HTML::legend(_("Select the files to remove")));
209 if ($args['min_age'] > 0) {
210 $header->pushContent(
211 fmt("Also pages which have been deleted at least %s days.",
215 if ($args['max_age'] > 0) {
216 $header->pushContent(
218 fmt("Pages which have been deleted at least %s days are already checked.",
223 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
224 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
225 $header->pushContent($buttons);
227 // TODO: quick select by regex javascript?
228 return HTML::form(array('action' => $request->getPostURL(),
231 $pagelist->getContent(),
232 HiddenInputs($request->getArgs(),
234 array('admin_remove')),
235 HiddenInputs(array('admin_remove[action]' => $next_action,
236 'require_authority_for_post' => WIKIAUTH_ADMIN)));
240 class _PageList_Column_remove extends _PageList_Column {
241 function _getValue ($page_handle, &$revision_handle) {
242 return Button(array('action' => 'remove'), _("Remove"),
243 $page_handle->getName());
251 // c-hanging-comment-ender-p: nil
252 // indent-tabs-mode: nil