]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminRemove.php
oops. some missing plugin changes
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminRemove.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminRemove.php,v 1.2 2002-08-22 23:32:33 rurban Exp $');
3 /*
4  Copyright 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 // maybe display more attributes with this class...
24 //require_once('lib/PageList.php'); 
25
26 class WikiPlugin_WikiAdminRemove
27 extends WikiPlugin
28 {
29     function getName() {
30         return _("WikiAdminRemove");
31     }
32
33     function getDescription() {
34         return _("Permanently remove all selected pages.");
35     }
36
37     function getDefaultArguments() {
38         return array('only'    => '',
39                      'exclude' => '',
40                      'debug' => false);
41     }
42
43     function collectPages(&$list, &$dbi) {
44         $allPages = $dbi->getAllPages();
45         while ($pagehandle = $allPages->next()) {
46             $pagename = $pagehandle->getName();
47             if (empty($list[$pagename])) $list[$pagename] = 0;
48         }
49     }
50
51     function addTableHead(&$table) {
52         $row = HTML::tr(HTML::th(_("Select")),
53                         HTML::th(_("Name")));
54         $table->pushContent(HTML::thead($row));
55     }
56
57     function addTableBody(&$list, &$table) {
58         $tbody = HTML::tbody();
59         foreach ($list as $pagename => $selected) {
60             if ($selected) {
61                 $row = HTML::tr(array('class' => 'oddrow'),
62                                 HTML::td(HTML::input(array('type' => 'checkbox',
63                                                            'name' => "p[$pagename]",
64                                                            'value' => $pagename,
65                                                            'checked' => '1'))),
66                                 HTML::td(WikiLink($pagename)));
67             } else {
68                 $row = HTML::tr(array('class' => 'evenrow'),
69                                 HTML::td(HTML::input(array('type' => 'checkbox',
70                                                            'name' => "p[$pagename]",
71                                                            'value' => $pagename))),
72                                 HTML::td(WikiLink($pagename)));
73             }
74             $tbody->pushContent($row);
75         }
76         $table->pushContent($tbody);
77     }
78
79     function formatTable(&$list, &$dbi) {
80         $table = HTML::table(array('cellpadding' => 2,
81                                    'cellspacing' => 1,
82                                    'border'      => 0,
83                                    'class' => 'pagelist'));
84         $table->pushContent(HTML::caption(array('align'=>'top'), 
85                                           _("Permanently remove all selected pages.")));
86         // $this->addTableHead($table);
87         $this->addTableBody($list, $table);
88         return $table;
89     }
90
91     function run($dbi, $argstr, $request) {
92         $args = $this->getArgs($argstr, $request);
93         if (!empty($args['only']))
94             $this->only = explode(',',$args['only']);
95         if (!empty($args['exclude']))
96             $this->only = explode(',',$args['exclude']);
97         $this->debug = $args['debug'];
98         $this->_list = array();
99         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
100         $pagename = $request->getArg('pagename');
101         $form = HTML::form(array('action' => $_SERVER['REQUEST_URI'], 'method' => 'POST'));
102         if ($request->isPost() and $request->getArg('verify')) {
103             // List all to be deleted pages again.
104             foreach ($GLOBALS['HTTP_POST_VARS']['p'] as $page => $name) {
105                 $this->_list[$name] = 1;
106             }
107         } elseif ($request->isPost() and $request->getArg('remove')) {
108             // Real delete.
109             $ul = HTML::ul();
110             foreach ($GLOBALS['HTTP_POST_VARS']['p'] as $page => $name) {
111                 $dbi = $request->getDbh();
112                 $dbi->deletePage($name);
113                 $ul->pushContent(HTML::li(fmt("Removed page '%s' succesfully.", $name)));
114             }
115         } else {
116             // List all pages to select from.
117             $this->collectPages($this->_list, &$dbi);
118         }
119         $table = $this->formatTable($this->_list, &$dbi, &$request);
120         $form->pushContent($table);
121         $form->pushContent(HiddenInputs($GLOBALS['HTTP_GET_VARS'])); // debugging params, ...
122         // if (! USE_PATH_INFO ) $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'pagename', 'value' => $pagename)));
123         if (! $request->getArg('verify')) {
124             $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify')));
125             $form->pushContent(Button('submit:verify', _("Remove selected pages"), 'wikiadmin'), 
126                                Button('submit:cancel', _("Cancel"), 'button'));
127         } else {
128             $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'remove')));
129             $form->pushContent(Button('submit:remove', _("Remove selected pages"), 'wikiadmin'),
130                                Button('submit:cancel', _("Cancel"), 'button'));
131         }
132         if (! $request->getArg('remove')) {
133             return $form;
134         } else {
135             return HTML::div($ul,HTML::p(_('All selected pages have been permanently removed.')));
136         }
137     }
138 }
139
140 // Local Variables:
141 // mode: php
142 // tab-width: 8
143 // c-basic-offset: 4
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil
146 // End:
147 ?>