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