jenkins-bot has submitted this change and it was merged.

Change subject: OOUIHTMLForm: Display errors in a nicer way, part 2
......................................................................


OOUIHTMLForm: Display errors in a nicer way, part 2

Now we also handle the form-wide errors, putting them in the FieldLayout
that contains the form's header.

Follow-up to I860a96858c4fcac62d63b46e35a9153f22c0a9c9.

Bug: T98894
Change-Id: Ifbf38878d41906184f97169b22002f788711a311
---
M includes/htmlform/OOUIHTMLForm.php
M resources/src/mediawiki/mediawiki.htmlform.ooui.css
2 files changed, 64 insertions(+), 4 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  Florianschmidtwelzow: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/htmlform/OOUIHTMLForm.php 
b/includes/htmlform/OOUIHTMLForm.php
index 37badab..84d40a1 100644
--- a/includes/htmlform/OOUIHTMLForm.php
+++ b/includes/htmlform/OOUIHTMLForm.php
@@ -25,6 +25,8 @@
  * Compact stacked vertical format for forms, implemented using OOUI widgets.
  */
 class OOUIHTMLForm extends HTMLForm {
+       private $oouiErrors;
+
        public function __construct( $descriptor, $context = null, 
$messagePrefix = '' ) {
                parent::__construct( $descriptor, $context, $messagePrefix );
                $this->getOutput()->enableOOUI();
@@ -125,11 +127,43 @@
        }
 
        /**
-        * @param string|array|Status $errors
+        * @param string|array|Status $err
         * @return string
         */
-       function getErrors( $errors ) {
-               // TODO Write me!
+       function getErrors( $err ) {
+               if ( !$err ) {
+                       $errors = array();
+               } else if ( $err instanceof Status ) {
+                       if ( $err->isOK() ) {
+                               $errors = array();
+                       } else {
+                               $errors = $err->getErrorsByType( 'error' );
+                               foreach ( $errors as &$error ) {
+                                       // Input:  array( 'message' => 'foo', 
'errors' => array( 'a', 'b', 'c' ) )
+                                       // Output: array( 'foo', 'a', 'b', 'c' )
+                                       $error = array_merge( array( 
$error['message'] ), $error['params'] );
+                               }
+                       }
+               } else {
+                       $errors = $err;
+                       if ( !is_array( $errors ) ) {
+                               $errors = array( $errors );
+                       }
+               }
+
+               foreach ( $errors as &$error ) {
+                       if ( is_array( $error ) ) {
+                               $msg = array_shift( $error );
+                       } else {
+                               $msg = $error;
+                               $error = array();
+                       }
+                       $error = $this->msg( $msg, $error )->parse();
+                       $error = new OOUI\HtmlSnippet( $error );
+               }
+
+               // Used in getBody()
+               $this->oouiErrors = $errors;
                return '';
        }
 
@@ -146,7 +180,23 @@
                $fieldset = parent::getBody();
                // FIXME This only works for forms with no subsections
                if ( $fieldset instanceof OOUI\FieldsetLayout ) {
-                       $fieldset->group->prependContent( new OOUI\HtmlSnippet( 
$this->mHeader ) );
+                       $classes = array( 'mw-htmlform-ooui-header' );
+                       if ( !$this->mHeader ) {
+                               $classes[] = 'mw-htmlform-ooui-header-empty';
+                       }
+                       if ( $this->oouiErrors ) {
+                               $classes[] = 'mw-htmlform-ooui-header-errors';
+                       }
+                       $fieldset->addItems( array(
+                               new OOUI\FieldLayout(
+                                       new OOUI\LabelWidget( array( 'label' => 
new OOUI\HtmlSnippet( $this->mHeader ) ) ),
+                                       array(
+                                               '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 31d9854..309eb34 100644
--- a/resources/src/mediawiki/mediawiki.htmlform.ooui.css
+++ b/resources/src/mediawiki/mediawiki.htmlform.ooui.css
@@ -5,6 +5,16 @@
        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;
+}
+
 .mw-htmlform-ooui .mw-htmlform-submit-buttons {
        margin-top: 1em;
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifbf38878d41906184f97169b22002f788711a311
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Edokter <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to