2 rcs_id('$Id: WikiAdminSelect.php,v 1.16 2004-06-13 15:33:20 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 * "list" PagePermissions supported implicitly by PageList.
31 * Just a framework, nothing more.
33 // maybe display more attributes with this class...
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.16 $");
52 function getDefaultArguments() {
53 return array('s' => '', // preselect pages
54 /* select pages by meta-data: */
62 'sortby' => 'pagename',
67 function collectPages(&$list, &$dbi, $sortby, $limit=0) {
68 $allPages = $dbi->getAllPages(0,$sortby,$limit);
69 while ($pagehandle = $allPages->next()) {
70 $pagename = $pagehandle->getName();
71 if (empty($list[$pagename]))
78 * Preselect a list of pagenames by:
79 * s: comma-seperated list of pagename wildcards
80 * author, owner, creator
82 function preSelectS (&$args, &$request) {
83 // override plugin argument by GET: probably not needed if s||="" is used
84 // anyway, we force it for unique interface.
85 if (!empty($request->getArg['s']))
86 $args['s'] = $request->getArg['s'];
87 if ( !empty($args['owner']) )
88 $sl = PageList::allPagesByOwner($args['owner'],false,$args['sortby'],$args['limit']);
89 elseif ( !empty($args['author']) )
90 $sl = PageList::allPagesByAuthor($args['author'],false,$args['sortby'],$args['limit']);
91 elseif ( !empty($args['creator']) )
92 $sl = PageList::allPagesByCreator($args['creator'],false,$args['sortby'],$args['limit']);
93 elseif ( !empty($args['s']) or !empty($args['only']) ) {
95 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
97 $this->_list = array();
99 $request->setArg('verify', 1);
100 if (!empty($args['exclude']))
101 $exclude = explodePageList($args['exclude']);
102 foreach ($sl as $name) {
103 if (!empty($args['exclude'])) {
104 if (!in_array($name, $exclude))
105 $this->_list[$name] = 1;
107 $this->_list[$name] = 1;
114 function run($dbi, $argstr, &$request, $basepage) {
115 //if ($request->getArg('action') != 'browse')
116 // return $this->disabled("(action != 'browse')");
117 $args = $this->getArgs($argstr, $request);
118 $this->_args = $args;
119 $this->preSelectS(&$args, &$request);
121 $info = $args['info'];
122 $this->debug = $args['debug'];
124 // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
125 $pagename = $request->getArg('pagename');
126 // GetUrlToSelf() with all given params
127 //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
128 //$uri = $request->getURLtoSelf();//false, array('verify'));
129 $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
130 if ($request->getArg('WikiAdminSelect') == _("Go"))
133 $p = $request->getArg('p');
134 //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
135 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
136 HTML::input(array('type' => 'text',
139 HTML::input(array('type' => 'submit',
140 'name' => 'WikiAdminSelect',
141 'value' => _("Go")))));
142 if ($request->isPost()
143 && ! $request->getArg('wikiadmin')
145 $this->_list = array();
146 // List all selected pages again.
147 foreach ($p as $page => $name) {
148 $this->_list[$name] = 1;
151 elseif ($request->isPost()
152 and $request->_user->isAdmin()
154 //and $request->getArg('verify')
155 and ($request->getArg('action') == 'WikiAdminSelect')
156 and $request->getArg('wikiadmin')
159 // handle external plugin
160 $loader = new WikiPluginLoader();
161 $a = array_keys($request->getArg('wikiadmin'));
162 $plugin_action = $a[0];
163 $single_arg_plugins = array("Remove");
164 if (in_array($plugin_action,$single_arg_plugins)) {
165 $plugin = $loader->getPlugin($plugin_action);
167 foreach ($p as $page => $name) {
168 $plugin_args = "run_page=$name";
169 $request->setArg($plugin_action, 1);
170 $request->setArg('p', array($page => $name));
171 // if the plugin requires more args than the pagename,
172 // then this plugin will not return. (Rename, SearchReplace, ...)
173 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
174 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
176 $ul->pushContent(HTML::ul(HTML::li($action_result)));
179 // redirect to the plugin page.
180 // in which page is this plugin?
181 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
183 foreach ($p as $page => $x) {
184 $args["p[$page]"] = 1;
187 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
190 } elseif (empty($args['s'])) {
191 // List all pages to select from.
192 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
194 $pagelist = new PageList_Selectable($info, $exclude);
195 $pagelist->addPageList($this->_list);
196 $form->pushContent($pagelist->getContent());
197 foreach ($args as $k => $v) {
198 if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
199 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
202 foreach ($_GET as $k => $v) {
203 if (!in_array($k,array('s','WikiAdminSelect','action')))
204 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
207 if (! $request->getArg('verify')) {
208 $form->pushContent(HTML::input(array('type' => 'hidden',
210 'value' => 'verify')));
211 $form->pushContent(Button('submit:verify', _("Select pages"),
213 Button('submit:cancel', _("Cancel"), 'button'));
216 $form->pushContent(HTML::input(array('type' => 'hidden',
218 'value' => 'WikiAdminSelect'))
220 // Add the Buttons for all registered WikiAdmin plugins
221 $plugin_dir = 'lib/plugin';
222 if (defined('PHPWIKI_DIR'))
223 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
224 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
225 $actions = $fs->getFiles();
226 foreach ($actions as $f) {
227 $f = preg_replace('/.php$/','', $f);
228 $s = preg_replace('/^WikiAdmin/','', $f);
229 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
230 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
231 $form->pushContent($Theme->getButtonSeparator());
234 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
236 if (! $request->getArg('select')) {
239 ; //return $action_result;
244 // $Log: not supported by cvs2svn $
245 // Revision 1.15 2004/06/01 15:28:01 rurban
246 // AdminUser only ADMIN_USER not member of Administrators
247 // some RateIt improvements by dfrankow
248 // edit_toolbar buttons
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