2 rcs_id('$Id: WikiAdminRemove.php,v 1.27 2004-06-16 10:38: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.27 $");
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 return HTML::form(array('action' => $request->getPostURL(),
222 $pagelist->getContent(),
224 HiddenInputs($request->getArgs(),
226 array('admin_remove')),
228 HiddenInputs(array('admin_remove[action]' => $next_action,
229 'require_authority_for_post' => WIKIAUTH_ADMIN)),
234 class _PageList_Column_remove extends _PageList_Column {
235 function _getValue ($page_handle, &$revision_handle) {
236 return Button(array('action' => 'remove'), _("Remove"),
237 $page_handle->getName());
242 // $Log: not supported by cvs2svn $
243 // Revision 1.26 2004/06/14 11:31:39 rurban
244 // renamed global $Theme to $WikiTheme (gforge nameclash)
245 // inherit PageList default options from PageList
246 // default sortby=pagename
247 // use options in PageList_Selectable (limit, sortby, ...)
248 // added action revert, with button at action=diff
249 // added option regex to WikiAdminSearchReplace
251 // Revision 1.25 2004/06/13 15:33:20 rurban
252 // new support for arguments owner, author, creator in most relevant
253 // PageList plugins. in WikiAdmin* via preSelectS()
255 // Revision 1.24 2004/06/08 10:05:11 rurban
256 // simplified admin action shortcuts
258 // Revision 1.23 2004/06/03 22:24:48 rurban
259 // reenable admin check on !ENABLE_PAGEPERM, honor s=Wildcard arg, fix warning after Remove
261 // Revision 1.22 2004/05/16 22:07:35 rurban
262 // check more config-default and predefined constants
263 // various PagePerm fixes:
264 // fix default PagePerms, esp. edit and view for Bogo and Password users
265 // implemented Creator and Owner
266 // BOGOUSERS renamed to BOGOUSER
267 // fixed syntax errors in signin.tmpl
269 // Revision 1.21 2004/05/04 16:34:22 rurban
270 // prvent hidden p overwrite checked p
272 // Revision 1.20 2004/05/03 11:02:30 rurban
273 // fix passing args from WikiAdminSelect to WikiAdminRemove
275 // Revision 1.19 2004/04/12 09:12:23 rurban
278 // Revision 1.18 2004/04/07 23:13:19 rurban
279 // fixed pear/File_Passwd for Windows
280 // fixed FilePassUser sessions (filehandle revive) and password update
282 // Revision 1.17 2004/03/17 20:23:44 rurban
283 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
285 // Revision 1.16 2004/03/12 13:31:43 rurban
286 // enforce PagePermissions, errormsg if not Admin
288 // Revision 1.15 2004/03/01 13:48:46 rurban
290 // p[] consistency fix
292 // Revision 1.14 2004/02/22 23:20:33 rurban
293 // fixed DumpHtmlToDir,
294 // enhanced sortby handling in PageList
295 // new button_heading th style (enabled),
296 // added sortby and limit support to the db backends and plugins
297 // for paging support (<<prev, next>> links on long lists)
299 // Revision 1.13 2004/02/17 12:11:36 rurban
300 // 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, ...)
302 // Revision 1.12 2004/02/15 21:34:37 rurban
303 // PageList enhanced and improved.
304 // fixed new WikiAdmin... plugins
305 // editpage, Theme with exp. htmlarea framework
306 // (htmlarea yet committed, this is really questionable)
307 // WikiUser... code with better session handling for prefs
308 // enhanced UserPreferences (again)
309 // RecentChanges for show_deleted: how should pages be deleted then?
311 // Revision 1.11 2004/02/11 20:00:16 rurban
312 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
314 // Revision 1.9 2003/02/26 22:27:22 dairiki
315 // Fix and refactor FrameInclude plugin (more or less).
317 // (This should now generate valid HTML. Woohoo!)
319 // The output when using the Sidebar theme is ugly enough that it should
320 // be considered broken. (But the Sidebar theme appears pretty broken in
321 // general right now.)
323 // (Personal comment (not to be taken personally): I must say that I
324 // remain unconvinced of the usefulness of this plugin.)
326 // Revision 1.8 2003/02/17 17:23:59 dairiki
327 // Disable plugin unless action='browse'.
329 // Add a header to the output, and adjust the HTML formatting a bit.
331 // Revision 1.7 2003/02/17 06:06:33 dairiki
332 // Refactor & code cleanup.
334 // Added two new plugin arguments:
336 // min_age - only display pages which have been "deleted" for at
337 // least this many days. (Use min_age=none to get all
338 // pages, even non-deleted ones listed.)
340 // max_age - automatically check the checkboxes of pages which
341 // have been "deleted" this many days or more.
343 // ("Deleted" means the current version of the page is empty.
344 // For the most part, PhpWiki treats these "deleted" pages as
345 // if they didn't exist --- but, of course, the PageHistory is
346 // still available, allowing old versions of the page to be restored.)
348 // Revision 1.6 2003/02/16 19:47:17 dairiki
349 // Update WikiDB timestamp when editing or deleting pages.
351 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
353 // Reformatting & tabs to spaces;
354 // Added copyleft, getVersion, getDescription, rcs_id.
361 // c-hanging-comment-ender-p: nil
362 // indent-tabs-mode: nil