2 rcs_id('$Id: WikiFormRich.php,v 1.9 2004-11-24 13:55:42 rurban Exp $');
4 Copyright 2004 $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 * This is another replacement for MagicPhpWikiURL forms.
25 * Previously encoded with the "phpwiki:" syntax.
27 * Enhanced WikiForm to be more generic:
28 * - editbox[] name=.. value=.. text=..
29 * - checkbox[] name=.. value=0|1 checked text=..
30 * - radiobutton[] name=.. value=.. text=..
31 * - pulldown[] name=.. values=.. selected=.. text=.. (not yet!)
32 * - hidden[] name=.. value=..
33 * - action, submit buttontext, optional cancel button (bool)
34 * - method=GET or POST ((Default: POST).
36 * values which are constants are evaluated.
37 * The cancel button must be supported by the action. (which?)
39 * improve layout: nobr=1, class=wikiadmin
41 * add pulldown, possibly with <!plugin-list !>
44 <?plugin WikiFormRich action=dumpserial method=GET
45 checkbox[] name=include value="all"
46 editbox[] name=directory value=DEFAULT_DUMP_DIR
47 editbox[] name=pages value=*
48 editbox[] name=exclude value="" ?>
49 <?plugin WikiFormRich action=dumphtml method=GET
50 editbox[] name=directory value=HTML_DUMP_DIR
51 editbox[] name=pages value="*"
52 editbox[] name=exclude value="" ?>
53 <?plugin WikiFormRich action=loadfile method=GET
54 editbox[] name=source value=DEFAULT_WIKI_PGSRC
55 checkbox[] name=overwrite value=1
56 editbox[] name=exclude value="" ?>
57 <?plugin WikiFormRich action=TitleSearch method=GET class=wikiadmin nobr=1
58 editbox[] name=s text=""
59 checkbox[] name=case_exact
60 checkbox[] name=regex ?>
61 <?plugin WikiFormRich action=FullTextSearch method=GET class=wikiadmin nobr=1
62 editbox[] name=s text=""
63 checkbox[] name=case_exact
64 checkbox[] name=regex ?>
65 <?plugin WikiFormRich action=FuzzyPages method=GET class=wikiadmin nobr=1
66 editbox[] name=s text=""
67 checkbox[] name=case_exact ?>
70 class WikiPlugin_WikiFormRich
74 return "WikiFormRich";
76 function getDescription () {
77 return _("Provide generic WikiForm input buttons");
79 function getVersion() {
80 return preg_replace("/[Revision: $]/", '',
83 function getDefaultArguments() {
84 return array('action' => false, // required argument
85 'method' => 'POST', // or GET
87 'buttontext' => false, // for the submit button. default: action
88 'cancel' => false, // boolean if the action supports cancel also
89 'nobr' => false, // "no break": linebreaks or not
93 function handle_plugin_args_cruft($argstr, $args) {
94 $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "pulldown");
95 // no editbox[] = array(...) allowed (space)
96 $arg_array = preg_split("/\n/", $argstr);
97 // for security we should check this better
99 for ($i = 0; $i < count($arg_array); $i++) {
100 if (preg_match("/^\s*(".join("|",$allowed).")\[\]\s+(.+)\s*$/", $arg_array[$i], $m)) {
101 $name = $m[1]; // one of the allowed input types
102 $this->inputbox[][$name] = array(); $j = count($this->inputbox) - 1;
103 foreach (preg_split("/[\s]+/", $m[2]) as $attr_pair) {
104 list($attr, $value) = preg_split("/\s*=\s*/", $attr_pair);
105 if (preg_match('/^"(.*)"$/', $value, $m))
107 elseif (in_array($name, array("pulldown","checkbox","radiobutton"))
108 and preg_match('/^<!plugin-list.+!>$/', $value, $m))
109 // like pulldown[] name=test value=<!plugin-list BackLinks page=HomePage!>
111 $loader = new WikiPluginLoader();
114 $plugin_str = preg_replace(array("/^<!/","/!>$/"),array("<?","?>"), $value);
115 // will return a pagelist object! pulldown,checkbox,radiobutton
116 $value = $loader->expandPI($plugin_str, $GLOBALS['request'], $markup, $basepage);
117 if (isa($value, 'PageList')) $value = $value->_pages;
118 elseif (!is_array($value))
119 trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])),
122 elseif (defined($value))
123 $value = constant($value);
124 $this->inputbox[$j][$name][$attr] = $value;
126 //trigger_error("not yet finished");
127 //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
129 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
136 function run($dbi, $argstr, &$request, $basepage) {
137 extract($this->getArgs($argstr, $request));
138 if (empty($action)) {
139 return $this->error(fmt("A required argument '%s' is missing.", "action"));
141 $form = HTML::form(array('action' => $request->getPostURL(),
143 'class' => 'wikiadmin',
144 'accept-charset' => $GLOBALS['charset']),
145 HiddenInputs(array_merge(
146 array('action' => $action),
147 USE_PATH_INFO ? array()
148 : array('pagename' => $basepage))));
149 if ($nobr) $nbsp = HTML::Raw(' ');
150 foreach ($this->inputbox as $inputbox) {
151 foreach ($inputbox as $inputtype => $input) {
154 $input['type'] = 'checkbox';
155 if (empty($input['name']))
156 return $this->error(fmt("A required argument '%s' is missing.",
157 "checkbox[][name]"));
158 if (!isset($input['text']))
159 $input['text'] = gettext($input['name']); //."=".$input['value'];
160 $text = $input['text'];
161 unset($input['text']);
162 if (empty($input['value'])) $input['value'] = 1;
163 elseif (is_array($input['value'])) {
167 if (empty($input['checked'])) {
168 if ($request->getArg($input['name']))
169 $input['checked'] = 'checked';
171 $input['checked'] = 'checked';
174 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
176 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
179 $input['type'] = 'text';
180 if (empty($input['name']))
181 return $this->error(fmt("A required argument '%s' is missing.",
183 if (!isset($input['text'])) $input['text'] = gettext($input['name']);
184 $text = $input['text'];
185 if (empty($input['value']) and ($s = $request->getArg($input['name'])))
186 $input['value'] = $s;
187 unset($input['text']);
189 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
191 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
194 $input['type'] = 'radio';
195 if (empty($input['name']))
196 return $this->error(fmt("A required argument '%s' is missing.",
197 "radiobutton[][name]"));
198 if (!isset($input['text'])) $input['text'] = gettext($input['name']);
199 $text = $input['text'];
200 unset($input['text']);
201 if ($input['checked']) $input['checked'] = 'checked';
203 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
205 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
208 $input['type'] = 'hidden';
209 if (empty($input['name']))
210 return $this->error(fmt("A required argument '%s' is missing.",
212 unset($input['text']);
213 $form->pushContent(HTML::input($input));
215 return $this->error("Sorry, pulldown not yet supported");
219 if ($request->getArg('start_debug'))
220 $form->pushContent(HTML::input(array('name' => 'start_debug',
221 'value' => $request->getArg('start_debug'),
222 'type' => 'hidden')));
224 $form->pushContent(HiddenInputs(array('pagename' => $basepage)));
225 if (empty($buttontext)) $buttontext = $action;
226 $submit = Button('submit:', $buttontext, $class);
228 $form->pushContent(HTML::span(array('class' => $class),
229 $submit, Button('submit:cancel', _("Cancel"), $class)));
231 $form->pushContent(HTML::span(array('class' => $class),
238 // $Log: not supported by cvs2svn $
239 // Revision 1.8 2004/11/24 10:58:50 rurban
242 // Revision 1.7 2004/11/24 10:40:04 rurban
243 // better nobr, allow empty text=""
245 // Revision 1.5 2004/11/24 10:14:36 rurban
246 // fill-in request args as with plugin-form
248 // Revision 1.4 2004/11/23 15:17:20 rurban
249 // better support for case_exact search (not caseexact for consistency),
250 // plugin args simplification:
251 // handle and explode exclude and pages argument in WikiPlugin::getArgs
252 // and exclude in advance (at the sql level if possible)
253 // handle sortby and limit from request override in WikiPlugin::getArgs
254 // ListSubpages: renamed pages to maxpages
256 // Revision 1.3 2004/07/09 13:05:34 rurban
259 // Revision 1.2 2004/07/09 10:25:52 rurban
260 // fix the args parser
262 // Revision 1.1 2004/07/02 11:03:53 rurban
263 // renamed WikiFormMore to WikiFormRich: better syntax, no eval (safer)
265 // Revision 1.3 2004/07/01 13:59:25 rurban
266 // enhanced to allow arbitrary order of args and stricter eval checking
268 // Revision 1.2 2004/07/01 13:14:01 rurban
271 // Revision 1.1 2004/07/01 13:11:53 rurban
272 // more generic forms
280 // c-hanging-comment-ender-p: nil
281 // indent-tabs-mode: nil