2 rcs_id('$Id: WikiFormRich.php,v 1.8 2004-11-24 10:58:50 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)) {
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 (defined($value))
108 $value = constant($value);
109 $this->inputbox[$j][$name][$attr] = $value;
111 //trigger_error("not yet finished");
112 //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';');
114 trigger_error(sprintf("Invalid argument %s ignored",htmlentities($arg_array[$i])),
121 function run($dbi, $argstr, &$request, $basepage) {
122 extract($this->getArgs($argstr, $request));
123 if (empty($action)) {
124 return $this->error(fmt("A required argument '%s' is missing.","action"));
126 $form = HTML::form(array('action' => $request->getPostURL(),
128 'class' => 'wikiadmin',
129 'accept-charset' => $GLOBALS['charset']),
130 HiddenInputs(array('action' => $action,
131 'pagename' => $basepage)));
132 if ($nobr) $nbsp = HTML::Raw(' ');
133 foreach ($this->inputbox as $inputbox) {
134 foreach ($inputbox as $inputtype => $input) {
137 $input['type'] = 'checkbox';
138 if (empty($input['name']))
139 return $this->error(fmt("A required argument '%s' is missing.",
140 "checkbox[][name]"));
141 if (empty($input['value'])) $input['value'] = 1;
142 if (!isset($input['text']))
143 $input['text'] = gettext($input['name']); //."=".$input['value'];
144 $text = $input['text'];
145 unset($input['text']);
146 if (empty($input['checked'])) {
147 if ($request->getArg($input['name']))
148 $input['checked'] = 'checked';
150 $input['checked'] = 'checked';
153 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
155 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
158 $input['type'] = 'text';
159 if (empty($input['name']))
160 return $this->error(fmt("A required argument '%s' is missing.",
162 if (!isset($input['text'])) $input['text'] = gettext($input['name']);
163 $text = $input['text'];
164 if (empty($input['value']) and ($s = $request->getArg($input['name'])))
165 $input['value'] = $s;
166 unset($input['text']);
168 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
170 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
173 $input['type'] = 'radio';
174 if (empty($input['name']))
175 return $this->error(fmt("A required argument '%s' is missing.",
176 "radiobutton[][name]"));
177 if (!isset($input['text'])) $input['text'] = gettext($input['name']);
178 $text = $input['text'];
179 unset($input['text']);
180 if ($input['checked']) $input['checked'] = 'checked';
182 $form->pushContent(HTML::input($input), $nbsp, $text, $nbsp);
184 $form->pushContent(HTML::div(array('class' => $class), HTML::input($input), $text));
187 $input['type'] = 'hidden';
188 if (empty($input['name']))
189 return $this->error(fmt("A required argument '%s' is missing.",
191 unset($input['text']);
192 $form->pushContent(HTML::input($input));
194 return $this->error("Sorry, pulldown not yet supported");
198 if ($request->getArg('start_debug'))
199 $form->pushContent(HTML::input(array('name' => 'start_debug',
200 'value' => $request->getArg('start_debug'),
201 'type' => 'hidden')));
202 if (empty($buttontext)) $buttontext = $action;
203 $submit = Button('submit:', $buttontext, $class);
205 $form->pushContent(HTML::span(array('class' => $class),
206 $submit, Button('submit:cancel', _("Cancel"), $class)));
208 $form->pushContent(HTML::span(array('class' => $class),
215 // $Log: not supported by cvs2svn $
216 // Revision 1.7 2004/11/24 10:40:04 rurban
217 // better nobr, allow empty text=""
219 // Revision 1.5 2004/11/24 10:14:36 rurban
220 // fill-in request args as with plugin-form
222 // Revision 1.4 2004/11/23 15:17:20 rurban
223 // better support for case_exact search (not caseexact for consistency),
224 // plugin args simplification:
225 // handle and explode exclude and pages argument in WikiPlugin::getArgs
226 // and exclude in advance (at the sql level if possible)
227 // handle sortby and limit from request override in WikiPlugin::getArgs
228 // ListSubpages: renamed pages to maxpages
230 // Revision 1.3 2004/07/09 13:05:34 rurban
233 // Revision 1.2 2004/07/09 10:25:52 rurban
234 // fix the args parser
236 // Revision 1.1 2004/07/02 11:03:53 rurban
237 // renamed WikiFormMore to WikiFormRich: better syntax, no eval (safer)
239 // Revision 1.3 2004/07/01 13:59:25 rurban
240 // enhanced to allow arbitrary order of args and stricter eval checking
242 // Revision 1.2 2004/07/01 13:14:01 rurban
245 // Revision 1.1 2004/07/01 13:11:53 rurban
246 // more generic forms
254 // c-hanging-comment-ender-p: nil
255 // indent-tabs-mode: nil