2 rcs_id('$Id: WikiAdminRemove.php,v 1.8 2003-02-17 17:23:59 dairiki Exp $');
4 Copyright 2002 $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 * Displays a url in a seperate frame inside our body.
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');
36 class WikiPlugin_WikiAdminRemove
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 * Show only pages which have been 'deleted' this
56 * long (in days). (negative or non-numeric
57 * means show all pages, even non-deleted ones.)
59 * FIXME: could use a better name.
64 * Automatically check the checkboxes for files
65 * which have been 'deleted' this long (in days).
67 * FIXME: could use a better name.
71 /* Pages to exclude */
74 /* Columns to include in listing */
82 function collectPages(&$list, &$dbi) {
83 extract($this->_args);
87 $allPages = $dbi->getAllPages('include_deleted');
88 while ($pagehandle = $allPages->next()) {
89 $pagename = $pagehandle->getName();
90 $current = $pagehandle->getCurrentRevision();
91 if ($current->getVersion() < 1)
92 continue; // No versions in database
94 $empty = $current->hasDefaultContents();
96 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
97 $checked = $age >= $max_age;
104 if ($age > $min_age) {
105 if (empty($list[$pagename]))
106 $list[$pagename] = $checked;
111 function removePages(&$request, $pages) {
113 $dbi = $request->getDbh();
114 foreach ($pages as $name) {
115 $dbi->deletePage($name);
116 $ul->pushContent(HTML::li(fmt("Removed page '%s' succesfully.", $name)));
120 HTML::p(_('All selected pages have been permanently removed.')));
123 function run($dbi, $argstr, $request) {
124 if ($request->getArg('action') != 'browse')
125 return $this->disabled("(action != 'browse')");
127 $args = $this->getArgs($argstr, $request);
128 if (!is_numeric($args['min_age']))
129 $args['min_age'] = -1;
130 $this->_args = $args;
132 if (!empty($args['exclude']))
133 $exclude = explodePageList($args['exclude']);
138 $p = $request->getArg('p');
139 $post_args = $request->getArg('admin_remove');
141 $next_action = 'select';
144 if ($p && $request->isPost() && $request->_user->isAdmin()
145 && !empty($post_args['remove']) && empty($post_args['cancel'])) {
146 // FIXME: error message if not admin.
147 if ($post_args['action'] == 'verify') {
149 return $this->removePages($request, $p);
152 if ($post_args['action'] == 'select') {
153 $next_action = 'verify';
154 foreach ($p as $name) {
159 if ($next_action == 'select') {
160 // List all pages to select from.
161 $list = $this->collectPages($pages, $dbi);
167 $info .= "," . $args['info'];
168 $pagelist = new PageList_Selectable($info, $exclude);
169 $pagelist->addPageList($pages);
172 if ($next_action == 'verify') {
173 $button_label = _("Permanently remove selected pages");
174 $header->pushContent(HTML::strong(
175 _("Are you sure you want to permanently remove the selected files?")));
178 $button_label = _("Remove selected pages");
179 if ($args['min_age'] >= 0) {
180 $header->pushContent(
181 fmt("Listing pages which have been deleted at least %s days.",
185 $header->pushContent(_("Listing all pages."));
188 if ($args['max_age'] >= 0) {
189 $header->pushContent(
191 fmt("(Automatically checking pages which have been deleted at least %s days.)",
197 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
198 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
200 return HTML::form(array('action' => $request->getPostURL(),
205 $pagelist->getContent(),
207 HiddenInputs($request->getArgs(),
209 array('admin_remove')),
211 HiddenInputs(array('admin_remove[action]' => $next_action,
212 'require_authority_for_post' => WIKIAUTH_ADMIN)),
217 // $Log: not supported by cvs2svn $
218 // Revision 1.7 2003/02/17 06:06:33 dairiki
219 // Refactor & code cleanup.
221 // Added two new plugin arguments:
223 // min_age - only display pages which have been "deleted" for at
224 // least this many days. (Use min_age=none to get all
225 // pages, even non-deleted ones listed.)
227 // max_age - automatically check the checkboxes of pages which
228 // have been "deleted" this many days or more.
230 // ("Deleted" means the current version of the page is empty.
231 // For the most part, PhpWiki treats these "deleted" pages as
232 // if they didn't exist --- but, of course, the PageHistory is
233 // still available, allowing old versions of the page to be restored.)
235 // Revision 1.6 2003/02/16 19:47:17 dairiki
236 // Update WikiDB timestamp when editing or deleting pages.
238 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
240 // Reformatting & tabs to spaces;
241 // Added copyleft, getVersion, getDescription, rcs_id.
248 // c-hanging-comment-ender-p: nil
249 // indent-tabs-mode: nil