]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
Interim fix
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.6 2004-01-26 19:15:29 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  * Allows selection of multiple pages which get passed to other
25  * WikiAdmin plugins then. Then do Rename, Remove, Chmod, Chown, ...
26  *
27  * Usage:   <?plugin WikiAdminSelect?>
28  * Author:  Reini Urban <rurban@x-ray.at>
29  *
30  * KNOWN ISSUES:
31  * Just a framework, nothing more.
32  * Future versions will support PagePermissions.
33  */
34 // maybe display more attributes with this class...
35 require_once('lib/PageList.php');
36
37 class WikiPlugin_WikiAdminSelect
38 extends WikiPlugin
39 {
40     function getName() {
41         return _("WikiAdminSelect");
42     }
43
44     function getDescription() {
45         return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
46     }
47
48     function getVersion() {
49         return preg_replace("/[Revision: $]/", '',
50                             "\$Revision: 1.6 $");
51     }
52
53     function getDefaultArguments() {
54         return array('s'   => '*',
55                      'only'    => '',
56                      'exclude' => '',
57                      'info'    => 'all',
58                      'debug'   => false);
59     }
60
61     function collectPages(&$list, &$dbi) {
62         $allPages = $dbi->getAllPages();
63         while ($pagehandle = $allPages->next()) {
64             $pagename = $pagehandle->getName();
65             if (empty($list[$pagename]))
66                 $list[$pagename] = 0;
67         }
68     }
69
70     function run($dbi, $argstr, $request) {
71         $args = $this->getArgs($argstr, $request);
72         if (!empty($args['only']))
73             $only = explodePageList($args['only']);
74         else
75             $only = false;
76         if (!empty($args['exclude']))
77             $exclude = explodePageList($args['exclude']);
78         else
79             $exclude = false;
80         $info = $args['info'];
81         $this->debug = $args['debug'];
82         if (!empty($request->getArg['s']))
83             $args['s'] = $request->getArg['s'];
84         if (!empty($args['s'])) {
85             $s = $args['s'];
86             $sl = explodePageList($args['s']);
87             $this->_list = array();
88             if ($sl) {
89                 $request->setArg('verify',1);
90                 foreach ($sl as $name) {
91                     $this->_list[$name] = 1;
92                 }
93             }
94         } else {
95             $s = '*';
96             $this->_list = array();
97         }
98         $this->debug = $args['debug'];
99         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
100         $pagename = $request->getArg('pagename');
101         // GetUrlToSelf() with all given params
102         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
103         $uri = $request->getURLtoSelf(false, array('verify'));
104         $form = HTML::form(array('action' => $uri, 'method' => 'POST'));
105         if ($request->getArg('submit') == 'WikiAdminSelect')
106             $p = false;
107         else
108             $p = $request->getArg('p');
109         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
110         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
111                                    HTML::input(array('type' => 'text',
112                                                      'name' => 's',
113                                                      'value' => $s)),
114                                    HTML::input(array('type' => 'submit',
115                                                      'name' => 'WikiAdminSelect',
116                                                      'value' => _("Go")))));
117         if ($request->isPost() && $request->getArg('verify') && !empty($p)) {
118             // List all selected pages again.
119             foreach ($p as $page => $name) {
120                 $this->_list[$name] = 1;
121             }
122         } elseif ($request->isPost() && $request->_user->isAdmin()
123                   && !empty($p)
124                   && $request->getArg('action') == 'WikiAdminSelect') {
125             // handle external plugin
126             $l = new WikiPluginLoader();
127             $plugin_action = $request->getArg('submit');
128             $plugin = $l->getPlugin($plugin_action);
129
130             $ul = HTML::ul();
131             foreach ($p as $page => $name) {
132                 $plugin_args = "run_page=$name";
133                 $request->setArg($plugin_action, 1);
134                 $request->setArg('p', array($page => $name));
135                 $action_result = $plugin->run($dbi, $plugin_args, $request);
136                 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
137                                               $name, $select)));
138                 $ul->pushContent(HTML::ul(HTML::li($action_result)));
139             }
140         } elseif (empty($args['s'])) {
141             // List all pages to select from.
142             $this->collectPages($this->_list, $dbi);
143         }
144         $pagelist = new PageList_Selectable($info
145                                             ? 'checkbox,' . $info
146                                             : 'checkbox', $exclude);
147         $pagelist->addPageList($this->_list);
148         $form->pushContent($pagelist->getContent());
149         foreach ($_GET as $k => $v) {
150             if (!in_array($k,array('s','WikiAdminSelect','action')))
151                 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
152         }
153         if (! $request->getArg('verify')) {
154             $form->pushContent(HTML::input(array('type' => 'hidden',
155                                                  'name' => 'action',
156                                                  'value' => 'verify')));
157             $form->pushContent(Button('submit:verify', _("Select pages"),
158                                       'wikiadmin'),
159                                Button('submit:cancel', _("Cancel"), 'button'));
160         } else {
161             global $Theme;
162             $form->pushContent(HTML::input(array('type' => 'hidden',
163                                                  'name' => 'action',
164                                                  'value' => 'WikiAdminSelect'))
165                                );
166             // Add the Buttons for all registered WikiAdmin plugins
167             $plugin_dir = 'lib/plugin';
168             if (defined('PHPWIKI_DIR'))
169                 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
170             $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
171             $actions = $fs->getFiles();
172             foreach ($actions as $f) {
173                 $f = preg_replace('/.php$/','', $f);
174                 $s = preg_replace('/^WikiAdmin/','', $f);
175                 $form->pushContent(Button("submit:$f", _($s), "wikiadmin"));
176                 $form->pushContent($Theme->getButtonSeparator());
177             }
178             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
179         }
180         if (! $request->getArg('select')) {
181             return $form;
182         } else {
183             ; //return $action_result;
184         }
185     }
186 }
187
188 // $Log: not supported by cvs2svn $
189 // Revision 1.5  2003/02/24 19:38:04  dairiki
190 // Get rid of unused method Request::debugVars().
191 //
192 // Revision 1.4  2003/02/24 01:36:27  dairiki
193 // Don't use PHPWIKI_DIR unless it's defined.
194 // (Also typo/bugfix in SystemInfo plugin.)
195 //
196 // Revision 1.3  2003/02/22 20:49:56  dairiki
197 // Fixes for "Call-time pass by reference has been deprecated" errors.
198 //
199 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
200 // Code cleanup:
201 // Reformatting & tabs to spaces;
202 // Added copyleft, getVersion, getDescription, rcs_id.
203 //
204
205 // Local Variables:
206 // mode: php
207 // tab-width: 8
208 // c-basic-offset: 4
209 // c-hanging-comment-ender-p: nil
210 // indent-tabs-mode: nil
211 // End:
212 ?>