2 rcs_id('$Id: WikiAdminRemove.php,v 1.22 2004-05-16 22:07:35 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.22 $");
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',
82 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
83 extract($this->_args);
87 $allPages = $dbi->getAllPages('include_deleted',$sortby,$limit);
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;
112 function removePages(&$request, $pages) {
114 $dbi = $request->getDbh(); $count = 0;
115 foreach ($pages as $name) {
116 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
117 if (mayAccessPage('remove',$name)) {
118 $dbi->deletePage($name);
119 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
122 $ul->pushContent(HTML::li(fmt("Didn't removed page '%s'. Access denied.", $name)));
125 if ($count) $dbi->touch();
127 HTML::p(fmt("%d pages have been permanently removed."),$count));
130 function run($dbi, $argstr, &$request, $basepage) {
131 if ($request->getArg('action') != 'browse')
132 return $this->disabled("(action != 'browse')");
134 $args = $this->getArgs($argstr, $request);
135 if (!is_numeric($args['min_age']))
136 $args['min_age'] = -1;
137 $this->_args =& $args;
139 if (!empty($args['exclude']))
140 $exclude = explodePageList($args['exclude']);
145 $p = $request->getArg('p');
146 $post_args = $request->getArg('admin_remove');
148 $next_action = 'select';
151 if ($p && $request->isPost() &&
152 !empty($post_args['remove']) && empty($post_args['cancel'])) {
154 // FIXME: check individual PagePermissions
156 if (!$request->_user->isAdmin()) {
157 $request->_notAuthorized(WIKIAUTH_ADMIN);
158 $this->disabled("! user->isAdmin");
161 if ($post_args['action'] == 'verify') {
163 return $this->removePages($request, array_keys($p));
166 if ($post_args['action'] == 'select') {
167 $next_action = 'verify';
168 foreach ($p as $name => $c) {
169 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
173 } elseif (is_array($p) && !$request->isPost()) { // from WikiAdminSelect
174 $next_action = 'verify';
175 foreach ($p as $name => $c) {
176 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
179 $request->setArg('p',false);
181 if ($next_action == 'select') {
182 // List all pages to select from.
183 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
185 $pagelist = new PageList_Selectable($args['info'], $exclude,
188 => new _PageList_Column_remove('remove', _("Remove")))));
189 $pagelist->addPageList($pages);
192 if ($next_action == 'verify') {
193 $button_label = _("Yes");
194 $header->pushContent(HTML::strong(
195 _("Are you sure you want to permanently remove the selected files?")));
198 $button_label = _("Remove selected pages");
199 $header->pushContent(_("Permanently remove the selected files:"),HTML::br());
200 if ($args['min_age'] > 0) {
201 $header->pushContent(
202 fmt("Also pages which have been deleted at least %s days.",
206 $header->pushContent(_("List all pages."));
209 if ($args['max_age'] > 0) {
210 $header->pushContent(
212 fmt("(Pages which have been deleted at least %s days are already checked.)",
218 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
219 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
221 return HTML::form(array('action' => $request->getPostURL(),
226 $pagelist->getContent(),
228 HiddenInputs($request->getArgs(),
230 array('admin_remove')),
232 HiddenInputs(array('admin_remove[action]' => $next_action,
233 'require_authority_for_post' => WIKIAUTH_ADMIN)),
238 class _PageList_Column_remove extends _PageList_Column {
239 function _getValue ($page_handle, &$revision_handle) {
240 return Button(array('action' => 'remove'), _("Remove"),
241 $page_handle->getName());
246 // $Log: not supported by cvs2svn $
247 // Revision 1.21 2004/05/04 16:34:22 rurban
248 // prvent hidden p overwrite checked p
250 // Revision 1.20 2004/05/03 11:02:30 rurban
251 // fix passing args from WikiAdminSelect to WikiAdminRemove
253 // Revision 1.19 2004/04/12 09:12:23 rurban
256 // Revision 1.18 2004/04/07 23:13:19 rurban
257 // fixed pear/File_Passwd for Windows
258 // fixed FilePassUser sessions (filehandle revive) and password update
260 // Revision 1.17 2004/03/17 20:23:44 rurban
261 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
263 // Revision 1.16 2004/03/12 13:31:43 rurban
264 // enforce PagePermissions, errormsg if not Admin
266 // Revision 1.15 2004/03/01 13:48:46 rurban
268 // p[] consistency fix
270 // Revision 1.14 2004/02/22 23:20:33 rurban
271 // fixed DumpHtmlToDir,
272 // enhanced sortby handling in PageList
273 // new button_heading th style (enabled),
274 // added sortby and limit support to the db backends and plugins
275 // for paging support (<<prev, next>> links on long lists)
277 // Revision 1.13 2004/02/17 12:11:36 rurban
278 // 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, ...)
280 // Revision 1.12 2004/02/15 21:34:37 rurban
281 // PageList enhanced and improved.
282 // fixed new WikiAdmin... plugins
283 // editpage, Theme with exp. htmlarea framework
284 // (htmlarea yet committed, this is really questionable)
285 // WikiUser... code with better session handling for prefs
286 // enhanced UserPreferences (again)
287 // RecentChanges for show_deleted: how should pages be deleted then?
289 // Revision 1.11 2004/02/11 20:00:16 rurban
290 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
292 // Revision 1.9 2003/02/26 22:27:22 dairiki
293 // Fix and refactor FrameInclude plugin (more or less).
295 // (This should now generate valid HTML. Woohoo!)
297 // The output when using the Sidebar theme is ugly enough that it should
298 // be considered broken. (But the Sidebar theme appears pretty broken in
299 // general right now.)
301 // (Personal comment (not to be taken personally): I must say that I
302 // remain unconvinced of the usefulness of this plugin.)
304 // Revision 1.8 2003/02/17 17:23:59 dairiki
305 // Disable plugin unless action='browse'.
307 // Add a header to the output, and adjust the HTML formatting a bit.
309 // Revision 1.7 2003/02/17 06:06:33 dairiki
310 // Refactor & code cleanup.
312 // Added two new plugin arguments:
314 // min_age - only display pages which have been "deleted" for at
315 // least this many days. (Use min_age=none to get all
316 // pages, even non-deleted ones listed.)
318 // max_age - automatically check the checkboxes of pages which
319 // have been "deleted" this many days or more.
321 // ("Deleted" means the current version of the page is empty.
322 // For the most part, PhpWiki treats these "deleted" pages as
323 // if they didn't exist --- but, of course, the PageHistory is
324 // still available, allowing old versions of the page to be restored.)
326 // Revision 1.6 2003/02/16 19:47:17 dairiki
327 // Update WikiDB timestamp when editing or deleting pages.
329 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
331 // Reformatting & tabs to spaces;
332 // Added copyleft, getVersion, getDescription, rcs_id.
339 // c-hanging-comment-ender-p: nil
340 // indent-tabs-mode: nil