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 * This is the base class for most WikiAdmin* classes, using
31 * collectPages() and preSelectS().
32 * "list" PagePermissions supported implicitly by PageList.
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: $]/", '',
52 function getDefaultArguments() {
53 return array('s' => '', // preselect pages
54 /* select pages by meta-data: */
62 'sortby' => 'pagename',
68 * Default collector for all WikiAdmin* plugins.
69 * preSelectS() is similar, but fills $this->_list
71 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-seperated 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) {
89 // override plugin argument by GET: probably not needed if s||="" is used
90 // anyway, we force it for unique interface.
91 if (!empty($request->getArg['s']))
92 $args['s'] = $request->getArg['s'];
93 if ( !empty($args['owner']) )
94 $sl = PageList::allPagesByOwner($args['owner'],false,$args['sortby'],$args['limit'],$args['exclude']);
95 elseif ( !empty($args['author']) )
96 $sl = PageList::allPagesByAuthor($args['author'],false,$args['sortby'],$args['limit'],$args['exclude']);
97 elseif ( !empty($args['creator']) )
98 $sl = PageList::allPagesByCreator($args['creator'],false,$args['sortby'],$args['limit'],$args['exclude']);
99 elseif ( !empty($args['s']) or !empty($args['only']) ) {
101 $sl = explodePageList(empty($args['only']) ? $args['s'] : $args['only']);
103 $this->_list = array();
105 $request->setArg('verify', 1);
106 foreach ($sl as $name) {
107 if (!empty($args['exclude'])) {
108 if (!in_array($name, $args['exclude']))
109 $this->_list[$name] = 1;
111 $this->_list[$name] = 1;
118 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'];
127 $this->debug = $args['debug'];
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->isPost()
148 && ! $request->getArg('wikiadmin')
150 $this->_list = array();
151 // List all selected pages again.
152 foreach ($p as $page => $name) {
153 $this->_list[$name] = 1;
156 elseif ($request->isPost()
157 and $request->_user->isAdmin()
159 //and $request->getArg('verify')
160 and ($request->getArg('action') == 'WikiAdminSelect')
161 and $request->getArg('wikiadmin')
164 // handle external plugin
165 $loader = new WikiPluginLoader();
166 $a = array_keys($request->getArg('wikiadmin'));
167 $plugin_action = $a[0];
168 $single_arg_plugins = array("Remove");
169 if (in_array($plugin_action, $single_arg_plugins)) {
170 $plugin = $loader->getPlugin($plugin_action);
172 foreach ($p as $page => $name) {
173 $plugin_args = "run_page=$name";
174 $request->setArg($plugin_action, 1);
175 $request->setArg('p', array($page => $name));
176 // if the plugin requires more args than the pagename,
177 // then this plugin will not return. (Rename, SearchReplace, ...)
178 $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
179 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
181 $ul->pushContent(HTML::ul(HTML::li($action_result)));
184 // redirect to the plugin page.
185 // in which page is this plugin?
186 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
188 foreach ($p as $page => $x) {
189 $args["p[$page]"] = 1;
192 WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
195 } elseif (empty($args['s'])) {
196 // List all pages to select from.
197 $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
199 $pagelist = new PageList_Selectable($info, $args['exclude'], $args);
200 $pagelist->addPageList($this->_list);
201 $form->pushContent($pagelist->getContent());
202 foreach ($args as $k => $v) {
203 if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
204 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
207 foreach ($_GET as $k => $v) {
208 if (!in_array($k,array('s','WikiAdminSelect','action')))
209 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
212 if (! $request->getArg('verify')) {
213 $form->pushContent(HTML::input(array('type' => 'hidden',
215 'value' => 'verify')));
216 $form->pushContent(Button('submit:verify', _("Select pages"),
218 Button('submit:cancel', _("Cancel"), 'button'));
221 $form->pushContent(HTML::input(array('type' => 'hidden',
223 'value' => 'WikiAdminSelect'))
225 // Add the Buttons for all registered WikiAdmin plugins
226 $plugin_dir = 'lib/plugin';
227 if (defined('PHPWIKI_DIR'))
228 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
229 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
230 $actions = $fs->getFiles();
231 foreach ($actions as $f) {
232 $f = preg_replace('/.php$/','', $f);
233 $s = preg_replace('/^WikiAdmin/','', $f);
234 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
235 $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
236 $form->pushContent($WikiTheme->getButtonSeparator());
239 // $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
241 if (! $request->getArg('select')) {
244 ; //return $action_result;
248 function _tablePush(&$table, $first, $second) {
261 // c-hanging-comment-ender-p: nil
262 // indent-tabs-mode: nil