2 rcs_id('$Id: WikiAdminSelect.php,v 1.18 2004-06-16 10:38:59 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.18 $");
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) {
72 $allPages = $dbi->getAllPages(0,$sortby,$limit);
73 while ($pagehandle = $allPages->next()) {
74 $pagename = $pagehandle->getName();
75 if (empty($list[$pagename]))
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[]
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']) ) {
101 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
103 $this->_list = array();
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;
113 $this->_list[$name] = 1;
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 $this->preSelectS($args, $request);
127 $info = $args['info'];
128 $this->debug = $args['debug'];
130 // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
131 $pagename = $request->getArg('pagename');
132 // GetUrlToSelf() with all given params
133 //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
134 //$uri = $request->getURLtoSelf();//false, array('verify'));
135 $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
136 if ($request->getArg('WikiAdminSelect') == _("Go"))
139 $p = $request->getArg('p');
140 //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
141 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
142 HTML::input(array('type' => 'text',
145 HTML::input(array('type' => 'submit',
146 'name' => 'WikiAdminSelect',
147 'value' => _("Go")))));
148 if ($request->isPost()
149 && ! $request->getArg('wikiadmin')
151 $this->_list = array();
152 // List all selected pages again.
153 foreach ($p as $page => $name) {
154 $this->_list[$name] = 1;
157 elseif ($request->isPost()
158 and $request->_user->isAdmin()
160 //and $request->getArg('verify')
161 and ($request->getArg('action') == 'WikiAdminSelect')
162 and $request->getArg('wikiadmin')
165 // handle external plugin
166 $loader = new WikiPluginLoader();
167 $a = array_keys($request->getArg('wikiadmin'));
168 $plugin_action = $a[0];
169 $single_arg_plugins = array("Remove");
170 if (in_array($plugin_action,$single_arg_plugins)) {
171 $plugin = $loader->getPlugin($plugin_action);
173 foreach ($p as $page => $name) {
174 $plugin_args = "run_page=$name";
175 $request->setArg($plugin_action, 1);
176 $request->setArg('p', array($page => $name));
177 // if the plugin requires more args than the pagename,
178 // then this plugin will not return. (Rename, SearchReplace, ...)
179 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
180 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
182 $ul->pushContent(HTML::ul(HTML::li($action_result)));
185 // redirect to the plugin page.
186 // in which page is this plugin?
187 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
189 foreach ($p as $page => $x) {
190 $args["p[$page]"] = 1;
193 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
196 } elseif (empty($args['s'])) {
197 // List all pages to select from.
198 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
200 $pagelist = new PageList_Selectable($info, $exclude);
201 $pagelist->addPageList($this->_list);
202 $form->pushContent($pagelist->getContent());
203 foreach ($args as $k => $v) {
204 if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
205 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
208 foreach ($_GET as $k => $v) {
209 if (!in_array($k,array('s','WikiAdminSelect','action')))
210 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
213 if (! $request->getArg('verify')) {
214 $form->pushContent(HTML::input(array('type' => 'hidden',
216 'value' => 'verify')));
217 $form->pushContent(Button('submit:verify', _("Select pages"),
219 Button('submit:cancel', _("Cancel"), 'button'));
222 $form->pushContent(HTML::input(array('type' => 'hidden',
224 'value' => 'WikiAdminSelect'))
226 // Add the Buttons for all registered WikiAdmin plugins
227 $plugin_dir = 'lib/plugin';
228 if (defined('PHPWIKI_DIR'))
229 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
230 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
231 $actions = $fs->getFiles();
232 foreach ($actions as $f) {
233 $f = preg_replace('/.php$/','', $f);
234 $s = preg_replace('/^WikiAdmin/','', $f);
235 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
236 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
237 $form->pushContent($WikiTheme->getButtonSeparator());
240 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
242 if (! $request->getArg('select')) {
245 ; //return $action_result;
250 // $Log: not supported by cvs2svn $
251 // Revision 1.17 2004/06/14 11:31:39 rurban
252 // renamed global $Theme to $WikiTheme (gforge nameclash)
253 // inherit PageList default options from PageList
254 // default sortby=pagename
255 // use options in PageList_Selectable (limit, sortby, ...)
256 // added action revert, with button at action=diff
257 // added option regex to WikiAdminSearchReplace
259 // Revision 1.16 2004/06/13 15:33:20 rurban
260 // new support for arguments owner, author, creator in most relevant
261 // PageList plugins. in WikiAdmin* via preSelectS()
263 // Revision 1.15 2004/06/01 15:28:01 rurban
264 // AdminUser only ADMIN_USER not member of Administrators
265 // some RateIt improvements by dfrankow
266 // edit_toolbar buttons
268 // Revision 1.14 2004/02/24 15:20:07 rurban
269 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
271 // Revision 1.13 2004/02/22 23:20:33 rurban
272 // fixed DumpHtmlToDir,
273 // enhanced sortby handling in PageList
274 // new button_heading th style (enabled),
275 // added sortby and limit support to the db backends and plugins
276 // for paging support (<<prev, next>> links on long lists)
278 // Revision 1.12 2004/02/19 22:05:57 rurban
279 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
281 // Revision 1.11 2004/02/17 12:11:36 rurban
282 // 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, ...)
284 // Revision 1.10 2004/02/15 21:34:37 rurban
285 // PageList enhanced and improved.
286 // fixed new WikiAdmin... plugins
287 // editpage, Theme with exp. htmlarea framework
288 // (htmlarea yet committed, this is really questionable)
289 // WikiUser... code with better session handling for prefs
290 // enhanced UserPreferences (again)
291 // RecentChanges for show_deleted: how should pages be deleted then?
293 // Revision 1.9 2004/02/12 13:05:50 rurban
294 // Rename functional for PearDB backend
295 // some other minor changes
296 // SiteMap comes with a not yet functional feature request: includepages (tbd)
298 // Revision 1.8 2004/02/11 20:00:16 rurban
299 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
301 // Revision 1.7 2004/01/27 23:23:39 rurban
302 // renamed ->Username => _userid for consistency
303 // renamed mayCheckPassword => mayCheckPass
304 // fixed recursion problem in WikiUserNew
305 // fixed bogo login (but not quite 100% ready yet, password storage)
307 // Revision 1.6 2004/01/26 19:15:29 rurban
310 // Revision 1.5 2003/02/24 19:38:04 dairiki
311 // Get rid of unused method Request::debugVars().
313 // Revision 1.4 2003/02/24 01:36:27 dairiki
314 // Don't use PHPWIKI_DIR unless it's defined.
315 // (Also typo/bugfix in SystemInfo plugin.)
317 // Revision 1.3 2003/02/22 20:49:56 dairiki
318 // Fixes for "Call-time pass by reference has been deprecated" errors.
320 // Revision 1.2 2003/01/18 22:14:29 carstenklapp
322 // Reformatting & tabs to spaces;
323 // Added copyleft, getVersion, getDescription, rcs_id.
330 // c-hanging-comment-ender-p: nil
331 // indent-tabs-mode: nil