]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.12 2004-02-19 22:05:57 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.12 $");
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, $basepage) {
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             $loader = 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 = $loader->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, $basepage);
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.11  2004/02/17 12:11:36  rurban
228 // 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, ...)
229 //
230 // Revision 1.10  2004/02/15 21:34:37  rurban
231 // PageList enhanced and improved.
232 // fixed new WikiAdmin... plugins
233 // editpage, Theme with exp. htmlarea framework
234 //   (htmlarea yet committed, this is really questionable)
235 // WikiUser... code with better session handling for prefs
236 // enhanced UserPreferences (again)
237 // RecentChanges for show_deleted: how should pages be deleted then?
238 //
239 // Revision 1.9  2004/02/12 13:05:50  rurban
240 // Rename functional for PearDB backend
241 // some other minor changes
242 // SiteMap comes with a not yet functional feature request: includepages (tbd)
243 //
244 // Revision 1.8  2004/02/11 20:00:16  rurban
245 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
246 //
247 // Revision 1.7  2004/01/27 23:23:39  rurban
248 // renamed ->Username => _userid for consistency
249 // renamed mayCheckPassword => mayCheckPass
250 // fixed recursion problem in WikiUserNew
251 // fixed bogo login (but not quite 100% ready yet, password storage)
252 //
253 // Revision 1.6  2004/01/26 19:15:29  rurban
254 // Interim fix
255 //
256 // Revision 1.5  2003/02/24 19:38:04  dairiki
257 // Get rid of unused method Request::debugVars().
258 //
259 // Revision 1.4  2003/02/24 01:36:27  dairiki
260 // Don't use PHPWIKI_DIR unless it's defined.
261 // (Also typo/bugfix in SystemInfo plugin.)
262 //
263 // Revision 1.3  2003/02/22 20:49:56  dairiki
264 // Fixes for "Call-time pass by reference has been deprecated" errors.
265 //
266 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
267 // Code cleanup:
268 // Reformatting & tabs to spaces;
269 // Added copyleft, getVersion, getDescription, rcs_id.
270 //
271
272 // Local Variables:
273 // mode: php
274 // tab-width: 8
275 // c-basic-offset: 4
276 // c-hanging-comment-ender-p: nil
277 // indent-tabs-mode: nil
278 // End:
279 ?>