2 rcs_id('$Id: WikiAdminSelect.php,v 1.12 2004-02-19 22:05:57 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.12 $");
53 function getDefaultArguments() {
54 return array('s' => '', // preselect pages
58 'sortby' => 'pagename',
62 function collectPages(&$list, &$dbi, $sortby) {
63 $allPages = $dbi->getAllPages(0,$sortby);
64 while ($pagehandle = $allPages->next()) {
65 $pagename = $pagehandle->getName();
66 if (empty($list[$pagename]))
72 function run($dbi, $argstr, &$request, $basepage) {
73 //if ($request->getArg('action') != 'browse')
74 // return $this->disabled("(action != 'browse')");
75 $args = $this->getArgs($argstr, $request);
76 if (!empty($args['only']))
77 $only = explodePageList($args['only']);
80 if (!empty($args['exclude']))
81 $exclude = explodePageList($args['exclude']);
84 $info = $args['info'];
85 $this->debug = $args['debug'];
86 if (!empty($request->getArg['s']))
87 $args['s'] = $request->getArg['s'];
88 if ( //( $request->getArg('WikiAdminSelect') == _("Go")) and
91 $sl = explodePageList($args['s']);
92 $this->_list = array();
94 $request->setArg('verify',1);
95 foreach ($sl as $name) {
96 $this->_list[$name] = 1;
101 if (!empty($args['s']))
103 $this->_list = array();
106 // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
107 $pagename = $request->getArg('pagename');
108 // GetUrlToSelf() with all given params
109 //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
110 //$uri = $request->getURLtoSelf();//false, array('verify'));
111 $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
112 if ($request->getArg('WikiAdminSelect') == _("Go"))
115 $p = $request->getArg('p');
116 //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
117 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
118 HTML::input(array('type' => 'text',
121 HTML::input(array('type' => 'submit',
122 'name' => 'WikiAdminSelect',
123 'value' => _("Go")))));
124 if ($request->isPost()
125 && ! $request->getArg('wikiadmin')
127 $this->_list = array();
128 // List all selected pages again.
129 foreach ($p as $page => $name) {
130 $this->_list[$name] = 1;
133 elseif ($request->isPost()
134 and $request->_user->isAdmin()
136 //and $request->getArg('verify')
137 and ($request->getArg('action') == 'WikiAdminSelect')
138 and $request->getArg('wikiadmin')
141 // handle external plugin
142 $loader = new WikiPluginLoader();
143 $a = array_keys($request->getArg('wikiadmin'));
144 $plugin_action = $a[0];
145 $single_arg_plugins = array("Remove");
146 if (in_array($plugin_action,$single_arg_plugins)) {
147 $plugin = $loader->getPlugin($plugin_action);
149 foreach ($p as $page => $name) {
150 $plugin_args = "run_page=$name";
151 $request->setArg($plugin_action, 1);
152 $request->setArg('p', array($page => $name));
153 // if the plugin requires more args than the pagename,
154 // then this plugin will not return. (Rename, SearchReplace, ...)
155 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
156 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
158 $ul->pushContent(HTML::ul(HTML::li($action_result)));
161 // redirect to the plugin page.
162 // in which page is this plugin?
163 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
165 foreach ($p as $page => $x) {
166 $args["p[$page]"] = 1;
169 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
172 } elseif (empty($args['s'])) {
173 // List all pages to select from.
174 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby']);
176 $pagelist = new PageList_Selectable($info, $exclude);
177 $pagelist->addPageList($this->_list);
178 $form->pushContent($pagelist->getContent());
179 foreach ($args as $k => $v) {
180 if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
181 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
184 foreach ($_GET as $k => $v) {
185 if (!in_array($k,array('s','WikiAdminSelect','action')))
186 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
189 if (! $request->getArg('verify')) {
190 $form->pushContent(HTML::input(array('type' => 'hidden',
192 'value' => 'verify')));
193 $form->pushContent(Button('submit:verify', _("Select pages"),
195 Button('submit:cancel', _("Cancel"), 'button'));
198 $form->pushContent(HTML::input(array('type' => 'hidden',
200 'value' => 'WikiAdminSelect'))
202 // Add the Buttons for all registered WikiAdmin plugins
203 $plugin_dir = 'lib/plugin';
204 if (defined('PHPWIKI_DIR'))
205 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
206 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
207 $actions = $fs->getFiles();
208 foreach ($actions as $f) {
209 $f = preg_replace('/.php$/','', $f);
210 $s = preg_replace('/^WikiAdmin/','', $f);
211 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
212 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
213 $form->pushContent($Theme->getButtonSeparator());
216 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
218 if (! $request->getArg('select')) {
221 ; //return $action_result;
226 // $Log: not supported by cvs2svn $
227 // Revision 1.11 2004/02/17 12:11:36 rurban
228 // 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, ...)
230 // Revision 1.10 2004/02/15 21:34:37 rurban
231 // PageList enhanced and improved.
232 // fixed new WikiAdmin... plugins
233 // editpage, Theme with exp. htmlarea framework
234 // (htmlarea yet committed, this is really questionable)
235 // WikiUser... code with better session handling for prefs
236 // enhanced UserPreferences (again)
237 // RecentChanges for show_deleted: how should pages be deleted then?
239 // Revision 1.9 2004/02/12 13:05:50 rurban
240 // Rename functional for PearDB backend
241 // some other minor changes
242 // SiteMap comes with a not yet functional feature request: includepages (tbd)
244 // Revision 1.8 2004/02/11 20:00:16 rurban
245 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
247 // Revision 1.7 2004/01/27 23:23:39 rurban
248 // renamed ->Username => _userid for consistency
249 // renamed mayCheckPassword => mayCheckPass
250 // fixed recursion problem in WikiUserNew
251 // fixed bogo login (but not quite 100% ready yet, password storage)
253 // Revision 1.6 2004/01/26 19:15:29 rurban
256 // Revision 1.5 2003/02/24 19:38:04 dairiki
257 // Get rid of unused method Request::debugVars().
259 // Revision 1.4 2003/02/24 01:36:27 dairiki
260 // Don't use PHPWIKI_DIR unless it's defined.
261 // (Also typo/bugfix in SystemInfo plugin.)
263 // Revision 1.3 2003/02/22 20:49:56 dairiki
264 // Fixes for "Call-time pass by reference has been deprecated" errors.
266 // Revision 1.2 2003/01/18 22:14:29 carstenklapp
268 // Reformatting & tabs to spaces;
269 // Added copyleft, getVersion, getDescription, rcs_id.
276 // c-hanging-comment-ender-p: nil
277 // indent-tabs-mode: nil