Merge "(bug 47070) check content model namespace on import."
[lhc/web/wiklou.git] / includes / htmlform / HTMLMultiSelectField.php
index f1b058d..09576d4 100644 (file)
@@ -1,9 +1,9 @@
 <?php
+
 /**
  * Multi-select field
  */
 class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable {
-
        function validate( $value, $alldata ) {
                $p = parent::validate( $value, $alldata );
 
@@ -11,13 +11,13 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                        return $p;
                }
 
-               if ( ! is_array( $value ) ) {
+               if ( !is_array( $value ) ) {
                        return false;
                }
 
                # If all options are valid, array_intersect of the valid options
                # and the provided options will return the provided options.
-               $validOptions = HTMLFormField::flattenOptions( $this->mParams[ 'options' ] );
+               $validOptions = HTMLFormField::flattenOptions( $this->mParams['options'] );
 
                $validValues = array_intersect( $value, $validOptions );
                if ( count( $validValues ) == count( $value ) ) {
@@ -28,7 +28,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        function getInputHTML( $value ) {
-               $html = $this->formatOptions( $this->mParams[ 'options' ], $value );
+               $html = $this->formatOptions( $this->mParams['options'], $value );
 
                return $html;
        }
@@ -36,11 +36,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        function formatOptions( $options, $value ) {
                $html = '';
 
-               $attribs = array();
-
-               if ( ! empty( $this->mParams[ 'disabled' ] ) ) {
-                       $attribs[ 'disabled' ] = 'disabled';
-               }
+               $attribs = $this->getAttributes( array( 'disabled', 'tabindex' ) );
 
                foreach ( $options as $label => $info ) {
                        if ( is_array( $info ) ) {
@@ -49,10 +45,22 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                        } else {
                                $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
 
-                               $checkbox = Xml::check( $this->mName . '[]', in_array( $info, $value, true ), $attribs + $thisAttribs );
-                               $checkbox .= '&#160;' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
-
-                               $html .= ' ' . Html::rawElement( 'div', array( 'class' => 'mw-htmlform-flatlist-item' ), $checkbox );
+                               $checkbox = Xml::check(
+                                       $this->mName . '[]',
+                                       in_array( $info, $value, true ),
+                                       $attribs + $thisAttribs
+                               );
+                               $checkbox .= '&#160;' . Html::rawElement(
+                                       'label',
+                                       array( 'for' => "{$this->mID}-$info" ),
+                                       $label
+                               );
+
+                               $html .= ' ' . Html::rawElement(
+                                       'div',
+                                       array( 'class' => 'mw-htmlform-flatlist-item' ),
+                                       $checkbox
+                               );
                        }
                }
 
@@ -94,11 +102,11 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        function filterDataForSubmit( $data ) {
-               $options = HTMLFormField::flattenOptions( $this->mParams[ 'options' ] );
+               $options = HTMLFormField::flattenOptions( $this->mParams['options'] );
 
                $res = array();
                foreach ( $options as $opt ) {
-                       $res[ "$opt" ] = in_array( $opt, $data );
+                       $res["$opt"] = in_array( $opt, $data );
                }
 
                return $res;
@@ -107,4 +115,4 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        protected function needsLabel() {
                return false;
        }
-}
\ No newline at end of file
+}