X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fhtmlform%2FHTMLFormField.php;h=8604ba2098da405a005f7532e0ca3d8cee4179ba;hb=e3f6c10d87732c0c8a9bbd7bb57b6c964b92e29a;hp=b47bfa06cae1a39a5c5ef6ddd7fd3f64d63a716c;hpb=0c9f05bff8529a9a4f5e12140bee959edafa38c9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index b47bfa06ca..8604ba2098 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( '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.