*Tweak rev_deleted message
[mediawiki.git] / includes / HTMLForm.php
blob69ec1007c262ae32cc5fdc603e506816facadae2
1 <?php
2 /**
3 * This file contain a class to easily build HTML forms
4 */
6 /**
7 * Class to build various forms
9 * @author jeluf, hashar
11 class HTMLForm {
12 /** name of our form. Used as prefix for labels */
13 var $mName, $mRequest;
15 function HTMLForm( &$request ) {
16 $this->mRequest = $request;
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
25 function fieldset( $name, $content ) {
26 return "<fieldset><legend>".wfMsg($this->mName.'-'.$name)."</legend>\n" .
27 $content . "\n</fieldset>\n";
30 /**
31 * @private
32 * @param $varname String: name of the checkbox.
33 * @param $checked Boolean: set true to check the box (default False).
35 function checkbox( $varname, $checked=false ) {
36 if ( $this->mRequest->wasPosted() && !is_null( $this->mRequest->getVal( $varname ) ) ) {
37 $checked = $this->mRequest->getCheck( $varname );
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";
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)
51 function textbox( $varname, $value='', $size=20 ) {
52 if ( $this->mRequest->wasPosted() ) {
53 $value = $this->mRequest->getText( $varname, $value );
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";
60 /**
61 * @private
62 * @param $varname String: name of the radiobox.
63 * @param $fields Array: Various fields.
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";
71 return $this->fieldset( $varname, $s );
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)
80 function textareabox ( $varname, $value='', $size=20 ) {
81 if ( $this->mRequest->wasPosted() ) {
82 $value = $this->mRequest->getText( $varname, $value );
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";
89 /**
90 * @private
91 * @param $varname String: name of the arraybox.
92 * @param $size Integer: Optional size of the textarea (default 20)
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";
104 return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
105 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
107 } // end class