Added EditFilterMerged hook: like EditFilter but uses the text after section merging...
[lhc/web/wiklou.git] / includes / HTMLForm.php
1 <?php
2 /**
3 * This file contain a class to easily build HTML forms
4 */
5
6 /**
7 * Class to build various forms
8 *
9 * @author jeluf, hashar
10 */
11 class HTMLForm {
12 /** name of our form. Used as prefix for labels */
13 var $mName, $mRequest;
14
15 function HTMLForm( &$request ) {
16 $this->mRequest = $request;
17 }
18
19 /**
20 * @private
21 * @param $name String: name of the fieldset.
22 * @param $content String: HTML content to put in.
23 * @return string HTML fieldset
24 */
25 function fieldset( $name, $content ) {
26 return "<fieldset><legend>".wfMsg($this->mName.'-'.$name)."</legend>\n" .
27 $content . "\n</fieldset>\n";
28 }
29
30 /**
31 * @private
32 * @param $varname String: name of the checkbox.
33 * @param $checked Boolean: set true to check the box (default False).
34 */
35 function checkbox( $varname, $checked=false ) {
36 if ( $this->mRequest->wasPosted() && !is_null( $this->mRequest->getVal( $varname ) ) ) {
37 $checked = $this->mRequest->getCheck( $varname );
38 }
39 return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
40 ( $checked ? ' checked="checked"' : '' ) .
41 " /><label for=\"{$varname}\">". wfMsg( $this->mName.'-'.$varname ) .
42 "</label></div>\n";
43 }
44
45 /**
46 * @private
47 * @param $varname String: name of the textbox.
48 * @param $value String: optional value (default empty)
49 * @param $size Integer: optional size of the textbox (default 20)
50 */
51 function textbox( $varname, $value='', $size=20 ) {
52 if ( $this->mRequest->wasPosted() ) {
53 $value = $this->mRequest->getText( $varname, $value );
54 }
55 $value = htmlspecialchars( $value );
56 return "<div><label>". wfMsg( $this->mName.'-'.$varname ) .
57 "<input type='text' name=\"{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
58 }
59
60 /**
61 * @private
62 * @param $varname String: name of the radiobox.
63 * @param $fields Array: Various fields.
64 */
65 function radiobox( $varname, $fields ) {
66 foreach ( $fields as $value => $checked ) {
67 $s .= "<div><label><input type='radio' name=\"{$varname}\" value=\"{$value}\"" .
68 ( $checked ? ' checked="checked"' : '' ) . " />" . wfMsg( $this->mName.'-'.$varname.'-'.$value ) .
69 "</label></div>\n";
70 }
71 return $this->fieldset( $varname, $s );
72 }
73
74 /**
75 * @private
76 * @param $varname String: name of the textareabox.
77 * @param $value String: optional value (default empty)
78 * @param $size Integer: optional size of the textarea (default 20)
79 */
80 function textareabox ( $varname, $value='', $size=20 ) {
81 if ( $this->mRequest->wasPosted() ) {
82 $value = $this->mRequest->getText( $varname, $value );
83 }
84 $value = htmlspecialchars( $value );
85 return '<div><label>'.wfMsg( $this->mName.'-'.$varname ).
86 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea></label></div>\n";
87 }
88
89 /**
90 * @private
91 * @param $varname String: name of the arraybox.
92 * @param $size Integer: Optional size of the textarea (default 20)
93 */
94 function arraybox( $varname , $size=20 ) {
95 $s = '';
96 if ( $this->mRequest->wasPosted() ) {
97 $arr = $this->mRequest->getArray( $varname );
98 if ( is_array( $arr ) ) {
99 foreach ( $_POST[$varname] as $element ) {
100 $s .= htmlspecialchars( $element )."\n";
101 }
102 }
103 }
104 return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
105 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
106 }
107 } // end class