2 rcs_id('$Id: WikiAdminSelect.php,v 1.25 2007-08-25 18:10:17 rurban Exp $');
4 Copyright 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
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.
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.
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
24 * Allows selection of multiple pages which get passed to other
25 * WikiAdmin plugins then. Then do Rename, Remove, Chmod, Chown, ...
27 * Usage: <?plugin WikiAdminSelect?>
28 * Author: Reini Urban <rurban@x-ray.at>
30 * This is the base class for most WikiAdmin* classes, using
31 * collectPages() and preSelectS().
32 * "list" PagePermissions supported implicitly by PageList.
34 require_once('lib/PageList.php');
36 class WikiPlugin_WikiAdminSelect
40 return _("WikiAdminSelect");
43 function getDescription() {
44 return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
47 function getVersion() {
48 return preg_replace("/[Revision: $]/", '',
49 "\$Revision: 1.25 $");
52 function getDefaultArguments() {
53 return array('s' => '', // preselect pages
54 /* select pages by meta-data: */
62 'sortby' => 'pagename',
68 * Default collector for all WikiAdmin* plugins.
69 * preSelectS() is similar, but fills $this->_list
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]))
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[]
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']) ) {
101 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
103 $this->_list = array();
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;
111 $this->_list[$name] = 1;
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;
124 $this->preSelectS($args, $request);
126 $info = $args['info'];
127 $this->debug = $args['debug'];
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"))
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',
143 'value' => $args['s'])),
144 HTML::input(array('type' => 'submit',
145 'name' => 'WikiAdminSelect',
146 'value' => _("Go")))));
147 if ($request->isPost()
148 && ! $request->getArg('wikiadmin')
150 $this->_list = array();
151 // List all selected pages again.
152 foreach ($p as $page => $name) {
153 $this->_list[$name] = 1;
156 elseif ($request->isPost()
157 and $request->_user->isAdmin()
159 //and $request->getArg('verify')
160 and ($request->getArg('action') == 'WikiAdminSelect')
161 and $request->getArg('wikiadmin')
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);
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'.",
181 $ul->pushContent(HTML::ul(HTML::li($action_result)));
184 // redirect to the plugin page.
185 // in which page is this plugin?
186 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
188 foreach ($p as $page => $x) {
189 $args["p[$page]"] = 1;
192 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
195 } elseif (empty($args['s'])) {
196 // List all pages to select from.
197 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
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
207 foreach ($_GET as $k => $v) {
208 if (!in_array($k,array('s','WikiAdminSelect','action')))
209 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
212 if (! $request->getArg('verify')) {
213 $form->pushContent(HTML::input(array('type' => 'hidden',
215 'value' => 'verify')));
216 $form->pushContent(Button('submit:verify', _("Select pages"),
218 Button('submit:cancel', _("Cancel"), 'button'));
221 $form->pushContent(HTML::input(array('type' => 'hidden',
223 'value' => 'WikiAdminSelect'))
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());
239 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
241 if (! $request->getArg('select')) {
244 ; //return $action_result;
248 function _tablePush(&$table, $first, $second) {
257 // $Log: not supported by cvs2svn $
258 // Revision 1.24 2007/01/04 16:47:13 rurban
259 // Clarify API: sortby,limit and exclude are strings.
261 // Revision 1.23 2005/09/14 06:06:09 rurban
262 // use a sane limit of 150
264 // Revision 1.22 2004/12/06 19:50:05 rurban
265 // enable action=remove which is undoable and seeable in RecentChanges: ADODB ony for now.
266 // renamed delete_page to purge_page.
267 // enable action=edit&version=-1 to force creation of a new version.
268 // added BABYCART_PATH config
269 // fixed magiqc in adodb.inc.php
270 // and some more docs
272 // Revision 1.21 2004/11/23 15:17:20 rurban
273 // better support for case_exact search (not caseexact for consistency),
274 // plugin args simplification:
275 // handle and explode exclude and pages argument in WikiPlugin::getArgs
276 // and exclude in advance (at the sql level if possible)
277 // handle sortby and limit from request override in WikiPlugin::getArgs
278 // ListSubpages: renamed pages to maxpages
280 // Revision 1.20 2004/10/04 23:39:34 rurban
283 // Revision 1.19 2004/06/29 08:52:24 rurban
284 // Use ...version() $need_content argument in WikiDB also:
285 // To reduce the memory footprint for larger sets of pagelists,
286 // we don't cache the content (only true or false) and
287 // we purge the pagedata (_cached_html) also.
288 // _cached_html is only cached for the current pagename.
289 // => Vastly improved page existance check, ACL check, ...
291 // Now only PagedList info=content or size needs the whole content, esp. if sortable.
293 // Revision 1.18 2004/06/16 10:38:59 rurban
294 // Disallow refernces in calls if the declaration is a reference
295 // ("allow_call_time_pass_reference clean").
296 // PhpWiki is now allow_call_time_pass_reference = Off clean,
297 // but several external libraries may not.
298 // In detail these libs look to be affected (not tested):
302 // Revision 1.17 2004/06/14 11:31:39 rurban
303 // renamed global $Theme to $WikiTheme (gforge nameclash)
304 // inherit PageList default options from PageList
305 // default sortby=pagename
306 // use options in PageList_Selectable (limit, sortby, ...)
307 // added action revert, with button at action=diff
308 // added option regex to WikiAdminSearchReplace
310 // Revision 1.16 2004/06/13 15:33:20 rurban
311 // new support for arguments owner, author, creator in most relevant
312 // PageList plugins. in WikiAdmin* via preSelectS()
314 // Revision 1.15 2004/06/01 15:28:01 rurban
315 // AdminUser only ADMIN_USER not member of Administrators
316 // some RateIt improvements by dfrankow
317 // edit_toolbar buttons
319 // Revision 1.14 2004/02/24 15:20:07 rurban
320 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
322 // Revision 1.13 2004/02/22 23:20:33 rurban
323 // fixed DumpHtmlToDir,
324 // enhanced sortby handling in PageList
325 // new button_heading th style (enabled),
326 // added sortby and limit support to the db backends and plugins
327 // for paging support (<<prev, next>> links on long lists)
329 // Revision 1.12 2004/02/19 22:05:57 rurban
330 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
332 // Revision 1.11 2004/02/17 12:11:36 rurban
333 // 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, ...)
335 // Revision 1.10 2004/02/15 21:34:37 rurban
336 // PageList enhanced and improved.
337 // fixed new WikiAdmin... plugins
338 // editpage, Theme with exp. htmlarea framework
339 // (htmlarea yet committed, this is really questionable)
340 // WikiUser... code with better session handling for prefs
341 // enhanced UserPreferences (again)
342 // RecentChanges for show_deleted: how should pages be deleted then?
344 // Revision 1.9 2004/02/12 13:05:50 rurban
345 // Rename functional for PearDB backend
346 // some other minor changes
347 // SiteMap comes with a not yet functional feature request: includepages (tbd)
349 // Revision 1.8 2004/02/11 20:00:16 rurban
350 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
352 // Revision 1.7 2004/01/27 23:23:39 rurban
353 // renamed ->Username => _userid for consistency
354 // renamed mayCheckPassword => mayCheckPass
355 // fixed recursion problem in WikiUserNew
356 // fixed bogo login (but not quite 100% ready yet, password storage)
358 // Revision 1.6 2004/01/26 19:15:29 rurban
361 // Revision 1.5 2003/02/24 19:38:04 dairiki
362 // Get rid of unused method Request::debugVars().
364 // Revision 1.4 2003/02/24 01:36:27 dairiki
365 // Don't use PHPWIKI_DIR unless it's defined.
366 // (Also typo/bugfix in SystemInfo plugin.)
368 // Revision 1.3 2003/02/22 20:49:56 dairiki
369 // Fixes for "Call-time pass by reference has been deprecated" errors.
371 // Revision 1.2 2003/01/18 22:14:29 carstenklapp
373 // Reformatting & tabs to spaces;
374 // Added copyleft, getVersion, getDescription, rcs_id.
381 // c-hanging-comment-ender-p: nil
382 // indent-tabs-mode: nil