2 rcs_id('$Id: WikiAdminRemove.php,v 1.28 2004-11-01 10:43:59 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');
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: $]/", '',
49 "\$Revision: 1.28 $");
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_deleted',$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;
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']);
181 $pagelist = new PageList_Selectable($args['info'], $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(),
221 $pagelist->getContent(),
222 HiddenInputs($request->getArgs(),
224 array('admin_remove')),
225 HiddenInputs(array('admin_remove[action]' => $next_action,
226 '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());
239 // $Log: not supported by cvs2svn $
240 // Revision 1.27 2004/06/16 10:38:59 rurban
241 // Disallow refernces in calls if the declaration is a reference
242 // ("allow_call_time_pass_reference clean").
243 // PhpWiki is now allow_call_time_pass_reference = Off clean,
244 // but several external libraries may not.
245 // In detail these libs look to be affected (not tested):
249 // Revision 1.26 2004/06/14 11:31:39 rurban
250 // renamed global $Theme to $WikiTheme (gforge nameclash)
251 // inherit PageList default options from PageList
252 // default sortby=pagename
253 // use options in PageList_Selectable (limit, sortby, ...)
254 // added action revert, with button at action=diff
255 // added option regex to WikiAdminSearchReplace
257 // Revision 1.25 2004/06/13 15:33:20 rurban
258 // new support for arguments owner, author, creator in most relevant
259 // PageList plugins. in WikiAdmin* via preSelectS()
261 // Revision 1.24 2004/06/08 10:05:11 rurban
262 // simplified admin action shortcuts
264 // Revision 1.23 2004/06/03 22:24:48 rurban
265 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
267 // Revision 1.22 2004/05/16 22:07:35 rurban
268 // check more config-default and predefined constants
269 // various PagePerm fixes:
270 // fix default PagePerms, esp. edit and view for Bogo and Password users
271 // implemented Creator and Owner
272 // BOGOUSERS renamed to BOGOUSER
273 // fixed syntax errors in signin.tmpl
275 // Revision 1.21 2004/05/04 16:34:22 rurban
276 // prvent hidden p overwrite checked p
278 // Revision 1.20 2004/05/03 11:02:30 rurban
279 // fix passing args from WikiAdminSelect to WikiAdminRemove
281 // Revision 1.19 2004/04/12 09:12:23 rurban
284 // Revision 1.18 2004/04/07 23:13:19 rurban
285 // fixed pear/File_Passwd for Windows
286 // fixed FilePassUser sessions (filehandle revive) and password update
288 // Revision 1.17 2004/03/17 20:23:44 rurban
289 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
291 // Revision 1.16 2004/03/12 13:31:43 rurban
292 // enforce PagePermissions, errormsg if not Admin
294 // Revision 1.15 2004/03/01 13:48:46 rurban
296 // p[] consistency fix
298 // Revision 1.14 2004/02/22 23:20:33 rurban
299 // fixed DumpHtmlToDir,
300 // enhanced sortby handling in PageList
301 // new button_heading th style (enabled),
302 // added sortby and limit support to the db backends and plugins
303 // for paging support (<<prev, next>> links on long lists)
305 // Revision 1.13 2004/02/17 12:11:36 rurban
306 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
308 // Revision 1.12 2004/02/15 21:34:37 rurban
309 // PageList enhanced and improved.
310 // fixed new WikiAdmin... plugins
311 // editpage, Theme with exp. htmlarea framework
312 // (htmlarea yet committed, this is really questionable)
313 // WikiUser... code with better session handling for prefs
314 // enhanced UserPreferences (again)
315 // RecentChanges for show_deleted: how should pages be deleted then?
317 // Revision 1.11 2004/02/11 20:00:16 rurban
318 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
320 // Revision 1.9 2003/02/26 22:27:22 dairiki
321 // Fix and refactor FrameInclude plugin (more or less).
323 // (This should now generate valid HTML. Woohoo!)
325 // The output when using the Sidebar theme is ugly enough that it should
326 // be considered broken. (But the Sidebar theme appears pretty broken in
327 // general right now.)
329 // (Personal comment (not to be taken personally): I must say that I
330 // remain unconvinced of the usefulness of this plugin.)
332 // Revision 1.8 2003/02/17 17:23:59 dairiki
333 // Disable plugin unless action='browse'.
335 // Add a header to the output, and adjust the HTML formatting a bit.
337 // Revision 1.7 2003/02/17 06:06:33 dairiki
338 // Refactor & code cleanup.
340 // Added two new plugin arguments:
342 // min_age - only display pages which have been "deleted" for at
343 // least this many days. (Use min_age=none to get all
344 // pages, even non-deleted ones listed.)
346 // max_age - automatically check the checkboxes of pages which
347 // have been "deleted" this many days or more.
349 // ("Deleted" means the current version of the page is empty.
350 // For the most part, PhpWiki treats these "deleted" pages as
351 // if they didn't exist --- but, of course, the PageHistory is
352 // still available, allowing old versions of the page to be restored.)
354 // Revision 1.6 2003/02/16 19:47:17 dairiki
355 // Update WikiDB timestamp when editing or deleting pages.
357 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
359 // Reformatting & tabs to spaces;
360 // Added copyleft, getVersion, getDescription, rcs_id.
367 // c-hanging-comment-ender-p: nil
368 // indent-tabs-mode: nil