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