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