]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
just aesthetics
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.20 2004-10-04 23:39:34 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  * This is the base class for most WikiAdmin* classes, using
31  * collectPages() and preSelectS().
32  * "list" PagePermissions supported implicitly by PageList.
33  */
34 require_once('lib/PageList.php');
35
36 class WikiPlugin_WikiAdminSelect
37 extends WikiPlugin
38 {
39     function getName() {
40         return _("WikiAdminSelect");
41     }
42
43     function getDescription() {
44         return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
45     }
46
47     function getVersion() {
48         return preg_replace("/[Revision: $]/", '',
49                             "\$Revision: 1.20 $");
50     }
51
52     function getDefaultArguments() {
53         return array('s'       => '', // preselect pages
54                      /* select pages by meta-data: */
55                      'author'   => false,
56                      'owner'    => false,
57                      'creator'  => false,
58
59                      'only'    => '',
60                      'exclude' => '',
61                      'info'    => 'most',
62                      'sortby'  => 'pagename',
63                      'limit'    => 0,
64                      'debug'   => false);
65     }
66
67     /**
68      * Default collector for all WikiAdmin* plugins.
69      * preSelectS() is similar, but fills $this->_list
70      */
71     function collectPages(&$list, &$dbi, $sortby, $limit=0) {
72         $allPages = $dbi->getAllPages(0,$sortby,$limit);
73         while ($pagehandle = $allPages->next()) {
74             $pagename = $pagehandle->getName();
75             if (empty($list[$pagename]))
76                 $list[$pagename] = 0;
77         }
78         return $list;
79     }
80
81     /**
82      * Preselect a list of pagenames by the supporting the follwing args:
83      * 's': comma-seperated list of pagename wildcards
84      * 'author', 'owner', 'creator': from WikiDB_Page
85      * 'only: forgot what the diffrrence to 's' was.
86      * Sets $this->_list, which is picked up by collectPages() and is a default for p[]
87      */
88     function preSelectS (&$args, &$request) {
89         // override plugin argument by GET: probably not needed if s||="" is used
90         // anyway, we force it for unique interface.
91         if (!empty($request->getArg['s']))
92             $args['s'] = $request->getArg['s'];
93         if ( !empty($args['owner']) )
94             $sl = PageList::allPagesByOwner($args['owner'],false,$args['sortby'],$args['limit']);
95         elseif ( !empty($args['author']) )
96             $sl = PageList::allPagesByAuthor($args['author'],false,$args['sortby'],$args['limit']);
97         elseif ( !empty($args['creator']) )
98             $sl = PageList::allPagesByCreator($args['creator'],false,$args['sortby'],$args['limit']);
99         elseif ( !empty($args['s']) or !empty($args['only']) ) {
100             // all pages by name
101             $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
102         }
103         $this->_list = array();
104         if (!empty($sl)) {
105             $request->setArg('verify', 1);
106             if (!empty($args['exclude']))
107                 $exclude = explodePageList($args['exclude']);
108             foreach ($sl as $name) {
109                 if (!empty($args['exclude'])) {
110                     if (!in_array($name, $exclude))
111                         $this->_list[$name] = 1;
112                 } else {
113                     $this->_list[$name] = 1;
114                 }
115             }
116         }
117         return $this->_list;
118     }
119
120     function run($dbi, $argstr, &$request, $basepage) {
121         //if ($request->getArg('action') != 'browse')
122         //    return $this->disabled("(action != 'browse')");
123         $args = $this->getArgs($argstr, $request);
124         $this->_args = $args;
125         extract($args);
126         $this->preSelectS($args, $request);
127
128         $info = $args['info'];
129         $this->debug = $args['debug'];
130
131         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
132         $pagename = $request->getArg('pagename');
133         // GetUrlToSelf() with all given params
134         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
135         //$uri = $request->getURLtoSelf();//false, array('verify'));
136         $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
137         if ($request->getArg('WikiAdminSelect') == _("Go"))
138             $p = false;
139         else
140             $p = $request->getArg('p');
141         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
142         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
143                                    HTML::input(array('type' => 'text',
144                                                      'name' => 's',
145                                                      'value' => $args['s'])),
146                                    HTML::input(array('type' => 'submit',
147                                                      'name' => 'WikiAdminSelect',
148                                                      'value' => _("Go")))));
149         if ($request->isPost() 
150             && ! $request->getArg('wikiadmin')
151             && !empty($p)) {
152             $this->_list = array();
153             // List all selected pages again.
154             foreach ($p as $page => $name) {
155                 $this->_list[$name] = 1;
156             }
157         }
158         elseif ($request->isPost()
159                 and $request->_user->isAdmin()
160                 and !empty($p)
161                 //and $request->getArg('verify')
162                 and ($request->getArg('action') == 'WikiAdminSelect')
163                 and $request->getArg('wikiadmin')
164                )
165         {
166             // handle external plugin
167             $loader = new WikiPluginLoader();
168             $a = array_keys($request->getArg('wikiadmin'));
169             $plugin_action = $a[0];
170             $single_arg_plugins = array("Remove");
171             if (in_array($plugin_action, $single_arg_plugins)) {
172                 $plugin = $loader->getPlugin($plugin_action);
173                 $ul = HTML::ul();
174                 foreach ($p as $page => $name) {
175                     $plugin_args = "run_page=$name";
176                     $request->setArg($plugin_action, 1);
177                     $request->setArg('p', array($page => $name));
178                     // if the plugin requires more args than the pagename,
179                     // then this plugin will not return. (Rename, SearchReplace, ...)
180                     $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
181                     $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
182                                                   $name, $select)));
183                     $ul->pushContent(HTML::ul(HTML::li($action_result)));
184                 }
185             } else {
186                 // redirect to the plugin page.
187                 // in which page is this plugin?
188                 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
189                 $args = array();
190                 foreach ($p as $page => $x) {
191                   $args["p[$page]"] = 1;
192                 }
193                 header("Location: ".
194                   WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
195                 exit();
196             }
197         } elseif (empty($args['s'])) {
198             // List all pages to select from.
199             $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
200         }
201         $pagelist = new PageList_Selectable($info, $exclude, $args);
202         $pagelist->addPageList($this->_list);
203         $form->pushContent($pagelist->getContent());
204         foreach ($args as $k => $v) {
205             if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
206                 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
207         }
208         /*
209         foreach ($_GET as $k => $v) {
210             if (!in_array($k,array('s','WikiAdminSelect','action')))
211                 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
212         }
213         */
214         if (! $request->getArg('verify')) {
215             $form->pushContent(HTML::input(array('type' => 'hidden',
216                                                  'name' => 'action',
217                                                  'value' => 'verify')));
218             $form->pushContent(Button('submit:verify', _("Select pages"),
219                                       'wikiadmin'),
220                                Button('submit:cancel', _("Cancel"), 'button'));
221         } else {
222             global $WikiTheme;
223             $form->pushContent(HTML::input(array('type' => 'hidden',
224                                                  'name' => 'action',
225                                                  'value' => 'WikiAdminSelect'))
226                                );
227             // Add the Buttons for all registered WikiAdmin plugins
228             $plugin_dir = 'lib/plugin';
229             if (defined('PHPWIKI_DIR'))
230                 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
231             $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
232             $actions = $fs->getFiles();
233             foreach ($actions as $f) {
234                 $f = preg_replace('/.php$/','', $f);
235                 $s = preg_replace('/^WikiAdmin/','', $f);
236                 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
237                     $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
238                     $form->pushContent($WikiTheme->getButtonSeparator());
239                 }
240             }
241             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
242         }
243         if (! $request->getArg('select')) {
244             return $form;
245         } else {
246             ; //return $action_result;
247         }
248     }
249 }
250
251 // $Log: not supported by cvs2svn $
252 // Revision 1.19  2004/06/29 08:52:24  rurban
253 // Use ...version() $need_content argument in WikiDB also:
254 // To reduce the memory footprint for larger sets of pagelists,
255 // we don't cache the content (only true or false) and
256 // we purge the pagedata (_cached_html) also.
257 // _cached_html is only cached for the current pagename.
258 // => Vastly improved page existance check, ACL check, ...
259 //
260 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
261 //
262 // Revision 1.18  2004/06/16 10:38:59  rurban
263 // Disallow refernces in calls if the declaration is a reference
264 // ("allow_call_time_pass_reference clean").
265 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
266 //   but several external libraries may not.
267 //   In detail these libs look to be affected (not tested):
268 //   * Pear_DB odbc
269 //   * adodb oracle
270 //
271 // Revision 1.17  2004/06/14 11:31:39  rurban
272 // renamed global $Theme to $WikiTheme (gforge nameclash)
273 // inherit PageList default options from PageList
274 //   default sortby=pagename
275 // use options in PageList_Selectable (limit, sortby, ...)
276 // added action revert, with button at action=diff
277 // added option regex to WikiAdminSearchReplace
278 //
279 // Revision 1.16  2004/06/13 15:33:20  rurban
280 // new support for arguments owner, author, creator in most relevant
281 // PageList plugins. in WikiAdmin* via preSelectS()
282 //
283 // Revision 1.15  2004/06/01 15:28:01  rurban
284 // AdminUser only ADMIN_USER not member of Administrators
285 // some RateIt improvements by dfrankow
286 // edit_toolbar buttons
287 //
288 // Revision 1.14  2004/02/24 15:20:07  rurban
289 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
290 //
291 // Revision 1.13  2004/02/22 23:20:33  rurban
292 // fixed DumpHtmlToDir,
293 // enhanced sortby handling in PageList
294 //   new button_heading th style (enabled),
295 // added sortby and limit support to the db backends and plugins
296 //   for paging support (<<prev, next>> links on long lists)
297 //
298 // Revision 1.12  2004/02/19 22:05:57  rurban
299 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
300 //
301 // Revision 1.11  2004/02/17 12:11:36  rurban
302 // 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, ...)
303 //
304 // Revision 1.10  2004/02/15 21:34:37  rurban
305 // PageList enhanced and improved.
306 // fixed new WikiAdmin... plugins
307 // editpage, Theme with exp. htmlarea framework
308 //   (htmlarea yet committed, this is really questionable)
309 // WikiUser... code with better session handling for prefs
310 // enhanced UserPreferences (again)
311 // RecentChanges for show_deleted: how should pages be deleted then?
312 //
313 // Revision 1.9  2004/02/12 13:05:50  rurban
314 // Rename functional for PearDB backend
315 // some other minor changes
316 // SiteMap comes with a not yet functional feature request: includepages (tbd)
317 //
318 // Revision 1.8  2004/02/11 20:00:16  rurban
319 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
320 //
321 // Revision 1.7  2004/01/27 23:23:39  rurban
322 // renamed ->Username => _userid for consistency
323 // renamed mayCheckPassword => mayCheckPass
324 // fixed recursion problem in WikiUserNew
325 // fixed bogo login (but not quite 100% ready yet, password storage)
326 //
327 // Revision 1.6  2004/01/26 19:15:29  rurban
328 // Interim fix
329 //
330 // Revision 1.5  2003/02/24 19:38:04  dairiki
331 // Get rid of unused method Request::debugVars().
332 //
333 // Revision 1.4  2003/02/24 01:36:27  dairiki
334 // Don't use PHPWIKI_DIR unless it's defined.
335 // (Also typo/bugfix in SystemInfo plugin.)
336 //
337 // Revision 1.3  2003/02/22 20:49:56  dairiki
338 // Fixes for "Call-time pass by reference has been deprecated" errors.
339 //
340 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
341 // Code cleanup:
342 // Reformatting & tabs to spaces;
343 // Added copyleft, getVersion, getDescription, rcs_id.
344 //
345
346 // Local Variables:
347 // mode: php
348 // tab-width: 8
349 // c-basic-offset: 4
350 // c-hanging-comment-ender-p: nil
351 // indent-tabs-mode: nil
352 // End:
353 ?>