Merge "HTMLForm: Use OOUI\Element::configFromHtmlAttributes instead of rolling our...
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 10 Mar 2016 21:33:28 +0000 (21:33 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 10 Mar 2016 21:33:28 +0000 (21:33 +0000)
12 files changed:
includes/htmlform/HTMLAutoCompleteSelectField.php
includes/htmlform/HTMLButtonField.php
includes/htmlform/HTMLCheckField.php
includes/htmlform/HTMLCheckMatrix.php
includes/htmlform/HTMLComboboxField.php
includes/htmlform/HTMLFormField.php
includes/htmlform/HTMLFormFieldWithButton.php
includes/htmlform/HTMLMultiSelectField.php
includes/htmlform/HTMLRadioField.php
includes/htmlform/HTMLSelectField.php
includes/htmlform/HTMLTextAreaField.php
includes/htmlform/HTMLTextField.php

index 1f077a4..6606ca3 100644 (file)
@@ -101,11 +101,11 @@ class HTMLAutoCompleteSelectField extends HTMLTextField {
        }
 
        // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
-       public function getAttributes( array $list, array $mappings = null ) {
+       public function getAttributes( array $list ) {
                $attribs = [
                        'type' => 'text',
                        'data-autocomplete' => FormatJson::encode( array_keys( $this->autocomplete ) ),
-               ] + parent::getAttributes( $list, $mappings );
+               ] + parent::getAttributes( $list );
 
                if ( $this->getOptions() ) {
                        $attribs['data-hide-if'] = FormatJson::encode(
index 211089f..0b07765 100644 (file)
@@ -104,7 +104,9 @@ class HTMLButtonField extends HTMLFormField {
                        'id' => $this->mID,
                        'flags' => $this->mFlags,
                        'useInputTag' => $this->isBadIE(),
-               ] + $this->getAttributes( [ 'disabled', 'tabindex' ], [ 'tabindex' => 'tabIndex' ] ) );
+               ] + OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( [ 'disabled', 'tabindex' ] )
+               ) );
        }
 
        protected function needsLabel() {
index 13f30c2..a59b15e 100644 (file)
@@ -56,9 +56,8 @@ class HTMLCheckField extends HTMLFormField {
                $attr['id'] = $this->mID;
                $attr['name'] = $this->mName;
 
-               $attr += $this->getAttributes(
-                       [ 'disabled', 'tabindex' ],
-                       [ 'tabindex' => 'tabIndex' ]
+               $attr += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( [ 'disabled', 'tabindex' ] )
                );
 
                if ( $this->mClass !== '' ) {
index 6a4bec8..9f67233 100644 (file)
@@ -85,13 +85,7 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
                $rows = $this->mParams['rows'];
                $columns = $this->mParams['columns'];
 
-               $mappings = [];
-
-               if ( $this->mParent instanceof OOUIHTMLForm ) {
-                       $mappings['tabindex'] = 'tabIndex';
-               }
-
-               $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ], $mappings );
+               $attribs = $this->getAttributes( [ 'disabled', 'tabindex' ] );
 
                // Build the column headers
                $headerContents = Html::rawElement( 'td', [], '&#160;' );
@@ -156,8 +150,9 @@ class HTMLCheckMatrix extends HTMLFormField implements HTMLNestedFilterable {
                        return new OOUI\CheckboxInputWidget( [
                                'name' => "{$this->mName}[]",
                                'selected' => $checked,
-                               'value' => $attribs['value'],
-                       ] + $attribs );
+                       ] + OOUI\Element::configFromHtmlAttributes(
+                               $attribs
+                       ) );
                } else {
                        $checkbox = Xml::check( "{$this->mName}[]", $checked, $attribs );
                        if ( $this->mParent->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) {
index a0f248f..778aedb 100644 (file)
  */
 class HTMLComboboxField extends HTMLTextField {
        // FIXME Ewww, this shouldn't be adding any attributes not requested in $list :(
-       public function getAttributes( array $list, array $mappings = null ) {
+       public function getAttributes( array $list ) {
                $attribs = [
                        'type' => 'text',
                        'list' => $this->mName . '-datalist',
-               ] + parent::getAttributes( $list, $mappings );
+               ] + parent::getAttributes( $list );
 
                return $attribs;
        }
@@ -36,7 +36,9 @@ class HTMLComboboxField extends HTMLTextField {
        function getInputOOUI( $value ) {
                $disabled = false;
                $allowedParams = [ 'tabindex' ];
-               $attribs = $this->getAttributes( $allowedParams, [ 'tabindex' => 'tabIndex' ] );
+               $attribs = OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
 
                if ( $this->mClass !== '' ) {
                        $attribs['classes'] = [ $this->mClass ];
index ebbe323..6e5d656 100644 (file)
@@ -912,45 +912,23 @@ abstract class HTMLFormField {
                return Linker::tooltipAndAccesskeyAttribs( $this->mParams['tooltip'] );
        }
 
-       /**
-        * Get a translated key if necessary.
-        * @param array|null $mappings Array of mappings, 'original' => 'translated'
-        * @param string $key
-        * @return string
-        */
-       protected function getMappedKey( $mappings, $key ) {
-               if ( !is_array( $mappings ) ) {
-                       return $key;
-               }
-
-               if ( !empty( $mappings[$key] ) ) {
-                       return $mappings[$key];
-               }
-
-               return $key;
-       }
-
        /**
         * Returns the given attributes from the parameters
         *
         * @param array $list List of attributes to get
-        * @param array $mappings Optional - Key/value map of attribute names to use
-        *   instead of the ones passed in.
         * @return array Attributes
         */
-       public function getAttributes( array $list, array $mappings = null ) {
+       public function getAttributes( array $list ) {
                static $boolAttribs = [ 'disabled', 'required', 'autofocus', 'multiple', 'readonly' ];
 
                $ret = [];
                foreach ( $list as $key ) {
-                       $mappedKey = $this->getMappedKey( $mappings, $key );
-
                        if ( in_array( $key, $boolAttribs ) ) {
                                if ( !empty( $this->mParams[$key] ) ) {
-                                       $ret[$mappedKey] = $mappedKey;
+                                       $ret[$key] = '';
                                }
                        } elseif ( isset( $this->mParams[$key] ) ) {
-                               $ret[$mappedKey] = $this->mParams[$key];
+                               $ret[$key] = $this->mParams[$key];
                        }
                }
 
index 1ebd280..bcb07bd 100644 (file)
@@ -59,7 +59,9 @@ class HTMLFormFieldWithButton extends HTMLFormField {
                        'type' => $this->mButtonType,
                        'label' => $this->mButtonValue,
                        'flags' => $this->mButtonFlags,
-               ] );
+               ] + OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( [ 'disabled', 'tabindex' ] )
+               ) );
        }
 
        /**
index 251bb05..1aaa3e8 100644 (file)
@@ -72,8 +72,9 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                                new OOUI\CheckboxInputWidget( [
                                        'name' => "{$this->mName}[]",
                                        'selected' => $checked,
-                                       'value' => $attribs['value'],
-                               ] + $attribs ),
+                               ] + OOUI\Element::configFromHtmlAttributes(
+                                       $attribs
+                               ) ),
                                [
                                        'label' => $label,
                                        'align' => 'inline',
index ecca6ff..12a8a1f 100644 (file)
@@ -53,7 +53,9 @@ class HTMLRadioField extends HTMLFormField {
                        'value' => $value,
                        'options' => $options,
                        'classes' => 'mw-htmlform-flatlist-item',
-               ] + $this->getAttributes( [ 'disabled', 'tabindex' ], [ 'tabindex' => 'tabIndex' ] ) );
+               ] + OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( [ 'disabled', 'tabindex' ] )
+               ) );
        }
 
        function formatOptions( $options, $value ) {
index 6191665..b6ad46c 100644 (file)
@@ -45,7 +45,9 @@ class HTMLSelectField extends HTMLFormField {
        function getInputOOUI( $value ) {
                $disabled = false;
                $allowedParams = [ 'tabindex' ];
-               $attribs = $this->getAttributes( $allowedParams, [ 'tabindex' => 'tabIndex' ] );
+               $attribs = OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
 
                if ( $this->mClass !== '' ) {
                        $attribs['classes'] = [ $this->mClass ];
index b05fd7c..973f1cb 100644 (file)
@@ -66,10 +66,9 @@ class HTMLTextAreaField extends HTMLFormField {
                        'autofocus',
                ];
 
-               $attribs += $this->getAttributes( $allowedParams, [
-                       'tabindex' => 'tabIndex',
-                       'readonly' => 'readOnly',
-               ] );
+               $attribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
 
                return new OOUI\TextInputWidget( [
                        'id' => $this->mID,
index fb7584b..4d5bcab 100644 (file)
@@ -107,11 +107,9 @@ class HTMLTextField extends HTMLFormField {
                        'type',
                ];
 
-               $attribs += $this->getAttributes( $allowedParams, [
-                       'maxlength' => 'maxLength',
-                       'readonly' => 'readOnly',
-                       'tabindex' => 'tabIndex',
-               ] );
+               $attribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
 
                $type = $this->getType( $attribs );