2 rcs_id('$Id: WikiAdminSelect.php,v 1.15 2004-06-01 15:28:01 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>
31 * Just a framework, nothing more.
32 * Future versions will support PagePermissions.
34 // maybe display more attributes with this class...
35 require_once('lib/PageList.php');
37 class WikiPlugin_WikiAdminSelect
41 return _("WikiAdminSelect");
44 function getDescription() {
45 return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
48 function getVersion() {
49 return preg_replace("/[Revision: $]/", '',
50 "\$Revision: 1.15 $");
53 function getDefaultArguments() {
54 return array('s' => '', // preselect pages
58 'sortby' => 'pagename',
63 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
64 $allPages = $dbi->getAllPages(0,$sortby,$limit);
65 while ($pagehandle = $allPages->next()) {
66 $pagename = $pagehandle->getName();
67 if (empty($list[$pagename]))
73 function preSelectS (&$args, &$request) {
74 if (!empty($request->getArg['s']))
75 $args['s'] = $request->getArg['s'];
76 if ( !empty($args['s']) ) {
78 $sl = explodePageList($args['s']);
79 $this->_list = array();
81 $request->setArg('verify', 1);
82 foreach ($sl as $name) {
83 $this->_list[$name] = 1;
88 if (!empty($args['s']))
90 $this->_list = array();
94 function run($dbi, $argstr, &$request, $basepage) {
95 //if ($request->getArg('action') != 'browse')
96 // return $this->disabled("(action != 'browse')");
97 $args = $this->getArgs($argstr, $request);
98 if (!empty($args['only']))
99 $only = explodePageList($args['only']);
102 if (!empty($args['exclude']))
103 $exclude = explodePageList($args['exclude']);
106 $info = $args['info'];
107 $this->debug = $args['debug'];
108 //TODO: use the method preSelectS()
109 if (!empty($request->getArg['s']))
110 $args['s'] = $request->getArg['s'];
111 if ( //( $request->getArg('WikiAdminSelect') == _("Go")) and
112 !empty($args['s'])) {
114 $sl = explodePageList($args['s']);
115 $this->_list = array();
117 $request->setArg('verify',1);
118 foreach ($sl as $name) {
119 $this->_list[$name] = 1;
124 if (!empty($args['s']))
126 $this->_list = array();
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',
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, $exclude);
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($Theme->getButtonSeparator());
239 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
241 if (! $request->getArg('select')) {
244 ; //return $action_result;
249 // $Log: not supported by cvs2svn $
250 // Revision 1.14 2004/02/24 15:20:07 rurban
251 // fixed minor warnings: unchecked args, POST => Get urls for sortby e.g.
253 // Revision 1.13 2004/02/22 23:20:33 rurban
254 // fixed DumpHtmlToDir,
255 // enhanced sortby handling in PageList
256 // new button_heading th style (enabled),
257 // added sortby and limit support to the db backends and plugins
258 // for paging support (<<prev, next>> links on long lists)
260 // Revision 1.12 2004/02/19 22:05:57 rurban
261 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
263 // Revision 1.11 2004/02/17 12:11:36 rurban
264 // 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, ...)
266 // Revision 1.10 2004/02/15 21:34:37 rurban
267 // PageList enhanced and improved.
268 // fixed new WikiAdmin... plugins
269 // editpage, Theme with exp. htmlarea framework
270 // (htmlarea yet committed, this is really questionable)
271 // WikiUser... code with better session handling for prefs
272 // enhanced UserPreferences (again)
273 // RecentChanges for show_deleted: how should pages be deleted then?
275 // Revision 1.9 2004/02/12 13:05:50 rurban
276 // Rename functional for PearDB backend
277 // some other minor changes
278 // SiteMap comes with a not yet functional feature request: includepages (tbd)
280 // Revision 1.8 2004/02/11 20:00:16 rurban
281 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
283 // Revision 1.7 2004/01/27 23:23:39 rurban
284 // renamed ->Username => _userid for consistency
285 // renamed mayCheckPassword => mayCheckPass
286 // fixed recursion problem in WikiUserNew
287 // fixed bogo login (but not quite 100% ready yet, password storage)
289 // Revision 1.6 2004/01/26 19:15:29 rurban
292 // Revision 1.5 2003/02/24 19:38:04 dairiki
293 // Get rid of unused method Request::debugVars().
295 // Revision 1.4 2003/02/24 01:36:27 dairiki
296 // Don't use PHPWIKI_DIR unless it's defined.
297 // (Also typo/bugfix in SystemInfo plugin.)
299 // Revision 1.3 2003/02/22 20:49:56 dairiki
300 // Fixes for "Call-time pass by reference has been deprecated" errors.
302 // Revision 1.2 2003/01/18 22:14:29 carstenklapp
304 // Reformatting & tabs to spaces;
305 // Added copyleft, getVersion, getDescription, rcs_id.
312 // c-hanging-comment-ender-p: nil
313 // indent-tabs-mode: nil