4 * Copyright 2002,2004 $ThePhpWikiProgrammingTeam
5 * Copyright 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: <<WikiAdminPurge>>
27 require_once 'lib/PageList.php';
28 require_once 'lib/plugin/WikiAdminSelect.php';
30 class WikiPlugin_WikiAdminPurge
31 extends WikiPlugin_WikiAdminSelect
35 return _("WikiAdminPurge");
38 function getDescription()
40 return _("Permanently purge all selected pages.");
43 /* getDefaultArguments() is inherited from WikiAdminSelect class */
45 function collectPages(&$list, &$dbi, $sortby, $limit = 0)
48 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
49 while ($pagehandle = $allPages->next()) {
50 $pagename = $pagehandle->getName();
51 $current = $pagehandle->getCurrentRevision();
52 if ($current->getVersion() < 1) {
53 continue; // No versions in database
55 if (empty($list[$pagename])) {
56 $list[$pagename] = false;
62 function purgePages(&$request, $pages)
64 $result = HTML::div();
66 $dbi = $request->getDbh();
68 foreach ($pages as $name) {
69 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
70 if (mayAccessPage('purge', $name)) {
71 $dbi->purgePage($name);
72 $ul->pushContent(HTML::li(fmt("Purged page ā%sā successfully.", $name)));
75 $ul->pushContent(HTML::li(fmt("Didn't purge page ā%sā. Access denied.", $name)));
80 $result->setAttr('class', 'feedback');
82 $result->pushContent(HTML::p(_("One page has been permanently purged:")));
84 $result->pushContent(HTML::p(fmt("%d pages have been permanently purged:", $count)));
86 $result->pushContent($ul);
89 $result->setAttr('class', 'error');
90 $result->pushContent(HTML::p(_("No pages purged.")));
95 function run($dbi, $argstr, &$request, $basepage)
97 if ($request->getArg('action') != 'browse') {
98 if ($request->getArg('action') != _("PhpWikiAdministration/Purge")) {
99 return $this->disabled(_("Plugin not run: not in browse mode"));
103 $args = $this->getArgs($argstr, $request);
104 $this->_args =& $args;
105 $this->preSelectS($args, $request);
107 $p = $request->getArg('p');
108 if (!$p) $p = $this->_list;
109 $post_args = $request->getArg('admin_purge');
111 $next_action = 'select';
113 if ($p && $request->isPost() &&
114 !empty($post_args['purge']) && empty($post_args['cancel'])
117 // check individual PagePermissions
118 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
119 $request->_notAuthorized(WIKIAUTH_ADMIN);
120 $this->disabled("! user->isAdmin");
122 if ($post_args['action'] == 'verify') {
124 return $this->purgePages($request, array_keys($p));
127 if ($post_args['action'] == 'select') {
128 $next_action = 'verify';
129 foreach ($p as $name => $c) {
130 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
134 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
135 $next_action = 'verify';
136 foreach ($p as $name => $c) {
137 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
140 $request->setArg('p', false);
142 if ($next_action == 'select') {
143 // List all pages to select from.
144 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
146 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
147 $pagelist->addPageList($pages);
149 $header = HTML::fieldset();
150 if ($next_action == 'verify') {
151 $button_label = _("Yes");
152 $header->pushContent(HTML::legend(_("Confirm purge")));
153 $header->pushContent(HTML::p(HTML::strong(
154 _("Are you sure you want to permanently purge the following files?"))));
156 $button_label = _("Permanently purge selected pages");
157 $header->pushContent(HTML::legend(_("Select the files to purge")));
160 $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'),
161 Button('submit:admin_purge[cancel]', _("Cancel"), 'button'));
162 $header->pushContent($buttons);
164 // TODO: quick select by regex javascript?
165 return HTML::form(array('action' => $request->getPostURL(),
168 $pagelist->getContent(),
169 HiddenInputs($request->getArgs(),
171 array('admin_purge')),
172 HiddenInputs(array('admin_purge[action]' => $next_action,
173 'require_authority_for_post' => WIKIAUTH_ADMIN)));
181 // c-hanging-comment-ender-p: nil
182 // indent-tabs-mode: nil