Merge "Fix importation of weird file names in importTextFiles.php"
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormField.php
index b47bfa0..8604ba2 100644 (file)
@@ -61,7 +61,7 @@ abstract class HTMLFormField {
         * @return bool
         */
        public function canDisplayErrors() {
-               return true;
+               return $this->hasVisibleOutput();
        }
 
        /**
@@ -455,10 +455,6 @@ abstract class HTMLFormField {
                        $this->mFilterCallback = $params['filter-callback'];
                }
 
-               if ( isset( $params['flatlist'] ) ) {
-                       $this->mClass .= ' mw-htmlform-flatlist';
-               }
-
                if ( isset( $params['hidelabel'] ) ) {
                        $this->mShowEmptyLabels = false;
                }
@@ -606,7 +602,7 @@ abstract class HTMLFormField {
                }
 
                $fieldType = get_class( $this );
-               $helpText = $this->getHelpText();
+               $help = $this->getHelpText();
                $errors = $this->getErrorsRaw( $value );
                foreach ( $errors as &$error ) {
                        $error = new OOUI\HtmlSnippet( $error );
@@ -620,14 +616,16 @@ abstract class HTMLFormField {
                $config = [
                        'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ],
                        'align' => $this->getLabelAlignOOUI(),
-                       'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null,
+                       'help' => ( $help !== null && $help !== '' ) ? new OOUI\HtmlSnippet( $help ) : null,
                        'errors' => $errors,
                        'notices' => $notices,
                        'infusable' => $infusable,
                ];
 
+               $preloadModules = false;
+
                if ( $infusable && $this->shouldInfuseOOUI() ) {
-                       $this->mParent->getOutput()->addModules( 'oojs-ui-core' );
+                       $preloadModules = true;
                        $config['classes'][] = 'mw-htmlform-field-autoinfuse';
                }
 
@@ -637,6 +635,18 @@ abstract class HTMLFormField {
                        $config['label'] = new OOUI\HtmlSnippet( $label );
                }
 
+               if ( $this->mHideIf ) {
+                       $preloadModules = true;
+                       $config['hideIf'] = $this->mHideIf;
+               }
+
+               $config['modules'] = $this->getOOUIModules();
+
+               if ( $preloadModules ) {
+                       $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
+                       $this->mParent->getOutput()->addModules( $this->getOOUIModules() );
+               }
+
                return $this->getFieldLayoutOOUI( $inputField, $config );
        }
 
@@ -655,9 +665,9 @@ abstract class HTMLFormField {
        protected function getFieldLayoutOOUI( $inputField, $config ) {
                if ( isset( $this->mClassWithButton ) ) {
                        $buttonWidget = $this->mClassWithButton->getInputOOUI( '' );
-                       return new OOUI\ActionFieldLayout( $inputField, $buttonWidget, $config );
+                       return new HTMLFormActionFieldLayout( $inputField, $buttonWidget, $config );
                }
-               return new OOUI\FieldLayout( $inputField, $config );
+               return new HTMLFormFieldLayout( $inputField, $config );
        }
 
        /**
@@ -672,6 +682,16 @@ abstract class HTMLFormField {
                return $this->getHelpText() !== null;
        }
 
+       /**
+        * Get the list of extra ResourceLoader modules which must be loaded client-side before it's
+        * possible to infuse this field's OOjs UI widget.
+        *
+        * @return string[]
+        */
+       protected function getOOUIModules() {
+               return [];
+       }
+
        /**
         * Get the complete raw fields for the input, including help text,
         * labels, and whatever.