Merge ""spellcheck" attribute for HTMLForm "text" and "textarea""
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 25 Jun 2015 10:17:54 +0000 (10:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 25 Jun 2015 10:17:54 +0000 (10:17 +0000)
1  2 
includes/htmlform/HTMLTextAreaField.php
includes/htmlform/HTMLTextField.php

@@@ -12,11 -12,21 +12,21 @@@ class HTMLTextAreaField extends HTMLFor
                return isset( $this->mParams['rows'] ) ? $this->mParams['rows'] : static::DEFAULT_ROWS;
        }
  
+       function getSpellCheck() {
+               $val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
+               if( is_bool( $val ) ) {
+                       // "spellcheck" attribute literally requires "true" or "false" to work.
+                       return $val === true ? 'true' : 'false';
+               }
+               return null;
+       }
        function getInputHTML( $value ) {
                $attribs = array(
                                'id' => $this->mID,
                                'cols' => $this->getCols(),
                                'rows' => $this->getRows(),
+                               'spellcheck' => $this->getSpellCheck(),
                        ) + $this->getTooltipAndAccessKey();
  
                if ( $this->mClass !== '' ) {
                $attribs += $this->getAttributes( $allowedParams );
                return Html::textarea( $this->mName, $value, $attribs );
        }
 +
 +      function getInputOOUI( $value ) {
 +              $attribs = $this->getTooltipAndAccessKey();
 +
 +              if ( $this->mClass !== '' ) {
 +                      $attribs['classes'] = array( $this->mClass );
 +              }
 +
 +              $allowedParams = array(
 +                      'placeholder',
 +                      'tabindex',
 +                      'disabled',
 +                      'readonly',
 +                      'required',
 +                      'autofocus',
 +              );
 +
 +              $attribs += $this->getAttributes( $allowedParams, array(
 +                      'tabindex' => 'tabIndex',
 +                      'readonly' => 'readOnly',
 +              ) );
 +
 +              return new OOUI\TextInputWidget( array(
 +                      'id' => $this->mID,
 +                      'name' => $this->mName,
 +                      'multiline' => true,
 +                      'value' => $value,
 +              ) + $attribs );
 +      }
  }
@@@ -5,6 -5,15 +5,15 @@@ class HTMLTextField extends HTMLFormFie
                return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
        }
  
+       function getSpellCheck() {
+               $val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
+               if( is_bool( $val ) ) {
+                       // "spellcheck" attribute literally requires "true" or "false" to work.
+                       return $val === true ? 'true' : 'false';
+               }
+               return null;
+       }
        function getInputHTML( $value ) {
                $attribs = array(
                                'id' => $this->mID,
@@@ -12,6 -21,7 +21,7 @@@
                                'size' => $this->getSize(),
                                'value' => $value,
                                'dir' => $this->mDir,
+                               'spellcheck' => $this->getSpellCheck(),
                        ) + $this->getTooltipAndAccessKey();
  
                if ( $this->mClass !== '' ) {
                $attribs += $this->getAttributes( $allowedParams );
  
                # Extract 'type'
 +              $type = $this->getType( $attribs );
 +              return Html::input( $this->mName, $value, $type, $attribs );
 +      }
 +
 +      protected function getType( &$attribs ) {
                $type = isset( $attribs['type'] ) ? $attribs['type'] : 'text';
                unset( $attribs['type'] );
  
                        }
                }
  
 -              return Html::input( $this->mName, $value, $type, $attribs );
 +              return $type;
 +      }
 +
 +      function getInputOOUI( $value ) {
 +              $attribs = $this->getTooltipAndAccessKey();
 +
 +              if ( $this->mClass !== '' ) {
 +                      $attribs['classes'] = array( $this->mClass );
 +              }
 +
 +              # @todo Enforce pattern, step, required, readonly on the server side as
 +              # well
 +              $allowedParams = array(
 +                      'autofocus',
 +                      'autosize',
 +                      'disabled',
 +                      'flags',
 +                      'indicator',
 +                      'maxlength',
 +                      'placeholder',
 +                      'readonly',
 +                      'required',
 +                      'tabindex',
 +                      'type',
 +              );
 +
 +              $attribs += $this->getAttributes( $allowedParams, array(
 +                      'maxlength' => 'maxLength',
 +                      'readonly' => 'readOnly',
 +                      'tabindex' => 'tabIndex',
 +              ) );
 +
 +              $type = $this->getType( $attribs );
 +
 +              return new OOUI\TextInputWidget( array(
 +                      'id' => $this->mID,
 +                      'name' => $this->mName,
 +                      'value' => $value,
 +                      'type' => $type,
 +              ) + $attribs );
        }
  }