4 Copyright 2002,2004 $ThePhpWikiProgrammingTeam
5 Copyright 2008 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) {
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 removed page '%s'. Access denied.", $name)));
123 if ($count) $dbi->touch();
125 HTML::p(fmt("%d pages have been permanently removed.",$count)));
128 function run($dbi, $argstr, &$request, $basepage) {
129 if ($request->getArg('action') != 'browse')
130 if ($request->getArg('action') != _("PhpWikiAdministration/Remove"))
131 return $this->disabled("(action != 'browse')");
133 $args = $this->getArgs($argstr, $request);
134 if (!is_numeric($args['min_age']))
135 $args['min_age'] = -1;
136 $this->_args =& $args;
137 /*if (!empty($args['exclude']))
138 $exclude = explodePageList($args['exclude']);
141 $this->preSelectS($args, $request);
143 $p = $request->getArg('p');
144 if (!$p) $p = $this->_list;
145 $post_args = $request->getArg('admin_remove');
147 $next_action = 'select';
149 if ($p && $request->isPost() &&
150 !empty($post_args['remove']) && empty($post_args['cancel'])) {
152 // check individual PagePermissions
153 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
154 $request->_notAuthorized(WIKIAUTH_ADMIN);
155 $this->disabled("! user->isAdmin");
157 if ($post_args['action'] == 'verify') {
159 return $this->removePages($request, array_keys($p));
162 if ($post_args['action'] == 'select') {
163 $next_action = 'verify';
164 foreach ($p as $name => $c) {
165 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
169 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
170 $next_action = 'verify';
171 foreach ($p as $name => $c) {
172 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
175 $request->setArg('p',false);
177 if ($next_action == 'select') {
178 // List all pages to select from.
179 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
181 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
184 => new _PageList_Column_remove('remove', _("Remove")))));
185 $pagelist->addPageList($pages);
188 if ($next_action == 'verify') {
189 $button_label = _("Yes");
190 $header->pushContent(HTML::strong(
191 _("Are you sure you want to permanently remove the selected files?")));
194 $button_label = _("Remove selected pages");
195 $header->pushContent(_("Permanently remove the selected files:"),HTML::br());
196 if ($args['min_age'] > 0) {
197 $header->pushContent(
198 fmt("Also pages which have been deleted at least %s days.",
202 $header->pushContent(_("List all pages."));
205 if ($args['max_age'] > 0) {
206 $header->pushContent(
208 fmt("(Pages which have been deleted at least %s days are already checked.)",
214 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
215 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
217 // TODO: quick select by regex javascript?
218 return HTML::form(array('action' => $request->getPostURL(),
222 $pagelist->getContent(),
223 HiddenInputs($request->getArgs(),
225 array('admin_remove')),
226 HiddenInputs(array('admin_remove[action]' => $next_action,
227 'require_authority_for_post' => WIKIAUTH_ADMIN)));
231 class _PageList_Column_remove extends _PageList_Column {
232 function _getValue ($page_handle, &$revision_handle) {
233 return Button(array('action' => 'remove'), _("Remove"),
234 $page_handle->getName());
242 // c-hanging-comment-ender-p: nil
243 // indent-tabs-mode: nil