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 */
20 * @param string $name Name of the fieldset.
21 * @param string $content HTML content to put in.
22 * @return string HTML fieldset
24 function fieldset( $name, $content ) {
25 return "<fieldset><legend>".wfMsg($this->mName
.'-'.$name)."</legend>\n" .
26 $content . "\n</fieldset>\n";
31 * @param string $varname Name of the checkbox.
32 * @param boolean $checked Set true to check the box (default False).
34 function checkbox( $varname, $checked=false ) {
35 $checked = isset( $_POST[$varname] ) && $_POST[$varname] ;
36 return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
37 ( $checked ?
' checked="checked"' : '' ) .
38 " /><label for=\"{$varname}\">". wfMsg( $this->mName
.'-'.$varname ) .
44 * @param string $varname Name of the textbox.
45 * @param string $value Optional value (default empty)
46 * @param integer $size Optional size of the textbox (default 20)
48 function textbox( $varname, $value='', $size=20 ) {
49 $value = isset( $_POST[$varname] ) ?
$_POST[$varname] : $value;
50 return "<div><label>". wfMsg( $this->mName
.'-'.$varname ) .
51 "<input type='text' name=\"{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
56 * @param string $varname Name of the radiobox.
57 * @param array $fields Various fields.
59 function radiobox( $varname, $fields ) {
60 foreach ( $fields as $value => $checked ) {
61 $s .= "<div><label><input type='radio' name=\"{$varname}\" value=\"{$value}\"" .
62 ( $checked ?
' checked="checked"' : '' ) . " />" . wfMsg( $this->mName
.'-'.$varname.'-'.$value ) .
65 return $this->fieldset( $this->mName
.'-'.$varname, $s );
70 * @param string $varname Name of the textareabox.
71 * @param string $value Optional value (default empty)
72 * @param integer $size Optional size of the textarea (default 20)
74 function textareabox ( $varname, $value='', $size=20 ) {
75 $value = isset( $_POST[$varname] ) ?
$_POST[$varname] : $value;
76 return '<div><label>'.wfMsg( $this->mName
.'-'.$varname ).
77 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea></label></div>\n";
82 * @param string $varname Name of the arraybox.
83 * @param integer $size Optional size of the textarea (default 20)
85 function arraybox( $varname , $size=20 ) {
87 if ( isset( $_POST[$varname] ) && is_array( $_POST[$varname] ) ) {
88 foreach ( $_POST[$varname] as $index=>$element ) {
92 return "<div><label>".wfMsg( $this->mName
.'-'.$varname ).
93 "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
98 // functions used by SpecialUserrights.php and SpecialGroups.php
100 /** Build a select with all defined groups
101 * @param string $selectname Name of this element. Name of form is automaticly prefixed.
102 * @param array $selected Array of element selected when posted. Multiples will only show them.
103 * @param boolean $multiple A multiple elements select.
104 * @param integer $size Number of element to be shown ignored for non multiple (default 6).
105 * @param boolean $reverse If true, multiple select will hide selected elements (default false).
107 function HTMLSelectGroups($selectname, $selectmsg, $selected=array(), $multiple=false, $size=6, $reverse=false) {
108 $groups =& Group
::getAllGroups();
110 $out = wfMsg($selectmsg);
111 $out .= '<select name="'.$selectname;
112 if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
115 foreach ( $groups as $id => $g ) {
117 // for multiple will only show the things we want
118 if(in_array($id, $selected) xor $reverse) {
119 $out .= '<option value="'.$id.'">'.$g->getExpandedName()."</option>\n";
123 if(in_array($id, $selected)) { $out .= 'selected="selected" '; }
124 $out .= 'value="'.$id.'">'.$g->getExpandedName()."</option>\n";
127 $out .= "</select>\n";
131 /** Build a select with all existent rights
132 * @param array $selected Names(?) of user rights that should be selected.
133 * @return string HTML select.
135 function HTMLSelectRights($selected='') {
136 global $wgAvailableRights;
137 $out = '<select name="editgroup-getrights[]" multiple="multiple">';
138 $groupRights = explode(',',$selected);
140 foreach($wgAvailableRights as $right) {
142 // check box when right exist
143 if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
144 else { $selected = ''; }
146 $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
148 $out .= "</select>\n";