]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminRemove.php
new PrevNext plugin with two buttons
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminRemove.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminRemove.php,v 1.3 2002-08-24 13:18:56 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 /**
24  * Displays a url in a seperate frame inside our body.
25  * Usage:   <?plugin WikiAdminRemove?>
26  * Author:  Reini Urban <rurban@x-ray.at>
27  *
28  * KNOWN ISSUES:
29  * Currently we must be Admin.
30  * Future versions will support PagePermissions.
31  * requires PHP 4.2 so far.
32  */ 
33 // maybe display more attributes with this class...
34 //require_once('lib/PageList.php'); 
35
36 class WikiPlugin_WikiAdminRemove
37 extends WikiPlugin
38 {
39     function getName() {
40         return _("WikiAdminRemove");
41     }
42
43     function getDescription() {
44         return _("Permanently remove all selected pages.");
45     }
46
47     function getDefaultArguments() {
48         return array('only'    => '',
49                      'exclude' => '',
50                      'debug' => false);
51     }
52
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;
58         }
59     }
60
61     function addTableHead(&$table) {
62         $row = HTML::tr(HTML::th(_("Select")),
63                         HTML::th(_("Name")));
64         $table->pushContent(HTML::thead($row));
65     }
66
67     function addTableBody(&$list, &$table) {
68         $tbody = HTML::tbody();
69         foreach ($list as $pagename => $selected) {
70             if ($selected) {
71                 $row = HTML::tr(array('class' => 'oddrow'),
72                                 HTML::td(HTML::input(array('type' => 'checkbox',
73                                                            'name' => "p[$pagename]",
74                                                            'value' => $pagename,
75                                                            'checked' => '1'))),
76                                 HTML::td(WikiLink($pagename)));
77             } else {
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)));
83             }
84             $tbody->pushContent($row);
85         }
86         $table->pushContent($tbody);
87     }
88
89     function formatTable(&$list, &$dbi) {
90         $table = HTML::table(array('cellpadding' => 2,
91                                    'cellspacing' => 1,
92                                    'border'      => 0,
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);
98         return $table;
99     }
100
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;
120             }
121         } elseif ($request->isPost() and $request->_user->isAdmin() and 
122                   $request->getArg('remove')) {
123             // Real delete.
124             $ul = HTML::ul();
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)));
129             }
130         } else {
131             // List all pages to select from.
132             $this->collectPages($this->_list, &$dbi);
133         }
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'));
142         } else {
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'));
146         }
147         if (! $request->getArg('remove')) {
148             return $form;
149         } else {
150             return HTML::div($ul,HTML::p(_('All selected pages have been permanently removed.')));
151         }
152     }
153 }
154
155 // Local Variables:
156 // mode: php
157 // tab-width: 8
158 // c-basic-offset: 4
159 // c-hanging-comment-ender-p: nil
160 // indent-tabs-mode: nil
161 // End:
162 ?>