Merge "MimeAnalyzer: Add testcases for mp3 detection"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLSelectAndOtherField.php
index e75c2b2..38b487a 100644 (file)
@@ -11,7 +11,7 @@
  * @todo FIXME: If made 'required', only the text field should be compulsory.
  */
 class HTMLSelectAndOtherField extends HTMLSelectField {
-       function __construct( $params ) {
+       public function __construct( $params ) {
                if ( array_key_exists( 'other', $params ) ) {
                        // Do nothing
                } elseif ( array_key_exists( 'other-message', $params ) ) {
@@ -31,10 +31,9 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        $this->mOptions = [ $params['other'] => 'other' ] + $this->mOptions;
                }
                $this->mFlatOptions = self::flattenOptions( $this->getOptions() );
-
        }
 
-       function getInputHTML( $value ) {
+       public function getInputHTML( $value ) {
                $select = parent::getInputHTML( $value[1] );
 
                $textAttribs = [
@@ -64,8 +63,70 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                return "$select<br />\n$textbox";
        }
 
-       function getInputOOUI( $value ) {
-               return false;
+       protected function getOOUIModules() {
+               return [ 'mediawiki.widgets.SelectWithInputWidget' ];
+       }
+
+       public function getInputOOUI( $value ) {
+               $this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SelectWithInputWidget.styles' );
+
+               # TextInput
+               $textAttribs = [
+                       'id' => $this->mID . '-other',
+                       'name' => $this->mName . '-other',
+                       'size' => $this->getSize(),
+                       'class' => [ 'mw-htmlform-select-and-other-field' ],
+                       'data-id-select' => $this->mID,
+                       'value' => $value[2],
+               ];
+
+               $allowedParams = [
+                       'required',
+                       'autofocus',
+                       'multiple',
+                       'disabled',
+                       'tabindex',
+                       'maxlength',
+               ];
+
+               $textAttribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
+
+               if ( $this->mClass !== '' ) {
+                       $textAttribs['classes'] = [ $this->mClass ];
+               }
+
+               # DropdownInput
+               $dropdownInputAttribs = [
+                       'name' => $this->mName,
+                       'id' => $this->mID,
+                       'options' => $this->getOptionsOOUI(),
+                       'value' => $value[1],
+               ];
+
+               $allowedParams = [
+                       'tabindex',
+                       'disabled',
+               ];
+
+               $dropdownInputAttribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
+
+               if ( $this->mClass !== '' ) {
+                       $dropdownInputAttribs['classes'] = [ $this->mClass ];
+               }
+
+               return $this->getInputWidget( [
+                       'textinput' => $textAttribs,
+                       'dropdowninput' => $dropdownInputAttribs,
+                       'or' => false,
+               ] );
+       }
+
+       public function getInputWidget( $params ) {
+               return new Mediawiki\Widget\SelectWithInputWidget( $params );
        }
 
        /**
@@ -73,7 +134,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
         *
         * @return array("<overall message>","<select value>","<text field value>")
         */
-       function loadDataFromRequest( $request ) {
+       public function loadDataFromRequest( $request ) {
                if ( $request->getCheck( $this->mName ) ) {
                        $list = $request->getText( $this->mName );
                        $text = $request->getText( $this->mName . '-other' );
@@ -108,11 +169,11 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                return [ $final, $list, $text ];
        }
 
-       function getSize() {
+       public function getSize() {
                return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
        }
 
-       function validate( $value, $alldata ) {
+       public function validate( $value, $alldata ) {
                # HTMLSelectField forces $value to be one of the options in the select
                # field, which is not useful here.  But we do want the validation further up
                # the chain
@@ -126,7 +187,7 @@ class HTMLSelectAndOtherField extends HTMLSelectField {
                        && $this->mParams['required'] !== false
                        && $value[1] === ''
                ) {
-                       return $this->msg( 'htmlform-required' )->parse();
+                       return $this->msg( 'htmlform-required' );
                }
 
                return true;