]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
fixed DumpHtmlToDir,
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.13 2004-02-22 23:20:33 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.13 $");
51     }
52
53     function getDefaultArguments() {
54         return array('s'       => '', // preselect pages
55                      'only'    => '',
56                      'exclude' => '',
57                      'info'    => 'most',
58                      'sortby'  => 'pagename',
59                      'limit'    => 0,
60                      'debug'   => false);
61     }
62
63     function collectPages(&$list, &$dbi, $sortby, $limit) {
64         $allPages = $dbi->getAllPages(0,$sortby,$limit);
65         while ($pagehandle = $allPages->next()) {
66             $pagename = $pagehandle->getName();
67             if (empty($list[$pagename]))
68                 $list[$pagename] = 0;
69         }
70         return $list;
71     }
72
73     function run($dbi, $argstr, &$request, $basepage) {
74         //if ($request->getArg('action') != 'browse')
75         //    return $this->disabled("(action != 'browse')");
76         $args = $this->getArgs($argstr, $request);
77         if (!empty($args['only']))
78             $only = explodePageList($args['only']);
79         else
80             $only = false;
81         if (!empty($args['exclude']))
82             $exclude = explodePageList($args['exclude']);
83         else
84             $exclude = false;
85         $info = $args['info'];
86         $this->debug = $args['debug'];
87         if (!empty($request->getArg['s']))
88             $args['s'] = $request->getArg['s'];
89         if (  //( $request->getArg('WikiAdminSelect') == _("Go")) and 
90               !empty($args['s'])) {
91             $s = $args['s'];
92             $sl = explodePageList($args['s']);
93             $this->_list = array();
94             if ($sl) {
95                 $request->setArg('verify',1);
96                 foreach ($sl as $name) {
97                     $this->_list[$name] = 1;
98                 }
99             }
100         } else {
101             $s = '*';
102             if (!empty($args['s']))
103                 $s = $args['s'];
104             $this->_list = array();
105         }
106
107         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
108         $pagename = $request->getArg('pagename');
109         // GetUrlToSelf() with all given params
110         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
111         //$uri = $request->getURLtoSelf();//false, array('verify'));
112         $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'POST'));
113         if ($request->getArg('WikiAdminSelect') == _("Go"))
114             $p = false;
115         else
116             $p = $request->getArg('p');
117         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
118         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "),
119                                    HTML::input(array('type' => 'text',
120                                                      'name' => 's',
121                                                      'value' => $s)),
122                                    HTML::input(array('type' => 'submit',
123                                                      'name' => 'WikiAdminSelect',
124                                                      'value' => _("Go")))));
125         if ($request->isPost() 
126             && ! $request->getArg('wikiadmin')
127             && !empty($p)) {
128             $this->_list = array();
129             // List all selected pages again.
130             foreach ($p as $page => $name) {
131                 $this->_list[$name] = 1;
132             }
133         }
134         elseif ($request->isPost()
135                 and $request->_user->isAdmin()
136                 and !empty($p)
137                 //and $request->getArg('verify')
138                 and ($request->getArg('action') == 'WikiAdminSelect')
139                 and $request->getArg('wikiadmin')
140                )
141         {
142             // handle external plugin
143             $loader = new WikiPluginLoader();
144             $a = array_keys($request->getArg('wikiadmin'));
145             $plugin_action = $a[0];
146             $single_arg_plugins = array("Remove");
147             if (in_array($plugin_action,$single_arg_plugins)) {
148                 $plugin = $loader->getPlugin($plugin_action);
149                 $ul = HTML::ul();
150                 foreach ($p as $page => $name) {
151                     $plugin_args = "run_page=$name";
152                     $request->setArg($plugin_action, 1);
153                     $request->setArg('p', array($page => $name));
154                     // if the plugin requires more args than the pagename,
155                     // then this plugin will not return. (Rename, SearchReplace, ...)
156                     $action_result = $plugin->run($dbi, $plugin_args, $request, $basepage);
157                     $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.",
158                                                   $name, $select)));
159                     $ul->pushContent(HTML::ul(HTML::li($action_result)));
160                 }
161             } else {
162                 // redirect to the plugin page.
163                 // in which page is this plugin?
164                 $plugin_action = preg_replace("/^WikiAdmin/","",$plugin_action);
165                 $args = array();
166                 foreach ($p as $page => $x) {
167                   $args["p[$page]"] = 1;
168                 }
169                 header("Location: ".
170                   WikiURL(_("PhpWikiAdministration")."/"._($plugin_action),$args,1));
171                 exit();
172             }
173         } elseif (empty($args['s'])) {
174             // List all pages to select from.
175             $this->_list = $this->collectPages($this->_list, $dbi, $args['sortby'], $args['limit']);
176         }
177         $pagelist = new PageList_Selectable($info, $exclude);
178         $pagelist->addPageList($this->_list);
179         $form->pushContent($pagelist->getContent());
180         foreach ($args as $k => $v) {
181             if (!in_array($k,array('s','WikiAdminSelect','action','verify')))
182                 $form->pushContent(HiddenInputs(array($k => $v))); // plugin params
183         }
184         /*
185         foreach ($_GET as $k => $v) {
186             if (!in_array($k,array('s','WikiAdminSelect','action')))
187                 $form->pushContent(HiddenInputs(array($k => $v))); // debugging params, ...
188         }
189         */
190         if (! $request->getArg('verify')) {
191             $form->pushContent(HTML::input(array('type' => 'hidden',
192                                                  'name' => 'action',
193                                                  'value' => 'verify')));
194             $form->pushContent(Button('submit:verify', _("Select pages"),
195                                       'wikiadmin'),
196                                Button('submit:cancel', _("Cancel"), 'button'));
197         } else {
198             global $Theme;
199             $form->pushContent(HTML::input(array('type' => 'hidden',
200                                                  'name' => 'action',
201                                                  'value' => 'WikiAdminSelect'))
202                                );
203             // Add the Buttons for all registered WikiAdmin plugins
204             $plugin_dir = 'lib/plugin';
205             if (defined('PHPWIKI_DIR'))
206                 $plugin_dir = PHPWIKI_DIR . "/$plugin_dir";
207             $fs = new fileSet($plugin_dir, 'WikiAdmin*.php');
208             $actions = $fs->getFiles();
209             foreach ($actions as $f) {
210                 $f = preg_replace('/.php$/','', $f);
211                 $s = preg_replace('/^WikiAdmin/','', $f);
212                 if (!in_array($s,array("Select","Utils"))) { // disable Select and Utils
213                     $form->pushContent(Button("submit:wikiadmin[$f]", _($s), "wikiadmin"));
214                     $form->pushContent($Theme->getButtonSeparator());
215                 }
216             }
217             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
218         }
219         if (! $request->getArg('select')) {
220             return $form;
221         } else {
222             ; //return $action_result;
223         }
224     }
225 }
226
227 // $Log: not supported by cvs2svn $
228 // Revision 1.12  2004/02/19 22:05:57  rurban
229 // Allow s arg from get requests (plugin-form as in PhpWikiAdministration)
230 //
231 // Revision 1.11  2004/02/17 12:11:36  rurban
232 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
233 //
234 // Revision 1.10  2004/02/15 21:34:37  rurban
235 // PageList enhanced and improved.
236 // fixed new WikiAdmin... plugins
237 // editpage, Theme with exp. htmlarea framework
238 //   (htmlarea yet committed, this is really questionable)
239 // WikiUser... code with better session handling for prefs
240 // enhanced UserPreferences (again)
241 // RecentChanges for show_deleted: how should pages be deleted then?
242 //
243 // Revision 1.9  2004/02/12 13:05:50  rurban
244 // Rename functional for PearDB backend
245 // some other minor changes
246 // SiteMap comes with a not yet functional feature request: includepages (tbd)
247 //
248 // Revision 1.8  2004/02/11 20:00:16  rurban
249 // WikiAdmin... series overhaul. Rename misses the db backend methods yet. Chmod + Chwon still missing.
250 //
251 // Revision 1.7  2004/01/27 23:23:39  rurban
252 // renamed ->Username => _userid for consistency
253 // renamed mayCheckPassword => mayCheckPass
254 // fixed recursion problem in WikiUserNew
255 // fixed bogo login (but not quite 100% ready yet, password storage)
256 //
257 // Revision 1.6  2004/01/26 19:15:29  rurban
258 // Interim fix
259 //
260 // Revision 1.5  2003/02/24 19:38:04  dairiki
261 // Get rid of unused method Request::debugVars().
262 //
263 // Revision 1.4  2003/02/24 01:36:27  dairiki
264 // Don't use PHPWIKI_DIR unless it's defined.
265 // (Also typo/bugfix in SystemInfo plugin.)
266 //
267 // Revision 1.3  2003/02/22 20:49:56  dairiki
268 // Fixes for "Call-time pass by reference has been deprecated" errors.
269 //
270 // Revision 1.2  2003/01/18 22:14:29  carstenklapp
271 // Code cleanup:
272 // Reformatting & tabs to spaces;
273 // Added copyleft, getVersion, getDescription, rcs_id.
274 //
275
276 // Local Variables:
277 // mode: php
278 // tab-width: 8
279 // c-basic-offset: 4
280 // c-hanging-comment-ender-p: nil
281 // indent-tabs-mode: nil
282 // End:
283 ?>