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
33 function getDescription()
35 return _("Permanently purge all selected pages.");
38 /* getDefaultArguments() is inherited from WikiAdminSelect class */
40 function collectPages(&$list, &$dbi, $sortby, $limit = 0)
43 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
44 while ($pagehandle = $allPages->next()) {
45 $pagename = $pagehandle->getName();
46 $current = $pagehandle->getCurrentRevision();
47 if ($current->getVersion() < 1) {
48 continue; // No versions in database
50 if (empty($list[$pagename])) {
51 $list[$pagename] = false;
57 function purgePages(&$request, $pages)
59 $result = HTML::div();
61 $dbi = $request->getDbh();
63 foreach ($pages as $name) {
64 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
65 if (mayAccessPage('purge', $name)) {
66 $dbi->purgePage($name);
67 $ul->pushContent(HTML::li(fmt("Purged page ā%sā successfully.", $name)));
70 $ul->pushContent(HTML::li(fmt("Didn't purge page ā%sā. Access denied.", $name)));
75 $result->setAttr('class', 'feedback');
77 $result->pushContent(HTML::p(_("One page has been permanently purged:")));
79 $result->pushContent(HTML::p(fmt("%d pages have been permanently purged:", $count)));
81 $result->pushContent($ul);
84 $result->setAttr('class', 'error');
85 $result->pushContent(HTML::p(_("No pages purged.")));
90 function run($dbi, $argstr, &$request, $basepage)
92 if ($request->getArg('action') != 'browse') {
93 if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Purge")) {
94 return $this->disabled(_("Plugin not run: not in browse mode"));
98 $args = $this->getArgs($argstr, $request);
99 $this->_args =& $args;
100 $this->preSelectS($args, $request);
102 $p = $request->getArg('p');
103 if (!$p) $p = $this->_list;
104 $post_args = $request->getArg('admin_purge');
106 $next_action = 'select';
108 if ($p && $request->isPost() &&
109 !empty($post_args['purge']) && empty($post_args['cancel'])
112 // check individual PagePermissions
113 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
114 $request->_notAuthorized(WIKIAUTH_ADMIN);
115 $this->disabled("! user->isAdmin");
117 if ($post_args['action'] == 'verify') {
119 return $this->purgePages($request, array_keys($p));
122 if ($post_args['action'] == 'select') {
123 $next_action = 'verify';
124 foreach ($p as $name => $c) {
125 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
129 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
130 $next_action = 'verify';
131 foreach ($p as $name => $c) {
132 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
135 $request->setArg('p', false);
137 if ($next_action == 'select') {
138 // List all pages to select from.
139 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
141 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
142 $pagelist->addPageList($pages);
144 $header = HTML::fieldset();
145 if ($next_action == 'verify') {
146 $button_label = _("Yes");
147 $header->pushContent(HTML::legend(_("Confirm purge")));
148 $header->pushContent(HTML::p(HTML::strong(
149 _("Are you sure you want to permanently purge the following files?"))));
151 $button_label = _("Permanently purge selected pages");
152 $header->pushContent(HTML::legend(_("Select the files to purge")));
155 $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'),
156 Button('submit:admin_purge[cancel]', _("Cancel"), 'button'));
157 $header->pushContent($buttons);
159 // TODO: quick select by regex javascript?
160 return HTML::form(array('action' => $request->getPostURL(),
163 $pagelist->getContent(),
164 HiddenInputs($request->getArgs(),
166 array('admin_purge')),
167 HiddenInputs(array('admin_purge[action]' => $next_action,
168 'require_authority_for_post' => WIKIAUTH_ADMIN)));
176 // c-hanging-comment-ender-p: nil
177 // indent-tabs-mode: nil