4 * Copyright 2002,2004 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Usage: <<WikiAdminRemove>>
26 * Author: Reini Urban <rurban@x-ray.at>
29 * Currently we must be Admin.
30 * Future versions will support PagePermissions.
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
39 function getDescription()
41 return _("Permanently remove all selected pages.");
44 function getDefaultArguments()
48 parent::getDefaultArguments(),
51 * Show only pages which have been 'deleted' this
52 * long (in days). (negative or non-numeric
53 * means show all pages, even non-deleted ones.)
55 * FIXME: could use a better name.
60 * Automatically check the checkboxes for files
61 * which have been 'deleted' this long (in days).
63 * FIXME: could use a better name.
66 /* Columns to include in listing */
71 protected function collectPages(&$list, &$dbi, $sortby, $limit = 0)
73 extract($this->_args);
77 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
78 while ($pagehandle = $allPages->next()) {
79 $pagename = $pagehandle->getName();
80 $current = $pagehandle->getCurrentRevision();
81 if ($current->getVersion() < 1)
82 continue; // No versions in database
84 $empty = $current->hasDefaultContents();
86 $age = ($now - $current->get('mtime')) / (24 * 3600.0);
87 $checked = $age >= $max_age;
93 if ($age >= $min_age) {
94 if (empty($list[$pagename]))
95 $list[$pagename] = $checked;
101 private function removePages(&$request, $pages)
103 $result = HTML::div();
105 $dbi = $request->getDbh();
107 foreach ($pages as $name) {
108 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
109 if (mayAccessPage('remove', $name)) {
110 $dbi->deletePage($name);
111 $ul->pushContent(HTML::li(fmt("Removed page ā%sā successfully.", $name)));
114 $ul->pushContent(HTML::li(fmt("Didn't remove page ā%sā. Access denied.", $name)));
119 $result->setAttr('class', 'feedback');
121 $result->pushContent(HTML::p(_("One page has been removed:")));
123 $result->pushContent(HTML::p(fmt("%d pages have been removed:", $count)));
126 $result->setAttr('class', 'error');
127 $result->pushContent(HTML::p(_("No pages removed.")));
129 $result->pushContent($ul);
135 * @param string $argstr
136 * @param WikiRequest $request
137 * @param string $basepage
140 function run($dbi, $argstr, &$request, $basepage)
142 if ($request->getArg('action') != 'browse') {
143 if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Remove")) {
144 return $this->disabled(_("Plugin not run: not in browse mode"));
148 $args = $this->getArgs($argstr, $request);
149 if (!is_numeric($args['min_age']))
150 $args['min_age'] = -1;
151 $this->_args =& $args;
152 /*if (!empty($args['exclude']))
153 $exclude = explodePageList($args['exclude']);
156 $this->preSelectS($args, $request);
158 $p = $request->getArg('p');
159 if (!$p) $p = $this->_list;
160 $post_args = $request->getArg('admin_remove');
162 $next_action = 'select';
164 if ($p && $request->isPost() &&
165 !empty($post_args['remove']) && empty($post_args['cancel'])
168 // check individual PagePermissions
169 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
170 $request->_notAuthorized(WIKIAUTH_ADMIN);
171 $this->disabled("! user->isAdmin");
173 if ($post_args['action'] == 'verify') {
175 return $this->removePages($request, array_keys($p));
178 if ($post_args['action'] == 'select') {
179 $next_action = 'verify';
180 foreach ($p as $name => $c) {
181 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
185 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
186 $next_action = 'verify';
187 foreach ($p as $name => $c) {
188 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
191 $request->setArg('p', false);
193 if ($next_action == 'select') {
194 // List all pages to select from.
195 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
198 $header = HTML::fieldset();
199 if ($next_action == 'verify') {
200 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
203 => new _PageList_Column_remove('remove', _("Remove")))));
204 $pagelist->addPageList($pages);
205 $button_label = _("Yes");
206 $header->pushContent(HTML::legend(_("Confirm removal")));
207 $header->pushContent(HTML::p(HTML::strong(
208 _("Are you sure you want to remove the selected files?"))));
210 $pagelist = new PageList_Selectable($args['info'], $args['exclude'],
213 => new _PageList_Column_remove('remove', _("Remove")))));
214 $pagelist->addPageList($pages);
215 $button_label = _("Remove selected pages");
216 $header->pushContent(HTML::legend(_("Select the files to remove")));
217 if ($args['min_age'] > 0) {
218 $header->pushContent(
219 fmt("Also pages which have been deleted at least %s days.",
223 if ($args['max_age'] > 0) {
224 $header->pushContent(
226 fmt("Pages which have been deleted at least %s days are already checked.",
231 $buttons = HTML::p(Button('submit:admin_remove[remove]', $button_label, 'wikiadmin'),
232 Button('submit:admin_remove[cancel]', _("Cancel"), 'button'));
233 $header->pushContent($buttons);
235 // TODO: quick select by regex javascript?
236 return HTML::form(array('action' => $request->getPostURL(),
239 $pagelist->getContent(),
240 HiddenInputs($request->getArgs(),
242 array('admin_remove')),
243 HiddenInputs(array('admin_remove[action]' => $next_action,
244 'require_authority_for_post' => WIKIAUTH_ADMIN)));
248 class _PageList_Column_remove extends _PageList_Column
250 function _getValue($page_handle, &$revision_handle)
252 return Button(array('action' => 'remove'), _("Remove"),
253 $page_handle->getName());
261 // c-hanging-comment-ender-p: nil
262 // indent-tabs-mode: nil