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 WikiPlugin_WikiAdminSelect::getDefaultArguments(),
59 * Show only pages which have been 'deleted' this
60 * long (in days). (negative or non-numeric
61 * means show all pages, even non-deleted ones.)
63 * FIXME: could use a better name.
68 * Automatically check the checkboxes for files
69 * which have been 'deleted' this long (in days).
71 * FIXME: could use a better name.
74 /* Columns to include in listing */
79 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
80 extract($this->_args);
84 $allPages = $dbi->getAllPages('include_empty',$sortby,$limit);
85 while ($pagehandle = $allPages->next()) {
86 $pagename = $pagehandle->getName();
87 $current = $pagehandle->getCurrentRevision();
88 if ($current->getVersion() < 1)
89 continue; // No versions in database
91 $empty = $current->hasDefaultContents();
93 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
94 $checked = $age >= $max_age;
101 if ($age >= $min_age) {
102 if (empty($list[$pagename]))
103 $list[$pagename] = $checked;
109 function removePages(&$request, $pages) {
110 $result = HTML::div();
112 $dbi = $request->getDbh(); $count = 0;
113 foreach ($pages as $name) {
114 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
115 if (mayAccessPage('remove',$name)) {
116 $dbi->deletePage($name);
117 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
120 $ul->pushContent(HTML::li(fmt("Didn't remove page '%s'. Access denied.", $name)));
125 $result->setAttr('class', 'feedback');
127 $result->pushContent(HTML::p("One page has been permanently removed:"));
129 $result->pushContent(HTML::p(fmt("%s pages have been permanently removed:", $count)));
131 $result->pushContent($ul);
134 $result->setAttr('class', 'error');
135 $result->pushContent(HTML::p("No pages removed."));
140 function run($dbi, $argstr, &$request, $basepage) {
141 if ($request->getArg('action') != 'browse')
142 if ($request->getArg('action') != _("PhpWikiAdministration/Remove"))
143 return $this->disabled("(action != 'browse')");
145 $args = $this->getArgs($argstr, $request);
146 if (!is_numeric($args['min_age']))
147 $args['min_age'] = -1;
148 $this->_args =& $args;
149 /*if (!empty($args['exclude']))
150 $exclude = explodePageList($args['exclude']);
153 $this->preSelectS($args, $request);
155 $p = $request->getArg('p');
156 if (!$p) $p = $this->_list;
157 $post_args = $request->getArg('admin_remove');
159 $next_action = 'select';
161 if ($p && $request->isPost() &&
162 !empty($post_args['remove']) && empty($post_args['cancel'])) {
164 // check individual PagePermissions
165 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
166 $request->_notAuthorized(WIKIAUTH_ADMIN);
167 $this->disabled("! user->isAdmin");
169 if ($post_args['action'] == 'verify') {
171 return $this->removePages($request, array_keys($p));
174 if ($post_args['action'] == 'select') {
175 $next_action = 'verify';
176 foreach ($p as $name => $c) {
177 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
181 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
182 $next_action = 'verify';
183 foreach ($p as $name => $c) {
184 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
187 $request->setArg('p',false);
189 if ($next_action == 'select') {
190 // List all pages to select from.
191 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
193 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
196 => new _PageList_Column_remove('remove', _("Remove")))));
197 $pagelist->addPageList($pages);
199 $header = HTML::fieldset();
200 if ($next_action == 'verify') {
201 $button_label = _("Yes");
202 $header->pushContent(HTML::p(HTML::strong(
203 _("Are you sure you want to permanently remove the selected files?"))));
206 $button_label = _("Remove selected pages");
207 $header->pushContent(HTML::legend(_("Select the files to remove")));
208 if ($args['min_age'] > 0) {
209 $header->pushContent(
210 fmt("Also pages which have been deleted at least %s days.",
214 if ($args['max_age'] > 0) {
215 $header->pushContent(
217 fmt("Pages which have been deleted at least %s days are already checked.",
222 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
223 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
224 $header->pushContent($buttons);
226 // TODO: quick select by regex javascript?
227 return HTML::form(array('action' => $request->getPostURL(),
230 $pagelist->getContent(),
231 HiddenInputs($request->getArgs(),
233 array('admin_remove')),
234 HiddenInputs(array('admin_remove[action]' => $next_action,
235 'require_authority_for_post' => WIKIAUTH_ADMIN)));
239 class _PageList_Column_remove extends _PageList_Column {
240 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