3 * Copyright © 2002,2004 $ThePhpWikiProgrammingTeam
4 * Copyright © 2009 Marc-Etienne Vargenau, Alcatel-Lucent
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 along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * SPDX-License-Identifier: GPL-2.0-or-later
27 * Usage: <<WikiAdminPurge>>
30 require_once 'lib/PageList.php';
31 require_once 'lib/plugin/WikiAdminSelect.php';
33 class WikiPlugin_WikiAdminPurge
34 extends WikiPlugin_WikiAdminSelect
36 function getDescription()
38 return _("Permanently purge selected pages").".";
41 /* getDefaultArguments() is inherited from WikiAdminSelect class */
43 protected function collectPages(&$list, &$dbi, $sortby, $limit = 0, $exclude = '')
46 $allPages = $dbi->getAllPages('include_empty', $sortby, $limit);
47 while ($pagehandle = $allPages->next()) {
48 $pagename = $pagehandle->getName();
49 $current = $pagehandle->getCurrentRevision();
50 if ($current->getVersion() < 1) {
51 continue; // No versions in database
53 if (empty($list[$pagename])) {
54 $list[$pagename] = false;
60 private function purgePages(&$request, $pages)
62 $result = HTML::div();
64 $dbi = $request->getDbh();
66 foreach ($pages as $name) {
67 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
68 if (mayAccessPage('purge', $name)) {
69 $dbi->purgePage($name);
70 $ul->pushContent(HTML::li(fmt("Purged page “%s” successfully.", $name)));
73 $ul->pushContent(HTML::li(fmt("Didn't purge page “%s”. Access denied.", $name)));
78 $result->setAttr('class', 'feedback');
80 $result->pushContent(HTML::p(_("One page has been permanently purged:")));
82 $result->pushContent(HTML::p(fmt("%d pages have been permanently purged:", $count)));
85 $result->setAttr('class', 'error');
86 $result->pushContent(HTML::p(_("No pages purged.")));
88 $result->pushContent($ul);
94 * @param string $argstr
95 * @param WikiRequest $request
96 * @param string $basepage
99 function run($dbi, $argstr, &$request, $basepage)
101 if ($request->getArg('action') != 'browse') {
102 if ($request->getArg('action') != __("PhpWikiAdministration")."/".__("Purge")) {
103 return $this->disabled(_("Plugin not run: not in browse mode"));
107 $args = $this->getArgs($argstr, $request);
108 $this->_args = $args;
109 $this->preSelectS($args, $request);
111 $p = $request->getArg('p');
112 if (!$p) $p = $this->_list;
113 $post_args = $request->getArg('admin_purge');
115 $next_action = 'select';
117 if ($p && $request->isPost() &&
118 !empty($post_args['purge']) && empty($post_args['cancel'])
120 // without individual PagePermissions:
121 if (!ENABLE_PAGEPERM and !$request->_user->isAdmin()) {
122 $request->_notAuthorized(WIKIAUTH_ADMIN);
123 $this->disabled("! user->isAdmin");
125 if ($post_args['action'] == 'verify') {
127 return $this->purgePages($request, array_keys($p));
129 if ($post_args['action'] == 'select') {
130 $next_action = 'verify';
131 foreach ($p as $name => $c) {
132 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
136 } elseif ($p && is_array($p) && !$request->isPost()) { // from WikiAdminSelect
137 $next_action = 'verify';
138 foreach ($p as $name => $c) {
139 $name = str_replace(array('%5B', '%5D'), array('[', ']'), $name);
142 $request->setArg('p', false);
144 if ($next_action == 'select') {
145 // List all pages to select from.
146 $pages = $this->collectPages($pages, $dbi, $args['sortby'], $args['limit'], $args['exclude']);
149 $header = HTML::fieldset();
150 if ($next_action == 'verify') {
151 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
152 $pagelist->addPageList($pages);
153 $button_label = _("Yes");
154 $header->pushContent(HTML::legend(_("Confirm purge")));
155 $header->pushContent(HTML::p(HTML::strong(
156 _("Are you sure you want to permanently purge the following pages?"))));
158 $pagelist = new PageList_Selectable($args['info'], $args['exclude'], array());
159 $pagelist->addPageList($pages);
160 $button_label = _("Permanently purge selected pages");
161 $header->pushContent(HTML::legend(_("Select the pages to purge")));
164 $buttons = HTML::p(Button('submit:admin_purge[purge]', $button_label, 'wikiadmin'),
165 HTML::raw(" "),
166 Button('submit:admin_purge[cancel]', _("Cancel"), 'button'));
167 $header->pushContent($buttons);
169 return HTML::form(array('action' => $request->getPostURL(),
172 $pagelist->getContent(),
173 HiddenInputs($request->getArgs(),
175 array('admin_purge')),
176 HiddenInputs(array('admin_purge[action]' => $next_action,
177 'require_authority_for_post' => WIKIAUTH_ADMIN)));