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, 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
43 function getDescription()
45 return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
48 function getDefaultArguments()
50 return array('s' => '', // preselect pages
51 /* select pages by meta-data: */
58 'sortby' => 'pagename',
65 * Default collector for all WikiAdmin* plugins.
66 * preSelectS() is similar, but fills $this->_list
70 * @param string $sortby
72 * @param string $exclude
75 protected function collectPages(&$list, &$dbi, $sortby, $limit = 0, $exclude = '')
77 $allPages = $dbi->getAllPages(0, $sortby, $limit, $exclude);
78 while ($pagehandle = $allPages->next()) {
79 $pagename = $pagehandle->getName();
80 if (empty($list[$pagename]))
87 * Preselect a list of pagenames by the supporting the following args:
88 * 's': comma-separated list of pagename wildcards
89 * 'author', 'owner', 'creator': from WikiDB_Page
90 * 'only: forgot what the difference to 's' was.
91 * Sets $this->_list, which is picked up by collectPages() and is a default for p[]
94 * @param WikiRequest $request
97 protected function preSelectS(&$args, &$request)
99 // override plugin argument by GET: probably not needed if s||="" is used
100 // anyway, we force it for unique interface.
101 if (!empty($request->getArg['s'])) {
102 $args['s'] = $request->getArg['s'];
104 if (!empty($args['owner'])) {
105 $sl = PageList::allPagesByOwner($args['owner'], false, $args['sortby'], $args['limit'], $args['exclude']);
106 } elseif (!empty($args['author'])) {
107 $sl = PageList::allPagesByAuthor($args['author'], false, $args['sortby'], $args['limit'], $args['exclude']);
108 } elseif (!empty($args['creator'])) {
109 $sl = PageList::allPagesByCreator($args['creator'], false, $args['sortby'], $args['limit'], $args['exclude']);
110 } elseif (!empty($args['s']) or !empty($args['only'])) {
112 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
114 $this->_list = array();
116 $request->setArg('verify', 1);
117 foreach ($sl as $name) {
118 if (!empty($args['exclude'])) {
119 if (!in_array($name, $args['exclude']))
120 $this->_list[$name] = 1;
122 $this->_list[$name] = 1;
131 * @param string $argstr
132 * @param WikiRequest $request
133 * @param string $basepage
136 function run($dbi, $argstr, &$request, $basepage)
138 //if ($request->getArg('action') != 'browse')
139 // return $this->disabled("(action != 'browse')");
140 $args = $this->getArgs($argstr, $request);
141 $this->_args = $args;
143 $this->preSelectS($args, $request);
145 $info = $args['info'];
147 $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post'));
148 if ($request->getArg('WikiAdminSelect') == _("Go"))
151 $p = $request->getArg('p');
152 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
153 HTML::input(array('type' => 'text',
155 'value' => $args['s'])),
156 HTML::input(array('type' => 'submit',
157 'name' => 'WikiAdminSelect',
158 'value' => _("Go")))));
159 if (!$request->getArg('verify')) {
160 $form->pushContent(HTML::input(array('type' => 'hidden',
162 'value' => 'verify')));
163 $form->pushContent(Button('submit:verify', _("Select pages"),
165 Button('submit:cancel', _("Cancel"), 'button'));
168 $form->pushContent(HTML::input(array('type' => 'hidden',
170 'value' => 'WikiAdminSelect'))
172 // Add the Buttons for all registered WikiAdmin plugins
173 $plugin_dir = 'lib/plugin';
174 if (defined('PHPWIKI_DIR'))
175 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
176 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
177 $actions = $fs->getFiles();
179 foreach ($actions as $f) {
180 $f = preg_replace('/.php$/', '', $f);
181 $s = preg_replace('/^WikiAdmin/', '', $f);
182 if (!in_array($s, array("Select", "Utils"))) { // disable Select and Utils
183 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
184 $form->pushContent($WikiTheme->getButtonSeparator());
187 // $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
190 if ($request->isPost()
191 && !$request->getArg('wikiadmin')
194 $this->_list = array();
195 // List all selected pages again.
196 foreach ($p as $page => $name) {
197 $this->_list[$name] = 1;
199 } elseif ($request->isPost()
200 and $request->_user->isAdmin()
202 //and $request->getArg('verify')
203 and ($request->getArg('action') == 'WikiAdminSelect')
204 and $request->getArg('wikiadmin')
206 // handle external plugin
207 $loader = new WikiPluginLoader();
208 $a = array_keys($request->getArg('wikiadmin'));
209 $plugin_action = $a[0];
210 $single_arg_plugins = array("Remove");
211 if (in_array($plugin_action, $single_arg_plugins)) {
212 $plugin = $loader->getPlugin($plugin_action);
214 foreach ($p as $page => $name) {
215 $plugin_args = "run_page=$name";
216 $request->setArg($plugin_action, 1);
217 $request->setArg('p', array($page => $name));
218 // if the plugin requires more args than the pagename,
219 // then this plugin will not return. (Rename, SearchReplace, ...)
220 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
221 $ul->pushContent(HTML::li(fmt("Selected page ā%sā passed to ā%sā.",
223 $ul->pushContent(HTML::ul(HTML::li($action_result)));
226 // redirect to the plugin page.
227 // in which page is this plugin?
228 $plugin_action = preg_replace("/^WikiAdmin/", "", $plugin_action);
230 foreach ($p as $page => $x) {
231 $args["p[$page]"] = 1;
233 header("Location: " .
234 WikiURL(__("PhpWikiAdministration")."/".__($plugin_action), $args, 1));
237 } elseif (empty($args['s'])) {
238 // List all pages to select from.
239 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
241 $pagelist = new PageList_Selectable($info, $args['exclude'], $args);
242 $pagelist->addPageList($this->_list);
243 $form->pushContent($pagelist->getContent());
244 foreach ($args as $k => $v) {
245 if (!in_array($k, array('s', 'WikiAdminSelect', 'action', 'verify')))
246 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
248 if (!$request->getArg('select')) {
251 ; //return $action_result;
256 protected function tablePush(&$table, $first, $second)
270 // c-hanging-comment-ender-p: nil
271 // indent-tabs-mode: nil