]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
Rename functional for PearDB backend
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.9 2004-02-12 13:05:50 rurban Exp $');
3 /*
4  Copyright 2002 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
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.
12
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.
17
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
21  */
22
23 /**
24  * Allows selection of multiple pages which get passed to other
25  * WikiAdmin plugins then. Then do Rename, Remove, Chmod, Chown, ...
26  *
27  * Usage:   <?plugin WikiAdminSelect?>
28  * Author:  Reini Urban <rurban@x-ray.at>
29  *
30  * KNOWN ISSUES:
31  * Just a framework, nothing more.
32  * Future versions will support PagePermissions.
33  */
34 // maybe display more attributes with this class...
35 require_once('lib/PageList.php');
36
37 class WikiPlugin_WikiAdminSelect
38 extends WikiPlugin
39 {
40     function getName() {
41         return _("WikiAdminSelect");
42     }
43
44     function getDescription() {
45         return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
46     }
47
48     function getVersion() {
49         return preg_replace("/[Revision: $]/", '',
50                             "\$Revision: 1.9 $");
51     }
52
53     function getDefaultArguments() {
54         return array('s'       => '', // preselect pages
55                      'only'    => '',
56                      'exclude' => '',
57                      'info'    => 'most',
58                      'sortby'  => 'pagename',
59                      'debug'   => false);
60     }
61
62     function collectPages(&$list, &$dbi, $sortby) {
63         $allPages = $dbi->getAllPages(0,$sortby);
64         while ($pagehandle = $allPages->next()) {
65             $pagename = $pagehandle->getName();
66             if (empty($list[$pagename]))
67                 $list[$pagename] = 0;
68         }
69     }
70
71     function run($dbi, $argstr, $request) {
72         //if ($request->getArg('action') != 'browse')
73         //    return $this->disabled("(action != 'browse')");
74         $args = $this->getArgs($argstr, $request);
75         if (!empty($args['only']))
76             $only = explodePageList($args['only']);
77         else
78             $only = false;
79         if (!empty($args['exclude']))
80             $exclude = explodePageList($args['exclude']);
81         else
82             $exclude = false;
83         $info = $args['info'];
84         $this->debug = $args['debug'];
85         if (!empty($request->getArg['s']))
86             $args['s'] = $request->getArg['s'];
87         if (!empty($args['s'])) {
88             $s = $args['s'];
89             $sl = explodePageList($args['s']);
90             $this->_list = array();
91             if ($sl) {
92                 $request->setArg('verify',1);
93                 foreach ($sl as $name) {
94                     $this->_list[$name] = 1;
95                 }
96             }
97         } else {
98             $s = '*';
99             $this->_list = array();
100         }
101         $this->debug = $args['debug'];
102         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
103         $pagename = $request->getArg('pagename');
104         // GetUrlToSelf() with all given params
105         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
106         $uri = $request->getURLtoSelf(false, array('verify'));
107         $form = HTML::form(array('action' => $uri, 'method' => 'POST'));
108         if ($request->getArg('WikiAdminSelect') == _("Go"))
109             $p = false;
110         else
111             $p = $request->getArg('p');
112         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
113         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
114                                    HTML::input(array('type' => 'text',
115                                                      'name' => 's',
116                                                      'value' => $s)),
117                                    HTML::input(array('type' => 'submit',
118                                                      'name' => 'WikiAdminSelect',
119                                                      'value' => _("Go")))));
120         if ($request->isPost() && $request->getArg('verify') && !empty($p)) {
121             // List all selected pages again.
122             foreach ($p as $page => $name) {
123                 $this->_list[$name] = 1;
124             }
125         } elseif ($request->isPost() && $request->_user->isAdmin()
126                   && !empty($p)
127                   && $request->getArg('action') == 'WikiAdminSelect') {
128             // handle external plugin
129             $l = new WikiPluginLoader();
130             $plugin_action = $request->getArg('submit');
131             $plugin = $l->getPlugin($plugin_action);
132
133             $ul = HTML::ul();
134             foreach ($p as $page => $name) {
135                 $plugin_args = "run_page=$name";
136                 $request->setArg($plugin_action, 1);
137                 $request->setArg('p', array($page => $name));
138                 $action_result = $plugin->run($dbi, $plugin_args, $request);
139                 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
140                                               $name, $select)));
141                 $ul->pushContent(HTML::ul(HTML::li($action_result)));
142             }
143         } elseif (empty($args['s'])) {
144             // List all pages to select from.
145             $this->collectPages($this->_list, $dbi, $args['sortby']);
146         }
147         $pagelist = new PageList_Selectable($info
148                                             ? 'checkbox,' . $info
149                                             : 'checkbox', $exclude);
150         $pagelist->addPageList($this->_list);
151         $form->pushContent($pagelist->getContent());
152         foreach ($args as $k => $v) {
153             if (!in_array($k,array('s','WikiAdminSelect','action')))
154                 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
155         }
156         foreach ($_GET as $k => $v) {
157             if (!in_array($k,array('s','WikiAdminSelect','action')))
158                 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
159         }
160         if (! $request->getArg('verify')) {
161             $form->pushContent(HTML::input(array('type' => 'hidden',
162                                                  'name' => 'action',
163                                                  'value' => 'verify')));
164             $form->pushContent(Button('submit:verify', _("Select pages"),
165                                       'wikiadmin'),
166                                Button('submit:cancel', _("Cancel"), 'button'));
167         } else {
168             global $Theme;
169             $form->pushContent(HTML::input(array('type' => 'hidden',
170                                                  'name' => 'action',
171                                                  'value' => 'WikiAdminSelect'))
172                                );
173             // Add the Buttons for all registered WikiAdmin plugins
174             $plugin_dir = 'lib/plugin';
175             if (defined('PHPWIKI_DIR'))
176                 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
177             $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
178             $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:$f", _($s), "wikiadmin"));
184                     $form->pushContent($Theme->getButtonSeparator());
185                 }
186             }
187             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
188         }
189         if (! $request->getArg('select')) {
190             return $form;
191         } else {
192             ; //return $action_result;
193         }
194     }
195 }
196
197 // $Log: not supported by cvs2svn $
198 // Revision 1.8  2004/02/11 20:00:16  rurban
199 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
200 //
201 // Revision 1.7  2004/01/27 23:23:39  rurban
202 // renamed ->Username => _userid for consistency
203 // renamed mayCheckPassword => mayCheckPass
204 // fixed recursion problem in WikiUserNew
205 // fixed bogo login (but not quite 100% ready yet, password storage)
206 //
207 // Revision 1.6  2004/01/26 19:15:29  rurban
208 // Interim fix
209 //
210 // Revision 1.5  2003/02/24 19:38:04  dairiki
211 // Get rid of unused method Request::debugVars().
212 //
213 // Revision 1.4  2003/02/24 01:36:27  dairiki
214 // Don't use PHPWIKI_DIR unless it's defined.
215 // (Also typo/bugfix in SystemInfo plugin.)
216 //
217 // Revision 1.3  2003/02/22 20:49:56  dairiki
218 // Fixes for "Call-time pass by reference has been deprecated" errors.
219 //
220 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
221 // Code cleanup:
222 // Reformatting & tabs to spaces;
223 // Added copyleft, getVersion, getDescription, rcs_id.
224 //
225
226 // Local Variables:
227 // mode: php
228 // tab-width: 8
229 // c-basic-offset: 4
230 // c-hanging-comment-ender-p: nil
231 // indent-tabs-mode: nil
232 // End:
233 ?>