2 rcs_id('$Id: WikiAdminSelect.php,v 1.4 2003-02-24 01:36:27 dairiki 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.
27 * Usage: <?plugin WikiAdminSelect?>
28 * Author: Reini Urban <rurban@x-ray.at>
31 * Just a framework, nothing more.
32 * Future versions will support PagePermissions.
34 // maybe display more attributes with this class...
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' => '*',
61 function collectPages(&$list, &$dbi) {
62 $allPages = $dbi->getAllPages();
63 while ($pagehandle = $allPages->next()) {
64 $pagename = $pagehandle->getName();
65 if (empty($list[$pagename]))
70 function run($dbi, $argstr, $request) {
71 $args = $this->getArgs($argstr, $request);
72 if (!empty($args['only']))
73 $only = explodePageList($args['only']);
76 if (!empty($args['exclude']))
77 $exclude = explodePageList($args['exclude']);
80 $info = $args['info'];
81 $this->debug = $args['debug'];
82 if (!empty($args['s'])) {
84 $sl = explodePageList($args['s']);
85 $this->_list = array();
87 $request->setArg('verify',1);
88 foreach ($sl as $name) {
89 $this->_list[$name] = 1;
94 $this->_list = array();
96 $this->debug = $args['debug'];
97 // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
98 $pagename = $request->getArg('pagename');
99 // GetUrlToSelf() with all given params
100 //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
101 $uri = $request->getURLtoSelf($request->debugVars(), array('verify'));
102 $form = HTML::form(array('action' => $uri, 'method' => 'POST'));
103 if ($request->getArg('submit') == 'WikiAdminSelect')
106 $p = $request->getArg('p');
107 //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
108 $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
109 HTML::input(array('type' => 'text',
112 HTML::input(array('type' => 'submit',
113 'name' => 'WikiAdminSelect',
114 'value' => _("Go")))));
115 if ($request->isPost() && $request->getArg('verify') && !empty($p)) {
116 // List all selected pages again.
117 foreach ($p as $page => $name) {
118 $this->_list[$name] = 1;
120 } elseif ($request->isPost() && $request->_user->isAdmin()
122 && $request->getArg('action') == 'WikiAdminSelect') {
123 // handle external plugin
124 $l = new WikiPluginLoader();
125 $plugin_action = $request->getArg('submit');
126 $plugin = $l->getPlugin($plugin_action);
129 foreach ($p as $page => $name) {
130 $plugin_args = "run_page=$name";
131 $request->setArg($plugin_action, 1);
132 $request->setArg('p', array($page => $name));
133 $action_result = $plugin->run($dbi, $plugin_args, $request);
134 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
136 $ul->pushContent(HTML::ul(HTML::li($action_result)));
138 } elseif (empty($args['s'])) {
139 // List all pages to select from.
140 $this->collectPages($this->_list, $dbi);
142 $pagelist = new PageList_Selectable($info
143 ? 'checkbox,' . $info
144 : 'checkbox', $exclude);
145 $pagelist->addPageList($this->_list);
146 $form->pushContent($pagelist->getContent());
147 $form->pushContent(HiddenGets(array('s'))); // debugging params, ...
148 if (! $request->getArg('verify')) {
149 $form->pushContent(HTML::input(array('type' => 'hidden',
151 'value' => 'verify')));
152 $form->pushContent(Button('submit:verify', _("Select pages"),
154 Button('submit:cancel', _("Cancel"), 'button'));
157 $form->pushContent(HTML::input(array('type' => 'hidden',
159 'value' => 'WikiAdminSelect'))
161 // Add the Buttons for all registered WikiAdmin plugins
162 $plugin_dir = 'lib/plugin';
163 if (defined('PHPWIKI_DIR'))
164 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
165 $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
166 $actions = $fs->getFiles();
167 foreach ($actions as $f) {
168 $f = preg_replace('/.php$/','', $f);
169 $s = preg_replace('/^WikiAdmin/','', $f);
170 $form->pushContent(Button("submit:$f", _($s), "wikiadmin"));
171 $form->pushContent($Theme->getButtonSeparator());
173 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
175 if (! $request->getArg('select')) {
178 ; //return $action_result;
183 // $Log: not supported by cvs2svn $
184 // Revision 1.3 2003/02/22 20:49:56 dairiki
185 // Fixes for "Call-time pass by reference has been deprecated" errors.
187 // Revision 1.2 2003/01/18 22:14:29 carstenklapp
189 // Reformatting & tabs to spaces;
190 // Added copyleft, getVersion, getDescription, rcs_id.
197 // c-hanging-comment-ender-p: nil
198 // indent-tabs-mode: nil