2 rcs_id('$Id: WikiAdminRemove.php,v 1.18 2004-04-07 23:13:19 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.18 $");
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();
115 foreach ($pages as $name) {
116 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
117 $dbi->deletePage($name);
118 $ul->pushContent(HTML::li(fmt("Removed page '%s' successfully.", $name)));
122 HTML::p(_('All selected pages have been permanently removed.')));
125 function run($dbi, $argstr, &$request, $basepage) {
126 if ($request->getArg('action') != 'browse')
127 return $this->disabled("(action != 'browse')");
129 $args = $this->getArgs($argstr, $request);
130 if (!is_numeric($args['min_age']))
131 $args['min_age'] = -1;
132 $this->_args = $args;
134 if (!empty($args['exclude']))
135 $exclude = explodePageList($args['exclude']);
140 $p = $request->getArg('p');
141 $post_args = $request->getArg('admin_remove');
143 $next_action = 'select';
146 if ($p && $request->isPost() &&
147 !empty($post_args['remove']) && empty($post_args['cancel'])) {
149 // FIXME: check individual PagePermissions
150 if (!$request->_user->isAdmin()) {
151 $request->_notAuthorized(WIKIAUTH_ADMIN);
152 $this->disabled("! user->isAdmin");
154 if ($post_args['action'] == 'verify') {
156 return $this->removePages($request, array_keys($p));
159 if ($post_args['action'] == 'select') {
160 $next_action = 'verify';
161 foreach ($p as $name => $c) {
162 $name = str_replace(array('%5B','%5D'),array('[',']'),$name);
167 if ($next_action == 'select') {
168 // List all pages to select from.
169 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit']);
171 $pagelist = new PageList_Selectable($args['info'], $exclude,
174 => new _PageList_Column_remove('remove', _("Remove"))));
175 $pagelist->addPageList($pages);
178 if ($next_action == 'verify') {
179 $button_label = _("Yes");
180 $header->pushContent(HTML::strong(
181 _("Are you sure you want to permanently remove the selected files?")));
184 $button_label = _("Remove selected pages");
185 $header->pushContent(_("Permanently remove the selected files:"),HTML::br());
186 if ($args['min_age'] > 0) {
187 $header->pushContent(
188 fmt("Also pages which have been deleted at least %s days.",
192 $header->pushContent(_("List all pages."));
195 if ($args['max_age'] > 0) {
196 $header->pushContent(
198 fmt("(Pages which have been deleted at least %s days are already checked.)",
204 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
205 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
207 return HTML::form(array('action' => $request->getPostURL(),
212 $pagelist->getContent(),
214 HiddenInputs($request->getArgs(),
216 array('admin_remove')),
218 HiddenInputs(array('admin_remove[action]' => $next_action,
219 'require_authority_for_post' => WIKIAUTH_ADMIN)),
224 class _PageList_Column_remove extends _PageList_Column {
225 function _getValue ($page_handle, &$revision_handle) {
226 return Button(array('action' => 'remove'), _("Remove"),
227 $page_handle->getName());
232 // $Log: not supported by cvs2svn $
233 // Revision 1.17 2004/03/17 20:23:44 rurban
234 // fixed p[] pagehash passing from WikiAdminSelect, fixed problem removing pages with [] in the pagename
236 // Revision 1.16 2004/03/12 13:31:43 rurban
237 // enforce PagePermissions, errormsg if not Admin
239 // Revision 1.15 2004/03/01 13:48:46 rurban
241 // p[] consistency fix
243 // Revision 1.14 2004/02/22 23:20:33 rurban
244 // fixed DumpHtmlToDir,
245 // enhanced sortby handling in PageList
246 // new button_heading th style (enabled),
247 // added sortby and limit support to the db backends and plugins
248 // for paging support (<<prev, next>> links on long lists)
250 // Revision 1.13 2004/02/17 12:11:36 rurban
251 // 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, ...)
253 // Revision 1.12 2004/02/15 21:34:37 rurban
254 // PageList enhanced and improved.
255 // fixed new WikiAdmin... plugins
256 // editpage, Theme with exp. htmlarea framework
257 // (htmlarea yet committed, this is really questionable)
258 // WikiUser... code with better session handling for prefs
259 // enhanced UserPreferences (again)
260 // RecentChanges for show_deleted: how should pages be deleted then?
262 // Revision 1.11 2004/02/11 20:00:16 rurban
263 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
265 // Revision 1.9 2003/02/26 22:27:22 dairiki
266 // Fix and refactor FrameInclude plugin (more or less).
268 // (This should now generate valid HTML. Woohoo!)
270 // The output when using the Sidebar theme is ugly enough that it should
271 // be considered broken. (But the Sidebar theme appears pretty broken in
272 // general right now.)
274 // (Personal comment (not to be taken personally): I must say that I
275 // remain unconvinced of the usefulness of this plugin.)
277 // Revision 1.8 2003/02/17 17:23:59 dairiki
278 // Disable plugin unless action='browse'.
280 // Add a header to the output, and adjust the HTML formatting a bit.
282 // Revision 1.7 2003/02/17 06:06:33 dairiki
283 // Refactor & code cleanup.
285 // Added two new plugin arguments:
287 // min_age - only display pages which have been "deleted" for at
288 // least this many days. (Use min_age=none to get all
289 // pages, even non-deleted ones listed.)
291 // max_age - automatically check the checkboxes of pages which
292 // have been "deleted" this many days or more.
294 // ("Deleted" means the current version of the page is empty.
295 // For the most part, PhpWiki treats these "deleted" pages as
296 // if they didn't exist --- but, of course, the PageHistory is
297 // still available, allowing old versions of the page to be restored.)
299 // Revision 1.6 2003/02/16 19:47:17 dairiki
300 // Update WikiDB timestamp when editing or deleting pages.
302 // Revision 1.5 2003/01/18 22:14:28 carstenklapp
304 // Reformatting & tabs to spaces;
305 // Added copyleft, getVersion, getDescription, rcs_id.
312 // c-hanging-comment-ender-p: nil
313 // indent-tabs-mode: nil