Merge "mediawiki.special.userlogin.signup: Remove unnecessary field hiding code"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Jul 2016 11:17:43 +0000 (11:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Jul 2016 11:17:43 +0000 (11:17 +0000)
includes/htmlform/HTMLForm.php
includes/htmlform/HTMLFormField.php

index 2b7417e..a7acd8b 100644 (file)
  *    'help-messages'       -- array of message keys/objects. As above, each item can
  *                             be an array of msg key and then parameters.
  *                             Overwrites 'help'.
+ *    'notice'              -- message text for a message to use as a notice in the field.
+ *                             Currently used by OOUI form fields only.
+ *    'notice-messages'     -- array of message keys/objects to use for notice.
+ *                             Overrides 'notice'.
+ *    'notice-message'      -- message key or object to use as a notice.
  *    'required'            -- passed through to the object, indicating that it
  *                             is a required field.
  *    'size'                -- the length of text fields
index 7cb497d..5f6460d 100644 (file)
@@ -612,11 +612,17 @@ abstract class HTMLFormField {
                        $error = new OOUI\HtmlSnippet( $error );
                }
 
+               $notices = $this->getNotices();
+               foreach ( $notices as &$notice ) {
+                       $notice = new OOUI\HtmlSnippet( $notice );
+               }
+
                $config = [
                        'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ],
                        'align' => $this->getLabelAlignOOUI(),
                        'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null,
                        'errors' => $errors,
+                       'notices' => $notices,
                        'infusable' => $infusable,
                ];
 
@@ -854,6 +860,30 @@ abstract class HTMLFormField {
                return $errors;
        }
 
+       /**
+        * Determine notices to display for the field.
+        *
+        * @since 1.28
+        * @return string[]
+        */
+       function getNotices() {
+               $notices = [];
+
+               if ( isset( $this->mParams['notice-message'] ) ) {
+                       $notices[] = $this->getMessage( $this->mParams['notice-message'] )->parse();
+               }
+
+               if ( isset( $this->mParams['notice-messages'] ) ) {
+                       foreach ( $this->mParams['notice-messages'] as $msg ) {
+                               $notices[] = $this->getMessage( $msg )->parse();
+                       }
+               } elseif ( isset( $this->mParams['notice'] ) ) {
+                       $notices[] = $this->mParams['notice'];
+               }
+
+               return $notices;
+       }
+
        /**
         * @return string HTML
         */