2 rcs_id('$Id: WikiAdminRemove.php,v 1.3 2002-08-24 13:18:56 rurban Exp $');
4 Copyright 2002 $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 * Displays a url in a seperate frame inside our body.
25 * Usage: <?plugin WikiAdminRemove?>
26 * Author: Reini Urban <rurban@x-ray.at>
29 * Currently we must be Admin.
30 * Future versions will support PagePermissions.
31 * requires PHP 4.2 so far.
33 // maybe display more attributes with this class...
34 //require_once('lib/PageList.php');
36 class WikiPlugin_WikiAdminRemove
40 return _("WikiAdminRemove");
43 function getDescription() {
44 return _("Permanently remove all selected pages.");
47 function getDefaultArguments() {
48 return array('only' => '',
53 function collectPages(&$list, &$dbi) {
54 $allPages = $dbi->getAllPages();
55 while ($pagehandle = $allPages->next()) {
56 $pagename = $pagehandle->getName();
57 if (empty($list[$pagename])) $list[$pagename] = 0;
61 function addTableHead(&$table) {
62 $row = HTML::tr(HTML::th(_("Select")),
64 $table->pushContent(HTML::thead($row));
67 function addTableBody(&$list, &$table) {
68 $tbody = HTML::tbody();
69 foreach ($list as $pagename => $selected) {
71 $row = HTML::tr(array('class' => 'oddrow'),
72 HTML::td(HTML::input(array('type' => 'checkbox',
73 'name' => "p[$pagename]",
76 HTML::td(WikiLink($pagename)));
78 $row = HTML::tr(array('class' => 'evenrow'),
79 HTML::td(HTML::input(array('type' => 'checkbox',
80 'name' => "p[$pagename]",
81 'value' => $pagename))),
82 HTML::td(WikiLink($pagename)));
84 $tbody->pushContent($row);
86 $table->pushContent($tbody);
89 function formatTable(&$list, &$dbi) {
90 $table = HTML::table(array('cellpadding' => 2,
93 'class' => 'pagelist'));
94 $table->pushContent(HTML::caption(array('align'=>'top'),
95 _("Permanently remove all selected pages.")));
96 // $this->addTableHead($table);
97 $this->addTableBody($list, $table);
101 function run($dbi, $argstr, $request) {
102 $args = $this->getArgs($argstr, $request);
103 if (!empty($args['only']))
104 $this->only = explode(',',$args['only']);
105 if (!empty($args['exclude']))
106 $this->only = explode(',',$args['exclude']);
107 $this->debug = $args['debug'];
108 $this->_list = array();
109 // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
110 $pagename = $request->getArg('pagename');
111 // GetUrlToSelf() with all given params
112 $uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
113 $form = HTML::form(array('action' => $uri, 'method' => 'POST'));
114 $p = $request->getArgs('p'); // $GLOBALS['HTTP_POST_VARS']['p']
115 if ($request->isPost() and $request->_user->isAdmin() and
116 $request->getArg('verify')) {
117 // List all to be deleted pages again.
118 foreach ($p as $page => $name) {
119 $this->_list[$name] = 1;
121 } elseif ($request->isPost() and $request->_user->isAdmin() and
122 $request->getArg('remove')) {
125 foreach ($p as $page => $name) {
126 $dbi = $request->getDbh();
127 $dbi->deletePage($name);
128 $ul->pushContent(HTML::li(fmt("Removed page '%s' succesfully.", $name)));
131 // List all pages to select from.
132 $this->collectPages($this->_list, &$dbi);
134 $table = $this->formatTable($this->_list, &$dbi, &$request);
135 $form->pushContent($table);
136 $form->pushContent(HiddenInputs($GLOBALS['HTTP_GET_VARS'])); // debugging params, ...
137 // if (! USE_PATH_INFO ) $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'pagename', 'value' => $pagename)));
138 if (! $request->getArg('verify')) {
139 $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify')));
140 $form->pushContent(Button('submit:verify', _("Remove selected pages"), 'wikiadmin'),
141 Button('submit:cancel', _("Cancel"), 'button'));
143 $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'remove')));
144 $form->pushContent(Button('submit:remove', _("Remove selected pages"), 'wikiadmin'),
145 Button('submit:cancel', _("Cancel"), 'button'));
147 if (! $request->getArg('remove')) {
150 return HTML::div($ul,HTML::p(_('All selected pages have been permanently removed.')));
159 // c-hanging-comment-ender-p: nil
160 // indent-tabs-mode: nil