]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/WikiAdminSelect.php
LANG still broken, working on better locale handling.
[SourceForge/phpwiki.git] / lib / plugin / WikiAdminSelect.php
1 <?php // -*-php-*-
2 rcs_id('$Id: WikiAdminSelect.php,v 1.1 2002-08-27 21:51:31 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 WikiAdmin plugins then.
25  * Usage:   <?plugin WikiAdminSelect?>
26  * Author:  Reini Urban <rurban@x-ray.at>
27  *
28  * KNOWN ISSUES:
29  * Just a framework, nothing more.
30  * Future versions will support PagePermissions.
31  */ 
32 // maybe display more attributes with this class...
33 require_once('lib/PageList.php'); 
34
35 class WikiPlugin_WikiAdminSelect
36 extends WikiPlugin
37 {
38     function getName() {
39         return _("WikiAdminSelect");
40     }
41
42     function getDescription() {
43         return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
44     }
45
46     function getDefaultArguments() {
47         return array('s'   => '*',
48                      'only'    => '',
49                      'exclude' => '',
50                      'info'    => 'all',
51                      'debug'   => false);
52     }
53
54     function collectPages(&$list, &$dbi) {
55         $allPages = $dbi->getAllPages();
56         while ($pagehandle = $allPages->next()) {
57             $pagename = $pagehandle->getName();
58             if (empty($list[$pagename])) $list[$pagename] = 0;
59         }
60     }
61
62     function run($dbi, $argstr, $request) {
63         $args = $this->getArgs($argstr, $request);
64         if (!empty($args['only']))
65             $only = explodePageList($args['only']);
66         else $only = false;
67         if (!empty($args['exclude']))
68             $exclude = explodePageList($args['exclude']);
69         else $exclude = false;
70         $info = $args['info'];
71         $this->debug = $args['debug'];
72         if (!empty($args['s'])) {
73             $s = $args['s'];
74             $sl = explodePageList($args['s']);
75             $this->_list = array();
76             if ($sl) {
77                 $request->setArg('verify',1);
78                 foreach ($sl as $name) {
79                     $this->_list[$name] = 1;
80                 }
81             }
82         } else {
83             $s = '*';
84             $this->_list = array();
85         }
86         $this->debug = $args['debug'];
87         // array_multisort($this->_list, SORT_NUMERIC, SORT_DESC);
88         $pagename = $request->getArg('pagename');
89         // GetUrlToSelf() with all given params
90         //$uri = $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI']; // without s would be better.
91         $uri = $request->getURLtoSelf($request->debugVars(),array('verify'));
92         $form = HTML::form(array('action' => $uri, 'method' => 'POST'));
93         if ($request->getArg('submit') == 'WikiAdminSelect')
94             $p = false;
95         else
96             $p = $request->getArg('p');
97         //$p = @$GLOBALS['HTTP_POST_VARS']['p'];
98         $form->pushContent(HTML::p(array('class' => 'wikitext'), _("Select: "), HTML::input(array('type' => 'text', 'name' => 's', 'value' => $s)), HTML::input(array('type' => 'submit', 'name' => 'WikiAdminSelect', 'value' => _("Go")))));
99         if ($request->isPost() and $request->getArg('verify') and !empty($p)) {
100             // List all selected pages again.
101             foreach ($p as $page => $name) {
102                 $this->_list[$name] = 1;
103             }
104         } elseif ($request->isPost() and $request->_user->isAdmin() and 
105                   !empty($p) and $request->getArg('action') == 'WikiAdminSelect') {
106             // handle external plugin
107             $l = new WikiPluginLoader();
108             $plugin_action = $request->getArg('submit');
109             $plugin = $l->getPlugin($plugin_action);
110             
111             $ul = HTML::ul();
112             foreach ($p as $page => $name) {
113                 $plugin_args = "run_page=$name"; 
114                 $request->setArg($plugin_action,1);
115                 $request->setArg('p',array($page => $name));
116                 $action_result = $plugin->run($dbi, $plugin_args, $request);
117                 $ul->pushContent(HTML::li(fmt("Selected page '%s' passed to '%s'.", $name, $select)));
118                 $ul->pushContent(HTML::ul(HTML::li($action_result)));
119             }
120         } elseif (empty($args['s'])) {
121             // List all pages to select from.
122             $this->collectPages($this->_list, &$dbi);
123         }
124         $pagelist = new PageList_Selectable($info ? 'checkbox,'.$info : 'checkbox', $exclude); 
125         $pagelist->addPageList($this->_list);
126         $form->pushContent($pagelist->getContent());
127         $form->pushContent(HiddenGets(array('s'))); // debugging params, ...
128         if (! $request->getArg('verify')) {
129             $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'verify')));
130             $form->pushContent(Button('submit:verify', _("Select pages"), 'wikiadmin'), 
131                                Button('submit:cancel', _("Cancel"), 'button'));
132         } else {
133             global $Theme;
134             $form->pushContent(HTML::input(array('type' => 'hidden', 'name' => 'action', 'value' => 'WikiAdminSelect')));
135             // Add the Buttons for all registered WikiAdmin plugins
136             $fs = new fileSet(PHPWIKI_DIR . '/lib/plugin', 'WikiAdmin*.php');
137             $actions = $fs->getFiles();
138             foreach ($actions as $f) {
139                 $f = preg_replace('/.php$/','', $f);
140                 $s = preg_replace('/^WikiAdmin/','', $f);
141                 $form->pushContent(Button("submit:$f", _($s), "wikiadmin"));
142                 $form->pushContent($Theme->getButtonSeparator());
143             }
144             $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
145         }
146         if (! $request->getArg('select')) {
147             return $form;
148         } else {
149             ; //return $action_result;
150         }
151     }
152 }
153
154 // Local Variables:
155 // mode: php
156 // tab-width: 8
157 // c-basic-offset: 4
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil
160 // End:
161 ?>