]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
Valid XHTML code
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.26 2008-08-20 18:16:55 vargenau 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.26 $");
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'    => 150,
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, $exclude='') {
72         $allPages = $dbi->getAllPages(0, $sortby, $limit, $exclude);
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 following args:
83      * 's': comma-seperated list of pagename wildcards
84      * 'author', 'owner', 'creator': from WikiDB_Page
85      * 'only: forgot what the difference 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'],$args['exclude']);
95         elseif ( !empty($args['author']) )
96             $sl = PageList::allPagesByAuthor($args['author'],false,$args['sortby'],$args['limit'],$args['exclude']);
97         elseif ( !empty($args['creator']) )
98             $sl = PageList::allPagesByCreator($args['creator'],false,$args['sortby'],$args['limit'],$args['exclude']);
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             foreach ($sl as $name) {
107                 if (!empty($args['exclude'])) {
108                     if (!in_array($name, $args['exclude']))
109                         $this->_list[$name] = 1;
110                 } else {
111                     $this->_list[$name] = 1;
112                 }
113             }
114         }
115         return $this->_list;
116     }
117
118     function run($dbi, $argstr, &$request, $basepage) {
119         //if ($request->getArg('action') != 'browse')
120         //    return $this->disabled("(action != 'browse')");
121         $args = $this->getArgs($argstr, $request);
122         $this->_args = $args;
123         extract($args);
124         $this->preSelectS($args, $request);
125
126         $info = $args['info'];
127         $this->debug = $args['debug'];
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' => $args['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, $args['exclude'], $args);
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 $WikiTheme;
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($WikiTheme->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     function _tablePush(&$table, $first, $second) {
249         $table->pushContent(
250                             HTML::tr(
251                                      HTML::td($first),
252                                      HTML::td($second)));
253     }
254
255 }
256
257 // $Log: not supported by cvs2svn $
258 // Revision 1.25  2007/08/25 18:10:17  rurban
259 // add default _tablePush
260 //
261 // Revision 1.24  2007/01/04 16:47:13  rurban
262 // Clarify API: sortby,limit and exclude are strings.
263 //
264 // Revision 1.23  2005/09/14 06:06:09  rurban
265 // use a sane limit of 150
266 //
267 // Revision 1.22  2004/12/06 19:50:05  rurban
268 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
269 // renamed delete_page to purge_page.
270 // enable action=edit&version=-1 to force creation of a new version.
271 // added BABYCART_PATH config
272 // fixed magiqc in adodb.inc.php
273 // and some more docs
274 //
275 // Revision 1.21  2004/11/23 15:17:20  rurban
276 // better support for case_exact search (not caseexact for consistency),
277 // plugin args simplification:
278 //   handle and explode exclude and pages argument in WikiPlugin::getArgs
279 //     and exclude in advance (at the sql level if possible)
280 //   handle sortby and limit from request override in WikiPlugin::getArgs
281 // ListSubpages: renamed pages to maxpages
282 //
283 // Revision 1.20  2004/10/04 23:39:34  rurban
284 // just aesthetics
285 //
286 // Revision 1.19  2004/06/29 08:52:24  rurban
287 // Use ...version() $need_content argument in WikiDB also:
288 // To reduce the memory footprint for larger sets of pagelists,
289 // we don't cache the content (only true or false) and
290 // we purge the pagedata (_cached_html) also.
291 // _cached_html is only cached for the current pagename.
292 // => Vastly improved page existance check, ACL check, ...
293 //
294 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
295 //
296 // Revision 1.18  2004/06/16 10:38:59  rurban
297 // Disallow refernces in calls if the declaration is a reference
298 // ("allow_call_time_pass_reference clean").
299 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
300 //   but several external libraries may not.
301 //   In detail these libs look to be affected (not tested):
302 //   * Pear_DB odbc
303 //   * adodb oracle
304 //
305 // Revision 1.17  2004/06/14 11:31:39  rurban
306 // renamed global $Theme to $WikiTheme (gforge nameclash)
307 // inherit PageList default options from PageList
308 //   default sortby=pagename
309 // use options in PageList_Selectable (limit, sortby, ...)
310 // added action revert, with button at action=diff
311 // added option regex to WikiAdminSearchReplace
312 //
313 // Revision 1.16  2004/06/13 15:33:20  rurban
314 // new support for arguments owner, author, creator in most relevant
315 // PageList plugins. in WikiAdmin* via preSelectS()
316 //
317 // Revision 1.15  2004/06/01 15:28:01  rurban
318 // AdminUser only ADMIN_USER not member of Administrators
319 // some RateIt improvements by dfrankow
320 // edit_toolbar buttons
321 //
322 // Revision 1.14  2004/02/24 15:20:07  rurban
323 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
324 //
325 // Revision 1.13  2004/02/22 23:20:33  rurban
326 // fixed DumpHtmlToDir,
327 // enhanced sortby handling in PageList
328 //   new button_heading th style (enabled),
329 // added sortby and limit support to the db backends and plugins
330 //   for paging support (<<prev, next>> links on long lists)
331 //
332 // Revision 1.12  2004/02/19 22:05:57  rurban
333 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
334 //
335 // Revision 1.11  2004/02/17 12:11:36  rurban
336 // 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, ...)
337 //
338 // Revision 1.10  2004/02/15 21:34:37  rurban
339 // PageList enhanced and improved.
340 // fixed new WikiAdmin... plugins
341 // editpage, Theme with exp. htmlarea framework
342 //   (htmlarea yet committed, this is really questionable)
343 // WikiUser... code with better session handling for prefs
344 // enhanced UserPreferences (again)
345 // RecentChanges for show_deleted: how should pages be deleted then?
346 //
347 // Revision 1.9  2004/02/12 13:05:50  rurban
348 // Rename functional for PearDB backend
349 // some other minor changes
350 // SiteMap comes with a not yet functional feature request: includepages (tbd)
351 //
352 // Revision 1.8  2004/02/11 20:00:16  rurban
353 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
354 //
355 // Revision 1.7  2004/01/27 23:23:39  rurban
356 // renamed ->Username => _userid for consistency
357 // renamed mayCheckPassword => mayCheckPass
358 // fixed recursion problem in WikiUserNew
359 // fixed bogo login (but not quite 100% ready yet, password storage)
360 //
361 // Revision 1.6  2004/01/26 19:15:29  rurban
362 // Interim fix
363 //
364 // Revision 1.5  2003/02/24 19:38:04  dairiki
365 // Get rid of unused method Request::debugVars().
366 //
367 // Revision 1.4  2003/02/24 01:36:27  dairiki
368 // Don't use PHPWIKI_DIR unless it's defined.
369 // (Also typo/bugfix in SystemInfo plugin.)
370 //
371 // Revision 1.3  2003/02/22 20:49:56  dairiki
372 // Fixes for "Call-time pass by reference has been deprecated" errors.
373 //
374 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
375 // Code cleanup:
376 // Reformatting & tabs to spaces;
377 // Added copyleft, getVersion, getDescription, rcs_id.
378 //
379
380 // Local Variables:
381 // mode: php
382 // tab-width: 8
383 // c-basic-offset: 4
384 // c-hanging-comment-ender-p: nil
385 // indent-tabs-mode: nil
386 // End:
387 ?>