4 * Copyright 2002 $ThePhpWikiProgrammingTeam
5 * Copyright 2008-2009 Marc-Etienne Vargenau, Alcatel-Lucent
7 * This file is part of PhpWiki.
9 * PhpWiki is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * PhpWiki is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with PhpWiki; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Allows selection of multiple pages which get passed to other
26 * WikiAdmin plugins then. Then do Rename, Remove, Chmod, Chown, ...
28 * Usage: <?plugin WikiAdminSelect?>
29 * Author: Reini Urban <rurban@x-ray.at>
31 * This is the base class for most WikiAdmin* classes, using
32 * collectPages() and preSelectS().
33 * "list" PagePermissions supported implicitly by PageList.
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: $]/", '',
53 function getDefaultArguments() {
54 return array('s' => '', // preselect pages
55 /* select pages by meta-data: */
62 'sortby' => 'pagename',
69 * Default collector for all WikiAdmin* plugins.
70 * preSelectS() is similar, but fills $this->_list
72 function collectPages(&$list, &$dbi, $sortby, $limit=0, $exclude='') {
73 $allPages = $dbi->getAllPages(0, $sortby, $limit, $exclude);
74 while ($pagehandle = $allPages->next()) {
75 $pagename = $pagehandle->getName();
76 if (empty($list[$pagename]))
83 * Preselect a list of pagenames by the supporting the following args:
84 * 's': comma-seperated list of pagename wildcards
85 * 'author', 'owner', 'creator': from WikiDB_Page
86 * 'only: forgot what the difference to 's' was.
87 * Sets $this->_list, which is picked up by collectPages() and is a default for p[]
89 function preSelectS (&$args, &$request) {
90 // override plugin argument by GET: probably not needed if s||="" is used
91 // anyway, we force it for unique interface.
92 if (!empty($request->getArg['s']))
93 $args['s'] = $request->getArg['s'];
94 if ( !empty($args['owner']) )
95 $sl = PageList::allPagesByOwner($args['owner'],false,$args['sortby'],$args['limit'],$args['exclude']);
96 elseif ( !empty($args['author']) )
97 $sl = PageList::allPagesByAuthor($args['author'],false,$args['sortby'],$args['limit'],$args['exclude']);
98 elseif ( !empty($args['creator']) )
99 $sl = PageList::allPagesByCreator($args['creator'],false,$args['sortby'],$args['limit'],$args['exclude']);
100 elseif ( !empty($args['s']) or !empty($args['only']) ) {
102 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
104 $this->_list = array();
106 $request->setArg('verify', 1);
107 foreach ($sl as $name) {
108 if (!empty($args['exclude'])) {
109 if (!in_array($name, $args['exclude']))
110 $this->_list[$name] = 1;
112 $this->_list[$name] = 1;
119 function run($dbi, $argstr, &$request, $basepage) {
120 //if ($request->getArg('action') != 'browse')
121 // return $this->disabled("(action != 'browse')");
122 $args = $this->getArgs($argstr, $request);
123 $this->_args = $args;
125 $this->preSelectS($args, $request);
127 $info = $args['info'];
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',
143 'value' => $args['s'])),
144 HTML::input(array('type' => 'submit',
145 'name' => 'WikiAdminSelect',
146 'value' => _("Go")))));
147 if (! $request->getArg('verify')) {
148 $form->pushContent(HTML::input(array('type' => 'hidden',
150 'value' => 'verify')));
151 $form->pushContent(Button('submit:verify', _("Select pages"),
153 Button('submit:cancel', _("Cancel"), 'button'));
156 $form->pushContent(HTML::input(array('type' => 'hidden',
158 'value' => 'WikiAdminSelect'))
160 // Add the Buttons for all registered WikiAdmin plugins
161 $plugin_dir = 'lib/plugin';
162 if (defined('PHPWIKI_DIR'))
163 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
164 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
165 $actions = $fs->getFiles();
167 foreach ($actions as $f) {
168 $f = preg_replace('/.php$/','', $f);
169 $s = preg_replace('/^WikiAdmin/','', $f);
170 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
171 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
172 $form->pushContent($WikiTheme->getButtonSeparator());
175 // $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
178 if ($request->isPost()
179 && ! $request->getArg('wikiadmin')
181 $this->_list = array();
182 // List all selected pages again.
183 foreach ($p as $page => $name) {
184 $this->_list[$name] = 1;
187 elseif ($request->isPost()
188 and $request->_user->isAdmin()
190 //and $request->getArg('verify')
191 and ($request->getArg('action') == 'WikiAdminSelect')
192 and $request->getArg('wikiadmin')
195 // handle external plugin
196 $loader = new WikiPluginLoader();
197 $a = array_keys($request->getArg('wikiadmin'));
198 $plugin_action = $a[0];
199 $single_arg_plugins = array("Remove");
200 if (in_array($plugin_action, $single_arg_plugins)) {
201 $plugin = $loader->getPlugin($plugin_action);
203 foreach ($p as $page => $name) {
204 $plugin_args = "run_page=$name";
205 $request->setArg($plugin_action, 1);
206 $request->setArg('p', array($page => $name));
207 // if the plugin requires more args than the pagename,
208 // then this plugin will not return. (Rename, SearchReplace, ...)
209 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
210 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
212 $ul->pushContent(HTML::ul(HTML::li($action_result)));
215 // redirect to the plugin page.
216 // in which page is this plugin?
217 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
219 foreach ($p as $page => $x) {
220 $args["p[$page]"] = 1;
223 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
226 } elseif (empty($args['s'])) {
227 // List all pages to select from.
228 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
230 $pagelist = new PageList_Selectable($info, $args['exclude'], $args);
231 $pagelist->addPageList($this->_list);
232 $form->pushContent($pagelist->getContent());
233 foreach ($args as $k => $v) {
234 if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
235 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
237 if (! $request->getArg('select')) {
240 ; //return $action_result;
244 function _tablePush(&$table, $first, $second) {
257 // c-hanging-comment-ender-p: nil
258 // indent-tabs-mode: nil