]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
AdminUser only ADMIN_USER not member of Administrators
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.15 2004-06-01 15:28:01 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.15 $");
51     }
52
53     function getDefaultArguments() {
54         return array('s'       => '', // preselect pages
55                      'only'    => '',
56                      'exclude' => '',
57                      'info'    => 'most',
58                      'sortby'  => 'pagename',
59                      'limit'    => 0,
60                      'debug'   => false);
61     }
62
63     function collectPages(&$list, &$dbi, $sortby, $limit=0) {
64         $allPages = $dbi->getAllPages(0,$sortby,$limit);
65         while ($pagehandle = $allPages->next()) {
66             $pagename = $pagehandle->getName();
67             if (empty($list[$pagename]))
68                 $list[$pagename] = 0;
69         }
70         return $list;
71     }
72
73     function preSelectS (&$args, &$request) {
74         if (!empty($request->getArg['s']))
75             $args['s'] = $request->getArg['s'];
76         if ( !empty($args['s']) ) {
77             $s = $args['s'];
78             $sl = explodePageList($args['s']);
79             $this->_list = array();
80             if ($sl) {
81                 $request->setArg('verify', 1);
82                 foreach ($sl as $name) {
83                     $this->_list[$name] = 1;
84                 }
85             }
86         } else {
87             $s = '*';
88             if (!empty($args['s']))
89                 $s = $args['s'];
90             $this->_list = array();
91         }
92     }
93
94     function run($dbi, $argstr, &$request, $basepage) {
95         //if ($request->getArg('action') != 'browse')
96         //    return $this->disabled("(action != 'browse')");
97         $args = $this->getArgs($argstr, $request);
98         if (!empty($args['only']))
99             $only = explodePageList($args['only']);
100         else
101             $only = false;
102         if (!empty($args['exclude']))
103             $exclude = explodePageList($args['exclude']);
104         else
105             $exclude = false;
106         $info = $args['info'];
107         $this->debug = $args['debug'];
108         //TODO: use the method preSelectS()
109         if (!empty($request->getArg['s']))
110             $args['s'] = $request->getArg['s'];
111         if (  //( $request->getArg('WikiAdminSelect') == _("Go")) and 
112               !empty($args['s'])) {
113             $s = $args['s'];
114             $sl = explodePageList($args['s']);
115             $this->_list = array();
116             if ($sl) {
117                 $request->setArg('verify',1);
118                 foreach ($sl as $name) {
119                     $this->_list[$name] = 1;
120                 }
121             }
122         } else {
123             $s = '*';
124             if (!empty($args['s']))
125                 $s = $args['s'];
126             $this->_list = array();
127         }
128
129         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
130         $pagename = $request->getArg('pagename');
131         // GetUrlToSelf() with all given params
132         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
133         //$uri = $request->getURLtoSelf();//false, array('verify'));
134         $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
135         if ($request->getArg('WikiAdminSelect') == _("Go"))
136             $p = false;
137         else
138             $p = $request->getArg('p');
139         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
140         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
141                                    HTML::input(array('type' => 'text',
142                                                      'name' => 's',
143                                                      'value' => $s)),
144                                    HTML::input(array('type' => 'submit',
145                                                      'name' => 'WikiAdminSelect',
146                                                      'value' => _("Go")))));
147         if ($request->isPost() 
148             && ! $request->getArg('wikiadmin')
149             && !empty($p)) {
150             $this->_list = array();
151             // List all selected pages again.
152             foreach ($p as $page => $name) {
153                 $this->_list[$name] = 1;
154             }
155         }
156         elseif ($request->isPost()
157                 and $request->_user->isAdmin()
158                 and !empty($p)
159                 //and $request->getArg('verify')
160                 and ($request->getArg('action') == 'WikiAdminSelect')
161                 and $request->getArg('wikiadmin')
162                )
163         {
164             // handle external plugin
165             $loader = new WikiPluginLoader();
166             $a = array_keys($request->getArg('wikiadmin'));
167             $plugin_action = $a[0];
168             $single_arg_plugins = array("Remove");
169             if (in_array($plugin_action,$single_arg_plugins)) {
170                 $plugin = $loader->getPlugin($plugin_action);
171                 $ul = HTML::ul();
172                 foreach ($p as $page => $name) {
173                     $plugin_args = "run_page=$name";
174                     $request->setArg($plugin_action, 1);
175                     $request->setArg('p', array($page => $name));
176                     // if the plugin requires more args than the pagename,
177                     // then this plugin will not return. (Rename, SearchReplace, ...)
178                     $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
179                     $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
180                                                   $name, $select)));
181                     $ul->pushContent(HTML::ul(HTML::li($action_result)));
182                 }
183             } else {
184                 // redirect to the plugin page.
185                 // in which page is this plugin?
186                 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
187                 $args = array();
188                 foreach ($p as $page => $x) {
189                   $args["p[$page]"] = 1;
190                 }
191                 header("Location: ".
192                   WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
193                 exit();
194             }
195         } elseif (empty($args['s'])) {
196             // List all pages to select from.
197             $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
198         }
199         $pagelist = new PageList_Selectable($info, $exclude);
200         $pagelist->addPageList($this->_list);
201         $form->pushContent($pagelist->getContent());
202         foreach ($args as $k => $v) {
203             if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
204                 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
205         }
206         /*
207         foreach ($_GET as $k => $v) {
208             if (!in_array($k,array('s','WikiAdminSelect','action')))
209                 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
210         }
211         */
212         if (! $request->getArg('verify')) {
213             $form->pushContent(HTML::input(array('type' => 'hidden',
214                                                  'name' => 'action',
215                                                  'value' => 'verify')));
216             $form->pushContent(Button('submit:verify', _("Select pages"),
217                                       'wikiadmin'),
218                                Button('submit:cancel', _("Cancel"), 'button'));
219         } else {
220             global $Theme;
221             $form->pushContent(HTML::input(array('type' => 'hidden',
222                                                  'name' => 'action',
223                                                  'value' => 'WikiAdminSelect'))
224                                );
225             // Add the Buttons for all registered WikiAdmin plugins
226             $plugin_dir = 'lib/plugin';
227             if (defined('PHPWIKI_DIR'))
228                 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
229             $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
230             $actions = $fs->getFiles();
231             foreach ($actions as $f) {
232                 $f = preg_replace('/.php$/','', $f);
233                 $s = preg_replace('/^WikiAdmin/','', $f);
234                 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
235                     $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
236                     $form->pushContent($Theme->getButtonSeparator());
237                 }
238             }
239             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
240         }
241         if (! $request->getArg('select')) {
242             return $form;
243         } else {
244             ; //return $action_result;
245         }
246     }
247 }
248
249 // $Log: not supported by cvs2svn $
250 // Revision 1.14  2004/02/24 15:20:07  rurban
251 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
252 //
253 // Revision 1.13  2004/02/22 23:20:33  rurban
254 // fixed DumpHtmlToDir,
255 // enhanced sortby handling in PageList
256 //   new button_heading th style (enabled),
257 // added sortby and limit support to the db backends and plugins
258 //   for paging support (<<prev, next>> links on long lists)
259 //
260 // Revision 1.12  2004/02/19 22:05:57  rurban
261 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
262 //
263 // Revision 1.11  2004/02/17 12:11:36  rurban
264 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
265 //
266 // Revision 1.10  2004/02/15 21:34:37  rurban
267 // PageList enhanced and improved.
268 // fixed new WikiAdmin... plugins
269 // editpage, Theme with exp. htmlarea framework
270 //   (htmlarea yet committed, this is really questionable)
271 // WikiUser... code with better session handling for prefs
272 // enhanced UserPreferences (again)
273 // RecentChanges for show_deleted: how should pages be deleted then?
274 //
275 // Revision 1.9  2004/02/12 13:05:50  rurban
276 // Rename functional for PearDB backend
277 // some other minor changes
278 // SiteMap comes with a not yet functional feature request: includepages (tbd)
279 //
280 // Revision 1.8  2004/02/11 20:00:16  rurban
281 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
282 //
283 // Revision 1.7  2004/01/27 23:23:39  rurban
284 // renamed ->Username => _userid for consistency
285 // renamed mayCheckPassword => mayCheckPass
286 // fixed recursion problem in WikiUserNew
287 // fixed bogo login (but not quite 100% ready yet, password storage)
288 //
289 // Revision 1.6  2004/01/26 19:15:29  rurban
290 // Interim fix
291 //
292 // Revision 1.5  2003/02/24 19:38:04  dairiki
293 // Get rid of unused method Request::debugVars().
294 //
295 // Revision 1.4  2003/02/24 01:36:27  dairiki
296 // Don't use PHPWIKI_DIR unless it's defined.
297 // (Also typo/bugfix in SystemInfo plugin.)
298 //
299 // Revision 1.3  2003/02/22 20:49:56  dairiki
300 // Fixes for "Call-time pass by reference has been deprecated" errors.
301 //
302 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
303 // Code cleanup:
304 // Reformatting & tabs to spaces;
305 // Added copyleft, getVersion, getDescription, rcs_id.
306 //
307
308 // Local Variables:
309 // mode: php
310 // tab-width: 8
311 // c-basic-offset: 4
312 // c-hanging-comment-ender-p: nil
313 // indent-tabs-mode: nil
314 // End:
315 ?>