Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/287442

Change subject: OOUIHTMLForm: Don't output an empty hidden LabelWidget if not 
needed
......................................................................

OOUIHTMLForm: Don't output an empty hidden LabelWidget if not needed

The hidden element is only needed if either a header is set or the form
has errors. If both does not apply, the element isn't needed and should
be omitted instead of hidden with display:none.

It's also not needed to add a LabelWidget for the header, if the form has
errors, only, but no header (which would result in an empty space between
the header and the fieldset legend).

Follow up: Ifbf38878d41906184f97169b22002f788711a311

Change-Id: I4ffefdc50d435590d25a7dfc202228920dd801ae
---
M includes/htmlform/OOUIHTMLForm.php
M resources/src/mediawiki/mediawiki.htmlform.ooui.css
2 files changed, 31 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/42/287442/1

diff --git a/includes/htmlform/OOUIHTMLForm.php 
b/includes/htmlform/OOUIHTMLForm.php
index 7a2ed50..908d97b 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -100,7 +100,7 @@
                        if ( $isBadIE ) {
                                $label = $button['value'];
                        } elseif ( isset( $button['label-message'] ) ) {
-                               $label = new OOUI\HtmlSnippet( 
$this->getMessage( $button['label-message'] )->parse() );
+                               $label = new OOUI\HtmlSnippet( $this->msg( 
$button['label-message'] )->parse() );
                        } elseif ( isset( $button['label'] ) ) {
                                $label = $button['label'];
                        } elseif ( isset( $button['label-raw'] ) ) {
@@ -198,7 +198,18 @@
                }
 
                foreach ( $errors as &$error ) {
-                       $error = $this->getMessage( $error )->parse();
+                       if ( is_array( $error ) ) {
+                               $msg = array_shift( $error );
+                       } else {
+                               $msg = $error;
+                               $error = [];
+                       }
+                       // if the error is already a message object, don't use 
it as a message key
+                       if ( !$msg instanceof Message ) {
+                               $error = $this->msg( $msg, $error )->parse();
+                       } else {
+                               $error = $msg->parse();
+                       }
                        $error = new OOUI\HtmlSnippet( $error );
                }
 
@@ -221,22 +232,27 @@
                // FIXME This only works for forms with no subsections
                if ( $fieldset instanceof OOUI\FieldsetLayout ) {
                        $classes = [ 'mw-htmlform-ooui-header' ];
-                       if ( !$this->mHeader ) {
-                               $classes[] = 'mw-htmlform-ooui-header-empty';
-                       }
                        if ( $this->oouiErrors ) {
                                $classes[] = 'mw-htmlform-ooui-header-errors';
                        }
-                       $fieldset->addItems( [
-                               new OOUI\FieldLayout(
-                                       new OOUI\LabelWidget( [ 'label' => new 
OOUI\HtmlSnippet( $this->mHeader ) ] ),
-                                       [
-                                               'align' => 'top',
-                                               'errors' => $this->oouiErrors,
-                                               'classes' => $classes,
-                                       ]
-                               )
-                       ], 0 );
+                       if ( $this->mHeader || $this->oouiErrors ) {
+                               // if there's no header, don't create an 
(empty) LabelWidget, simply use a placeholder
+                               if ( $this->mHeader ) {
+                                       $element = new OOUI\LabelWidget( [ 
'label' => new OOUI\HtmlSnippet( $this->mHeader ) ] );
+                               } else {
+                                       $element = new OOUI\Widget( [] );
+                               }
+                               $fieldset->addItems( [
+                                       new OOUI\FieldLayout(
+                                               $element,
+                                               [
+                                                       'align' => 'top',
+                                                       'errors' => 
$this->oouiErrors,
+                                                       'classes' => $classes,
+                                               ]
+                                       )
+                               ], 0 );
+                       }
                }
                return $fieldset;
        }
diff --git a/resources/src/mediawiki/mediawiki.htmlform.ooui.css 
b/resources/src/mediawiki/mediawiki.htmlform.ooui.css
index 260fd37..cc59853 100644
--- a/resources/src/mediawiki/mediawiki.htmlform.ooui.css
+++ b/resources/src/mediawiki/mediawiki.htmlform.ooui.css
@@ -4,13 +4,7 @@
        margin: 1em 0;
 }
 
-.oo-ui-fieldLayout.mw-htmlform-ooui-header-empty,
-.oo-ui-fieldLayout.mw-htmlform-ooui-header-empty .oo-ui-fieldLayout-body {
-       display: none;
-}
-
 .oo-ui-fieldLayout.mw-htmlform-ooui-header-errors {
-       /* Override 'display: none' from above */
        display: block;
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/287442
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4ffefdc50d435590d25a7dfc202228920dd801ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to