2 rcs_id('$Id: WikiAdminSelect.php,v 1.1 2002-08-27 21:51:31 rurban 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 WikiAdmin plugins then.
25 * Usage: <?plugin WikiAdminSelect?>
26 * Author: Reini Urban <rurban@x-ray.at>
29 * Just a framework, nothing more.
30 * Future versions will support PagePermissions.
32 // maybe display more attributes with this class...
33 require_once('lib/PageList.php');
35 class WikiPlugin_WikiAdminSelect
39 return _("WikiAdminSelect");
42 function getDescription() {
43 return _("Allows selection of multiple pages which get passed to other WikiAdmin plugins.");
46 function getDefaultArguments() {
47 return array('s' => '*',
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;
62 function run($dbi, $argstr, $request) {
63 $args = $this->getArgs($argstr, $request);
64 if (!empty($args['only']))
65 $only = explodePageList($args['only']);
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'])) {
74 $sl = explodePageList($args['s']);
75 $this->_list = array();
77 $request->setArg('verify',1);
78 foreach ($sl as $name) {
79 $this->_list[$name] = 1;
84 $this->_list = array();
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')
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;
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);
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)));
120 } elseif (empty($args['s'])) {
121 // List all pages to select from.
122 $this->collectPages($this->_list, &$dbi);
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'));
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());
144 $form->pushContent(Button('submit:cancel', _("Cancel"), 'button'));
146 if (! $request->getArg('select')) {
149 ; //return $action_result;
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil