X-Git-Url: https://git.heureux-cyclage.org/w/index.php?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLFormField.php;h=4afdea76f830fe4a48f274fe93218879aa11a344;hb=53779578b44575ef91feb3fad488f09b52f737d7;hp=3319d3b86a02a5da4badc2ab9aae98f95ba1b333;hpb=46a3fc8b68d5636deba3fee872f3e66698129608;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 3319d3b86a..4afdea76f8 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -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( 'mediawiki.htmlform.ooui' ); + $preloadModules = true; $config['classes'][] = 'mw-htmlform-field-autoinfuse'; } @@ -638,10 +636,17 @@ abstract class HTMLFormField { } if ( $this->mHideIf ) { - $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' ); + $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 ); } @@ -677,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. @@ -806,7 +821,7 @@ abstract class HTMLFormField { /** * Determine the help text to display * @since 1.20 - * @return string HTML + * @return string|null HTML */ public function getHelpText() { $helptext = null;