3 * This file contain a class to easily build HTML forms as well as custom
4 * functions used by SpecialUserlevels.php and SpecialGrouplevels.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 SpecialUserlevels & SpecialGrouplevels
100 /** Build a select with all existent 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, $selected=array(), $multiple=false, $size=6, $reverse=false) {
108 $dbr =& wfGetDB( DB_SLAVE
);
109 $group = $dbr->tableName( 'group' );
110 $sql = "SELECT group_id, group_name FROM $group";
111 $res = $dbr->query($sql,'wfSpecialAdmin');
113 $out = wfMsg($selectname);
114 $out .= '<select name="'.$selectname;
115 if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
118 while($g = $dbr->fetchObject( $res ) ) {
120 // for multiple will only show the things we want
121 if(in_array($g->group_id
, $selected) xor $reverse) {
122 $out .= '<option value="'.$g->group_id
.'">'.$g->group_name
."</option>\n";
126 if(in_array($g->group_id
, $selected)) { $out .= 'selected="selected" '; }
127 $out .= 'value="'.$g->group_id
.'">'.$g->group_name
."</option>\n";
130 $out .= "</select>\n";
134 /** Build a select with all existent rights
135 * @param array $selected Names(?) of user rights that should be selected.
136 * @return string HTML select.
138 function HTMLSelectRights($selected='') {
139 global $wgAvailableRights;
140 $out = '<select name="editgroup-getrights[]" multiple="multiple">';
141 $groupRights = explode(',',$selected);
143 foreach($wgAvailableRights as $right) {
145 // check box when right exist
146 if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
147 else { $selected = ''; }
149 $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
151 $out .= "</select>\n";