2 rcs_id('$Id: WikiAdminRemove.php,v 1.11 2004-02-11 20:00:16 rurban Exp $');
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');
35 class WikiPlugin_WikiAdminRemove
39 return _("WikiAdminRemove");
42 function getDescription() {
43 return _("Permanently remove all selected pages.");
46 function getVersion() {
47 return preg_replace("/[Revision: $]/", '',
48 "\$Revision: 1.11 $");
51 function getDefaultArguments() {
54 * Show only pages which have been 'deleted' this
55 * long (in days). (negative or non-numeric
56 * means show all pages, even non-deleted ones.)
58 * FIXME: could use a better name.
63 * Automatically check the checkboxes for files
64 * which have been 'deleted' this long (in days).
66 * FIXME: could use a better name.
70 /* Pages or regex to exclude */
73 /* Columns to include in listing */
77 'sortby' => 'pagename'
81 function collectPages(&$list, &$dbi, $sortby) {
82 extract($this->_args);
86 $allPages = $dbi->getAllPages('include_deleted',$sortby);
87 while ($pagehandle = $allPages->next()) {
88 $pagename = $pagehandle->getName();
89 $current = $pagehandle->getCurrentRevision();
90 if ($current->getVersion() < 1)
91 continue; // No versions in database
93 $empty = $current->hasDefaultContents();
95 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
96 $checked = $age >= $max_age;
103 if ($age > $min_age) {
104 if (empty($list[$pagename]))
105 $list[$pagename] = $checked;
110 function removePages(&$request, $pages) {
112 $dbi = $request->getDbh();
113 foreach ($pages as $name) {
114 $dbi->deletePage($name);
115 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
119 HTML::p(_('All selected pages have been permanently removed.')));
122 function run($dbi, $argstr, $request) {
123 if ($request->getArg('action') != 'browse')
124 return $this->disabled("(action != 'browse')");
126 $args = $this->getArgs($argstr, $request);
127 if (!is_numeric($args['min_age']))
128 $args['min_age'] = -1;
129 $this->_args = $args;
131 if (!empty($args['exclude']))
132 $exclude = explodePageList($args['exclude']);
137 $p = $request->getArg('p');
138 $post_args = $request->getArg('admin_remove');
140 $next_action = 'select';
143 if ($p && $request->isPost() && $request->_user->isAdmin()
144 && !empty($post_args['remove']) && empty($post_args['cancel'])) {
145 // FIXME: error message if not admin.
146 if ($post_args['action'] == 'verify') {
148 return $this->removePages($request, $p);
151 if ($post_args['action'] == 'select') {
152 $next_action = 'verify';
153 foreach ($p as $name) {
158 if ($next_action == 'select') {
159 // List all pages to select from.
160 $list = $this->collectPages($pages, $dbi, $args['sortby']);
166 $info .= "," . $args['info'];
167 $pagelist = new PageList_Selectable($info, $exclude);
168 $pagelist->addPageList($pages);
171 if ($next_action == 'verify') {
172 $button_label = _("Yes");
173 $header->pushContent(HTML::strong(
174 _("Are you sure you want to permanently remove the selected files?")));
177 $button_label = _("Remove selected pages");
178 if ($args['min_age'] >= 0) {
179 $header->pushContent(
180 fmt("Listing pages which have been deleted at least %s days.",
184 $header->pushContent(_("Listing all pages."));
187 if ($args['max_age'] >= 0) {
188 $header->pushContent(
190 fmt("(Automatically checking pages which have been deleted at least %s days.)",
196 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
197 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
199 return HTML::form(array('action' => $request->getPostURL(),
204 $pagelist->getContent(),
206 HiddenInputs($request->getArgs(),
208 array('admin_remove')),
210 HiddenInputs(array('admin_remove[action]' => $next_action,
211 'require_authority_for_post' => WIKIAUTH_ADMIN)),
216 // $Log: not supported by cvs2svn $
217 // Revision 1.9 2003/02/26 22:27:22 dairiki
218 // Fix and refactor FrameInclude plugin (more or less).
220 // (This should now generate valid HTML. Woohoo!)
222 // The output when using the Sidebar theme is ugly enough that it should
223 // be considered broken. (But the Sidebar theme appears pretty broken in
224 // general right now.)
226 // (Personal comment (not to be taken personally): I must say that I
227 // remain unconvinced of the usefulness of this plugin.)
229 // Revision 1.8 2003/02/17 17:23:59 dairiki
230 // Disable plugin unless action='browse'.
232 // Add a header to the output, and adjust the HTML formatting a bit.
234 // Revision 1.7 2003/02/17 06:06:33 dairiki
235 // Refactor & code cleanup.
237 // Added two new plugin arguments:
239 // min_age - only display pages which have been "deleted" for at
240 // least this many days. (Use min_age=none to get all
241 // pages, even non-deleted ones listed.)
243 // max_age - automatically check the checkboxes of pages which
244 // have been "deleted" this many days or more.
246 // ("Deleted" means the current version of the page is empty.
247 // For the most part, PhpWiki treats these "deleted" pages as
248 // if they didn't exist --- but, of course, the PageHistory is
249 // still available, allowing old versions of the page to be restored.)
251 // Revision 1.6 2003/02/16 19:47:17 dairiki
252 // Update WikiDB timestamp when editing or deleting pages.
254 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
256 // Reformatting & tabs to spaces;
257 // Added copyleft, getVersion, getDescription, rcs_id.
264 // c-hanging-comment-ender-p: nil
265 // indent-tabs-mode: nil