4 Copyright 2002,2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Usage: <?plugin WikiAdminRemove?>
25 * Author: Reini Urban <rurban@x-ray.at>
28 * Currently we must be Admin.
29 * Future versions will support PagePermissions.
30 * requires PHP 4.2 so far.
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
40 return _("WikiAdminRemove");
43 function getDescription() {
44 return _("Permanently remove all selected pages.");
47 function getVersion() {
48 return preg_replace("/[Revision: $]/", '',
52 function getDefaultArguments() {
55 PageList::supportedArgs(),
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) {
111 $dbi = $request->getDbh(); $count = 0;
112 foreach ($pages as $name) {
113 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
114 if (mayAccessPage('remove',$name)) {
115 $dbi->deletePage($name);
116 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
119 $ul->pushContent(HTML::li(fmt("Didn't removed page '%s'. Access denied.", $name)));
122 if ($count) $dbi->touch();
124 HTML::p(fmt("%d pages have been permanently removed.",$count)));
127 function run($dbi, $argstr, &$request, $basepage) {
128 if ($request->getArg('action') != 'browse')
129 if ($request->getArg('action') != _("PhpWikiAdministration/Remove"))
130 return $this->disabled("(action != 'browse')");
132 $args = $this->getArgs($argstr, $request);
133 if (!is_numeric($args['min_age']))
134 $args['min_age'] = -1;
135 $this->_args =& $args;
136 /*if (!empty($args['exclude']))
137 $exclude = explodePageList($args['exclude']);
140 $this->preSelectS($args, $request);
142 $p = $request->getArg('p');
143 if (!$p) $p = $this->_list;
144 $post_args = $request->getArg('admin_remove');
146 $next_action = 'select';
148 if ($p && $request->isPost() &&
149 !empty($post_args['remove']) && empty($post_args['cancel'])) {
151 // check individual PagePermissions
152 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
153 $request->_notAuthorized(WIKIAUTH_ADMIN);
154 $this->disabled("! user->isAdmin");
156 if ($post_args['action'] == 'verify') {
158 return $this->removePages($request, array_keys($p));
161 if ($post_args['action'] == 'select') {
162 $next_action = 'verify';
163 foreach ($p as $name => $c) {
164 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
168 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
169 $next_action = 'verify';
170 foreach ($p as $name => $c) {
171 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
174 $request->setArg('p',false);
176 if ($next_action == 'select') {
177 // List all pages to select from.
178 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
180 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
183 => new _PageList_Column_remove('remove', _("Remove")))));
184 $pagelist->addPageList($pages);
187 if ($next_action == 'verify') {
188 $button_label = _("Yes");
189 $header->pushContent(HTML::strong(
190 _("Are you sure you want to permanently remove the selected files?")));
193 $button_label = _("Remove selected pages");
194 $header->pushContent(_("Permanently remove the selected files:"),HTML::br());
195 if ($args['min_age'] > 0) {
196 $header->pushContent(
197 fmt("Also pages which have been deleted at least %s days.",
201 $header->pushContent(_("List all pages."));
204 if ($args['max_age'] > 0) {
205 $header->pushContent(
207 fmt("(Pages which have been deleted at least %s days are already checked.)",
213 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
214 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
216 // TODO: quick select by regex javascript?
217 return HTML::form(array('action' => $request->getPostURL(),
220 $pagelist->getContent(),
221 HiddenInputs($request->getArgs(),
223 array('admin_remove')),
224 HiddenInputs(array('admin_remove[action]' => $next_action,
225 'require_authority_for_post' => WIKIAUTH_ADMIN)),
230 class _PageList_Column_remove extends _PageList_Column {
231 function _getValue ($page_handle, &$revision_handle) {
232 return Button(array('action' => 'remove'), _("Remove"),
233 $page_handle->getName());
241 // c-hanging-comment-ender-p: nil
242 // indent-tabs-mode: nil