<?php
/**
* This file contain a class to easily build HTML forms as well as custom
- * functions used by SpecialUserlevels.php and SpecialGrouplevels.php
+ * functions used by SpecialUserrights.php and SpecialGroups.php
* @package MediaWiki
*/
*/
class HTMLForm {
/** name of our form. Used as prefix for labels */
- var $mName;
+ var $mName, $mRequest;
+
+ function HTMLForm( &$request ) {
+ $this->mRequest = $request;
+ }
/**
* @access private
* @param boolean $checked Set true to check the box (default False).
*/
function checkbox( $varname, $checked=false ) {
- $checked = isset( $_POST[$varname] ) && $_POST[$varname] ;
+ if ( $this->mRequest->wasPosted() && !is_null( $this->mRequest->getVal( $varname ) ) ) {
+ $checked = $this->mRequest->getCheck( $varname );
+ }
return "<div><input type='checkbox' value=\"1\" id=\"{$varname}\" name=\"wpOp{$varname}\"" .
( $checked ? ' checked="checked"' : '' ) .
" /><label for=\"{$varname}\">". wfMsg( $this->mName.'-'.$varname ) .
"</label></div>\n";
}
- /**
+ /**
* @access private
* @param string $varname Name of the textbox.
* @param string $value Optional value (default empty)
* @param integer $size Optional size of the textbox (default 20)
*/
function textbox( $varname, $value='', $size=20 ) {
- $value = isset( $_POST[$varname] ) ? $_POST[$varname] : $value;
+ if ( $this->mRequest->wasPosted() ) {
+ $value = $this->mRequest->getText( $varname, $value );
+ }
+ $value = htmlspecialchars( $value );
return "<div><label>". wfMsg( $this->mName.'-'.$varname ) .
"<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.
}
return $this->fieldset( $this->mName.'-'.$varname, $s );
}
-
- /**
+
+ /**
* @access private
* @param string $varname Name of the textareabox.
* @param string $value Optional value (default empty)
* @param integer $size Optional size of the textarea (default 20)
*/
function textareabox ( $varname, $value='', $size=20 ) {
- $value = isset( $_POST[$varname] ) ? $_POST[$varname] : $value;
+ if ( $this->mRequest->wasPosted() ) {
+ $value = $this->mRequest->getText( $varname, $value );
+ }
+ $value = htmlspecialchars( $value );
return '<div><label>'.wfMsg( $this->mName.'-'.$varname ).
"<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)
*/
function arraybox( $varname , $size=20 ) {
$s = '';
- if ( isset( $_POST[$varname] ) && is_array( $_POST[$varname] ) ) {
- foreach ( $_POST[$varname] as $index=>$element ) {
- $s .= $element."\n";
+ if ( $this->mRequest->wasPosted() ) {
+ $arr = $this->mRequest->getArray( $varname );
+ if ( is_array( $arr ) ) {
+ foreach ( $_POST[$varname] as $index=>$element ) {
+ $s .= htmlspecialchars( $element )."\n";
+ }
}
}
return "<div><label>".wfMsg( $this->mName.'-'.$varname ).
} // end class
-// functions used by SpecialUserlevels & SpecialGrouplevels
+// functions used by SpecialUserrights.php and SpecialGroups.php
-/** Build a select with all existent groups
+/** Build a select with all defined 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 array $selected Array of element selected when posted. Only multiples will 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 integer $size Number of elements 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) {
+function HTMLSelectGroups($selectname, $selectmsg, $selected=array(), $multiple=false, $size=6, $reverse=false) {
+ $groups = User::getAllGroups();
+ $out = htmlspecialchars( wfMsg( $selectmsg ) );
+
+ if( $multiple ) {
+ $attribs = array(
+ 'name' => $selectname . '[]',
+ 'multiple'=> 'multiple',
+ 'size' => $size );
+ } else {
+ $attribs = array( 'name' => $selectname );
+ }
+ $out .= wfElement( 'select', $attribs, null );
+
+ foreach( $groups as $group ) {
+ $attribs = array( 'value' => $group );
+ 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";
+ if( !in_array( $group, $selected ) xor $reverse ) {
+ continue;
}
} else {
- $out .= '<option ';
- if(in_array($g->group_id, $selected)) { $out .= 'selected="selected" '; }
- $out .= 'value="'.$g->group_id.'">'.$g->group_name."</option>\n";
+ if( in_array( $group, $selected ) ) {
+ $attribs['selected'] = 'selected';
+ }
}
+ $out .= wfElement( 'option', $attribs, User::getGroupName( $group ) ) . "\n";
}
+
$out .= "</select>\n";
return $out;
}
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";