* Yummie ? : syntax.
[lhc/web/wiklou.git] / includes / HTMLForm.php
index a13831f..e1bb123 100644 (file)
@@ -1,4 +1,10 @@
 <?php
+/**
+ * This file contain a class to easily build HTML forms as well as custom
+ * functions used by SpecialUserlevels.php and SpecialGrouplevels.php
+ * @package MediaWiki
+ */
+
 /**
  * Class to build various forms
  *
@@ -20,7 +26,7 @@ class HTMLForm {
                        $content . "\n</fieldset>\n";
        }
 
-       /*
+       /**
         * @access private
         * @param string $varname Name of the checkbox.
         * @param boolean $checked Set true to check the box (default False).
@@ -33,7 +39,7 @@ class HTMLForm {
                        "</label></div>\n";
        }
 
-       /* 
+       /** 
         * @access private
         * @param string $varname Name of the textbox.
         * @param string $value Optional value (default empty)
@@ -45,7 +51,7 @@ class HTMLForm {
                        "<input type='text' name=\"{$varname}\" value=\"{$value}\" size=\"{$size}\" /></label></div>\n";
        }
 
-       /* 
+       /** 
         * @access private
         * @param string $varname Name of the radiobox.
         * @param array $fields Various fields.
@@ -59,7 +65,7 @@ class HTMLForm {
                return $this->fieldset( $this->mName.'-'.$varname, $s );
        }
        
-       /* 
+       /** 
         * @access private
         * @param string $varname Name of the textareabox.
         * @param string $value Optional value (default empty)
@@ -71,7 +77,7 @@ class HTMLForm {
                       "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">$value</textarea></label></div>\n";
        }
 
-       /* 
+       /** 
         * @access private
         * @param string $varname Name of the arraybox.
         * @param integer $size Optional size of the textarea (default 20)
@@ -86,5 +92,63 @@ class HTMLForm {
                return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
                        "<textarea name=\"{$varname}\" rows=\"5\" cols=\"{$size}\">{$s}</textarea>\n";
        }
+} // end class
+
+
+// functions used by SpecialUserlevels & SpecialGrouplevels
+
+/** Build a select with all existent groups
+ * @param string $selectname Name of this element. Name of form is automaticly prefixed.
+ * @param array $selected Array of element selected when posted. Multiples will only show them.
+ * @param boolean $multiple A multiple elements select.
+ * @param integer $size Number of element to be shown ignored for non multiple (default 6).
+ * @param boolean $reverse If true, multiple select will hide selected elements (default false).
+*/
+function HTMLSelectGroups($selectname, $selected=array(), $multiple=false, $size=6, $reverse=false) {
+       $dbr =& wfGetDB( DB_SLAVE );
+       $group = $dbr->tableName( 'group' );
+       $sql = "SELECT group_id, group_name FROM $group";
+       $res = $dbr->query($sql,'wfSpecialAdmin');
+       
+       $out = wfMsg($selectname);
+       $out .= '<select name="'.$selectname;
+       if($multiple) { $out.='[]" multiple="multiple" size="'.$size; }
+       $out.= "\">\n";
+       
+       while($g = $dbr->fetchObject( $res ) ) {
+               if($multiple) {
+                       // for multiple will only show the things we want
+                       if(in_array($g->group_id, $selected) xor $reverse) { 
+                               $out .= '<option value="'.$g->group_id.'">'.$g->group_name."</option>\n";
+                       }
+               } else {
+                       $out .= '<option ';
+                       if(in_array($g->group_id, $selected)) { $out .= 'selected="selected" '; }
+                       $out .= 'value="'.$g->group_id.'">'.$g->group_name."</option>\n";
+               }
+       }
+       $out .= "</select>\n";
+       return $out;
+}
+
+/** Build a select with all existent rights
+ * @param array $selected Names(?) of user rights that should be selected.
+ * @return string HTML select.
+ */
+function HTMLSelectRights($selected='') {
+       global $wgAvailableRights;
+       $out = '<select name="editgroup-getrights[]" multiple="multiple">';
+       $groupRights = explode(',',$selected);
+       
+       foreach($wgAvailableRights as $right) {
+       
+               // check box when right exist
+               if(in_array($right, $groupRights)) { $selected = 'selected="selected" '; }
+               else { $selected = ''; }
+                                       
+               $out .= '<option value="'.$right.'" '.$selected.'>'.$right."</option>\n";
+       }
+       $out .= "</select>\n";
+       return $out;
 }
 ?>