3 * This file contain a class to easily build HTML forms as well as custom
4 * functions used by SpecialUserrights.php and SpecialGroups.php
9 * Class to build various forms
12 * @author jeluf, hashar
15 /** name of our form. Used as prefix for labels */
16 var $mName, $mRequest;
18 function HTMLForm( &$request ) {
19 $this->mRequest
= $request;
24 * @param string $name Name of the fieldset.
25 * @param string $content HTML content to put in.
26 * @return string HTML fieldset
28 function fieldset( $name, $content ) {
29 return "<fieldset><legend>".wfMsg($this->mName
.'-'.$name)."</legend>\n" .
30 $content . "\n</fieldset>\n";
35 * @param string $varname Name of the checkbox.
36 * @param boolean $checked Set true to check the box (default False).
38 function checkbox( $varname, $checked=false ) {
39 if ( $this->mRequest
->wasPosted() && !is_null( $this->mRequest
->getVal( $varname ) ) ) {
40 $checked = $this->mRequest
->getCheck( $varname );
42 return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
43 ( $checked ?
' checked="checked"' : '' ) .
44 " /><label for=\"{$varname}\">". wfMsg( $this->mName
.'-'.$varname ) .
50 * @param string $varname Name of the textbox.
51 * @param string $value Optional value (default empty)
52 * @param integer $size Optional size of the textbox (default 20)
54 function textbox( $varname, $value='', $size=20 ) {
55 if ( $this->mRequest
->wasPosted() ) {
56 $value = $this->mRequest
->getText( $varname, $value );
58 $value = htmlspecialchars( $value );
59 return "<div><label>". wfMsg( $this->mName
.'-'.$varname ) .
60 "<input type='text' name=\"{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
65 * @param string $varname Name of the radiobox.
66 * @param array $fields Various fields.
68 function radiobox( $varname, $fields ) {
69 foreach ( $fields as $value => $checked ) {
70 $s .= "<div><label><input type='radio' name=\"{$varname}\" value=\"{$value}\"" .
71 ( $checked ?
' checked="checked"' : '' ) . " />" . wfMsg( $this->mName
.'-'.$varname.'-'.$value ) .
74 return $this->fieldset( $this->mName
.'-'.$varname, $s );
79 * @param string $varname Name of the textareabox.
80 * @param string $value Optional value (default empty)
81 * @param integer $size Optional size of the textarea (default 20)
83 function textareabox ( $varname, $value='', $size=20 ) {
84 if ( $this->mRequest
->wasPosted() ) {
85 $value = $this->mRequest
->getText( $varname, $value );
87 $value = htmlspecialchars( $value );
88 return '<div><label>'.wfMsg( $this->mName
.'-'.$varname ).
89 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea></label></div>\n";
94 * @param string $varname Name of the arraybox.
95 * @param integer $size Optional size of the textarea (default 20)
97 function arraybox( $varname , $size=20 ) {
99 if ( $this->mRequest
->wasPosted() ) {
100 $arr = $this->mRequest
->getArray( $varname );
101 if ( is_array( $arr ) ) {
102 foreach ( $_POST[$varname] as $index=>$element ) {
103 $s .= htmlspecialchars( $element )."\n";
107 return "<div><label>".wfMsg( $this->mName
.'-'.$varname ).
108 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
113 // functions used by SpecialUserrights.php and SpecialGroups.php
115 /** Build a select with all defined groups
116 * @param string $selectname Name of this element. Name of form is automaticly prefixed.
117 * @param array $selected Array of element selected when posted. Only multiples will show them.
118 * @param boolean $multiple A multiple elements select.
119 * @param integer $size Number of elements to be shown ignored for non-multiple (default 6).
120 * @param boolean $reverse If true, multiple select will hide selected elements (default false).
122 function HTMLSelectGroups($selectname, $selectmsg, $selected=array(), $multiple=false, $size=6, $reverse=false) {
124 $groups =& Group
::getAllGroups();
126 $out = wfMsg($selectmsg);
127 $out .= '<select name="'.$selectname;
128 if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
131 foreach ( $groups as $id => $g ) {
133 // for multiple will only show the things we want
134 if(in_array($id, $selected) xor $reverse) {
135 $out .= '<option value="'.$id.'">'.$wgOut->parse( $g->getExpandedName() )."</option>\n";
139 if(in_array($id, $selected)) { $out .= 'selected="selected" '; }
140 $out .= 'value="'.$id.'">'.$wgOut->parse( $g->getExpandedName() )."</option>\n";
143 $out .= "</select>\n";
147 /** Build a select with all existent rights
148 * @param array $selected Names(?) of user rights that should be selected.
149 * @return string HTML select.
151 function HTMLSelectRights($selected='') {
152 global $wgAvailableRights;
153 $out = '<select name="editgroup-getrights[]" multiple="multiple">';
154 $groupRights = explode(',',$selected);
156 foreach($wgAvailableRights as $right) {
158 // check box when right exist
159 if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
160 else { $selected = ''; }
162 $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
164 $out .= "</select>\n";