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