Merge "Show a warning in edit preview when a template loop is detected"
[lhc/web/wiklou.git] / includes / htmlform / fields / HTMLSelectOrOtherField.php
index bb41079..a009b28 100644 (file)
@@ -64,8 +64,80 @@ class HTMLSelectOrOtherField extends HTMLTextField {
                return "$select<br />\n$textbox";
        }
 
+       protected function shouldInfuseOOUI() {
+               return true;
+       }
+
+       protected function getOOUIModules() {
+               return [ 'mediawiki.widgets.SelectWithInputWidget' ];
+       }
+
        public function getInputOOUI( $value ) {
-               return false;
+               $this->mParent->getOutput()->addModuleStyles( 'mediawiki.widgets.SelectWithInputWidget.styles' );
+
+               $valInSelect = false;
+               if ( $value !== false ) {
+                       $value = strval( $value );
+                       $valInSelect = in_array(
+                               $value, HTMLFormField::flattenOptions( $this->getOptions() ), true
+                       );
+               }
+
+               # DropdownInput
+               $dropdownAttribs = [
+                       'id' => $this->mID,
+                       'name' => $this->mName,
+                       'options' => $this->getOptionsOOUI(),
+                       'value' => $valInSelect ? $value : 'other',
+                       'class' => [ 'mw-htmlform-select-or-other' ],
+               ];
+
+               $allowedParams = [
+                       'disabled',
+                       'tabindex',
+               ];
+
+               $dropdownAttribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
+
+               # TextInput
+               $textAttribs = [
+                       'id' => $this->mID . '-other',
+                       'name' => $this->mName . '-other',
+                       'size' => $this->getSize(),
+                       'value' => $valInSelect ? '' : $value,
+               ];
+
+               $allowedParams = [
+                       'required',
+                       'autofocus',
+                       'multiple',
+                       'disabled',
+                       'tabindex',
+                       'maxlength',
+               ];
+
+               $textAttribs += OOUI\Element::configFromHtmlAttributes(
+                       $this->getAttributes( $allowedParams )
+               );
+
+               if ( $this->mClass !== '' ) {
+                       $textAttribs['classes'] = [ $this->mClass ];
+               }
+               if ( $this->mPlaceholder !== '' ) {
+                       $textAttribs['placeholder'] = $this->mPlaceholder;
+               }
+
+               return $this->getInputWidget( [
+                       'textinput' => $textAttribs,
+                       'dropdowninput' => $dropdownAttribs,
+                       'or' => true,
+               ] );
+       }
+
+       public function getInputWidget( $params ) {
+               return new Mediawiki\Widget\SelectWithInputWidget( $params );
        }
 
        /**