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 along
20 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Allows selection of multiple pages which get passed to other
26 * WikiAdmin plugins then. Then do Rename, Remove, Chmod, Chown, ...
28 * Usage: <<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
42 return _("WikiAdminSelect");
45 function getDescription()
47 return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
50 function getDefaultArguments()
52 return array('s' => '', // preselect pages
53 /* select pages by meta-data: */
60 'sortby' => 'pagename',
67 * Default collector for all WikiAdmin* plugins.
68 * preSelectS() is similar, but fills $this->_list
70 function collectPages(&$list, &$dbi, $sortby, $limit = 0, $exclude = '')
72 $allPages = $dbi->getAllPages(0, $sortby, $limit, $exclude);
73 while ($pagehandle = $allPages->next()) {
74 $pagename = $pagehandle->getName();
75 if (empty($list[$pagename]))
82 * Preselect a list of pagenames by the supporting the following args:
83 * 's': comma-separated list of pagename wildcards
84 * 'author', 'owner', 'creator': from WikiDB_Page
85 * 'only: forgot what the difference to 's' was.
86 * Sets $this->_list, which is picked up by collectPages() and is a default for p[]
88 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']); elseif (!empty($args['creator']))
98 $sl = PageList::allPagesByCreator($args['creator'], false, $args['sortby'], $args['limit'], $args['exclude']); elseif (!empty($args['s']) or !empty($args['only'])) {
100 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
102 $this->_list = array();
104 $request->setArg('verify', 1);
105 foreach ($sl as $name) {
106 if (!empty($args['exclude'])) {
107 if (!in_array($name, $args['exclude']))
108 $this->_list[$name] = 1;
110 $this->_list[$name] = 1;
117 function run($dbi, $argstr, &$request, $basepage)
119 //if ($request->getArg('action') != 'browse')
120 // return $this->disabled("(action != 'browse')");
121 $args = $this->getArgs($argstr, $request);
122 $this->_args = $args;
124 $this->preSelectS($args, $request);
126 $info = $args['info'];
128 $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'));
129 if ($request->getArg('WikiAdminSelect') == _("Go"))
132 $p = $request->getArg('p');
133 //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
134 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
135 HTML::input(array('type' => 'text',
137 'value' => $args['s'])),
138 HTML::input(array('type' => 'submit',
139 'name' => 'WikiAdminSelect',
140 'value' => _("Go")))));
141 if (!$request->getArg('verify')) {
142 $form->pushContent(HTML::input(array('type' => 'hidden',
144 'value' => 'verify')));
145 $form->pushContent(Button('submit:verify', _("Select pages"),
147 Button('submit:cancel', _("Cancel"), 'button'));
150 $form->pushContent(HTML::input(array('type' => 'hidden',
152 'value' => 'WikiAdminSelect'))
154 // Add the Buttons for all registered WikiAdmin plugins
155 $plugin_dir = 'lib/plugin';
156 if (defined('PHPWIKI_DIR'))
157 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
158 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
159 $actions = $fs->getFiles();
161 foreach ($actions as $f) {
162 $f = preg_replace('/.php$/', '', $f);
163 $s = preg_replace('/^WikiAdmin/', '', $f);
164 if (!in_array($s, array("Select", "Utils"))) { // disable Select and Utils
165 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
166 $form->pushContent($WikiTheme->getButtonSeparator());
169 // $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
172 if ($request->isPost()
173 && !$request->getArg('wikiadmin')
176 $this->_list = array();
177 // List all selected pages again.
178 foreach ($p as $page => $name) {
179 $this->_list[$name] = 1;
181 } elseif ($request->isPost()
182 and $request->_user->isAdmin()
184 //and $request->getArg('verify')
185 and ($request->getArg('action') == 'WikiAdminSelect')
186 and $request->getArg('wikiadmin')
188 // handle external plugin
189 $loader = new WikiPluginLoader();
190 $a = array_keys($request->getArg('wikiadmin'));
191 $plugin_action = $a[0];
192 $single_arg_plugins = array("Remove");
193 if (in_array($plugin_action, $single_arg_plugins)) {
194 $plugin = $loader->getPlugin($plugin_action);
196 foreach ($p as $page => $name) {
197 $plugin_args = "run_page=$name";
198 $request->setArg($plugin_action, 1);
199 $request->setArg('p', array($page => $name));
200 // if the plugin requires more args than the pagename,
201 // then this plugin will not return. (Rename, SearchReplace, ...)
202 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
203 $ul->pushContent(HTML::li(fmt("Selected page ā%sā passed to ā%sā.",
205 $ul->pushContent(HTML::ul(HTML::li($action_result)));
208 // redirect to the plugin page.
209 // in which page is this plugin?
210 $plugin_action = preg_replace("/^WikiAdmin/", "", $plugin_action);
212 foreach ($p as $page => $x) {
213 $args["p[$page]"] = 1;
215 header("Location: " .
216 WikiURL(_("PhpWikiAdministration") . "/" . _($plugin_action), $args, 1));
219 } elseif (empty($args['s'])) {
220 // List all pages to select from.
221 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
223 $pagelist = new PageList_Selectable($info, $args['exclude'], $args);
224 $pagelist->addPageList($this->_list);
225 $form->pushContent($pagelist->getContent());
226 foreach ($args as $k => $v) {
227 if (!in_array($k, array('s', 'WikiAdminSelect', 'action', 'verify')))
228 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
230 if (!$request->getArg('select')) {
233 ; //return $action_result;
237 private function _tablePush(&$table, $first, $second)
251 // c-hanging-comment-ender-p: nil
252 // indent-tabs-mode: nil