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

Change subject: Fix double-parsing of account creation messages.
......................................................................


Fix double-parsing of account creation messages.

Account creation messages don't need to be parsed. This is
a temporary fix to follow up when double-parsing was accidentally
added in 69ea4400037 (I402c6bebcfe).

Bug: 44718
Bug: 52191
Change-Id: I333d5468820994625348316ebf6c57d4df025284
---
M includes/Message.php
M includes/Status.php
M includes/specials/SpecialUserlogin.php
3 files changed, 63 insertions(+), 19 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Message.php b/includes/Message.php
index 208f96e..57c6264 100644
--- a/includes/Message.php
+++ b/includes/Message.php
@@ -799,7 +799,7 @@
         * @return Tuple(type, value)
         */
        protected function extractParam( $param ) {
-               if ( is_array( $param ) ){
+               if ( is_array( $param ) ) {
                        if ( isset( $param['raw'] ) ) {
                                return array( 'after', $param['raw'] );
                        } elseif ( isset( $param['num'] ) ) {
@@ -823,6 +823,11 @@
                                );
                                return array( 'before', '[INVALID]' );
                        }
+               } elseif ( $param instanceof Message ) {
+                       // Message objects should not be before parameters 
because
+                       // then they'll get double escaped. If the message 
needs to be
+                       // escaped, it'll happen right here when we call 
toString().
+                       return array( 'after', $param->toString() );
                } else {
                        return array( 'before', $param );
                }
diff --git a/includes/Status.php b/includes/Status.php
index 7a84fed..ab24201 100644
--- a/includes/Status.php
+++ b/includes/Status.php
@@ -188,19 +188,65 @@
                        }
                }
                if ( count( $this->errors ) == 1 ) {
-                       $s = $this->getErrorMessage( $this->errors[0] );
+                       $s = $this->getErrorMessage( $this->errors[0] 
)->plain();
                        if ( $shortContext ) {
                                $s = wfMessage( $shortContext, $s )->plain();
                        } elseif ( $longContext ) {
                                $s = wfMessage( $longContext, "* $s\n" 
)->plain();
                        }
                } else {
-                       $s = '* ' . implode( "\n* ",
-                               $this->getErrorMessageArray( $this->errors ) ) 
. "\n";
+                       $errors = $this->getErrorMessageArray( $this->errors );
+                       foreach ( $errors as &$error ) {
+                               $error = $error->plain();
+                       }
+                       $s = '* ' . implode( "\n* ", $errors ) . "\n";
                        if ( $longContext ) {
                                $s = wfMessage( $longContext, $s )->plain();
                        } elseif ( $shortContext ) {
                                $s = wfMessage( $shortContext, "\n$s\n" 
)->plain();
+                       }
+               }
+               return $s;
+       }
+
+       /**
+        * Get the error list as a Message object
+        *
+        * @param string $shortContext a short enclosing context message name, 
to
+        *        be used when there is a single error
+        * @param string $longContext a long enclosing context message name, 
for a list
+        * @return Message
+        */
+       function getMessage( $shortContext = false, $longContext = false ) {
+               if ( count( $this->errors ) == 0 ) {
+                       if ( $this->ok ) {
+                               $this->fatal( 'internalerror_info',
+                                       __METHOD__ . " called for a good 
result, this is incorrect\n" );
+                       } else {
+                               $this->fatal( 'internalerror_info',
+                                       __METHOD__ . ": Invalid result object: 
no error text but not OK\n" );
+                       }
+               }
+               if ( count( $this->errors ) == 1 ) {
+                       $s = $this->getErrorMessage( $this->errors[0] );
+                       if ( $shortContext ) {
+                               $s = wfMessage( $shortContext, $s );
+                       } elseif ( $longContext ) {
+                               $wrapper = new RawMessage( "* \$1\n" );
+                               $wrapper->params( $s )->parse();
+                               $s = wfMessage( $longContext, $wrapper );
+                       }
+               } else {
+                       $msgs =  $this->getErrorMessageArray( $this->errors );
+                       $wrapper = new RawMessage( '* $' . implode( "\n* \$", 
range( 1, count( $msgs ) + 1 ) ) );
+                       $wrapper->params( $msgs )->parse();
+
+                       if ( $longContext ) {
+                               $s = wfMessage( $longContext, $wrapper );
+                       } elseif ( $shortContext ) {
+                               $wrapper = new RawMessage( "\n\$1\n", $wrapper 
);
+                               $wrapper->parse();
+                               $s = wfMessage( $shortContext, $wrapper );
                        }
                }
                return $s;
@@ -230,7 +276,7 @@
                } else {
                        $msg = wfMessage( $error );
                }
-               return $msg->plain();
+               return $msg;
        }
 
        /**
@@ -369,15 +415,6 @@
                        }
                }
                return $replaced;
-       }
-
-       /**
-        * Backward compatibility function for WikiError -> Status migration
-        *
-        * @return String
-        */
-       public function getMessage() {
-               return $this->getWikiText();
        }
 
        /**
diff --git a/includes/specials/SpecialUserlogin.php 
b/includes/specials/SpecialUserlogin.php
index 90c4c35..5ac3e65 100644
--- a/includes/specials/SpecialUserlogin.php
+++ b/includes/specials/SpecialUserlogin.php
@@ -221,8 +221,8 @@
 
                $status = $this->addNewaccountInternal();
                if ( !$status->isGood() ) {
-                       $error = $this->getOutput()->parse( 
$status->getWikiText() );
-                       $this->mainLoginForm( $error );
+                       $error = $status->getMessage();
+                       $this->mainLoginForm( $error->toString() );
                        return;
                }
 
@@ -257,8 +257,8 @@
                # Create the account and abort if there's a problem doing so
                $status = $this->addNewAccountInternal();
                if ( !$status->isGood() ) {
-                       $error = $this->getOutput()->parse( 
$status->getWikiText() );
-                       $this->mainLoginForm( $error );
+                       $error = $status->getMessage();
+                       $this->mainLoginForm( $error->toString() );
                        return false;
                }
 
@@ -447,7 +447,9 @@
                if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) 
) ) {
                        // Hook point to add extra creation throttles and blocks
                        wfDebug( "LoginForm::addNewAccountInternal: a hook 
blocked creation\n" );
-                       return Status::newFatal( new RawMessage( $abortError ) 
);
+                       $abortError = new RawMessage( $abortError );
+                       $abortError->text();
+                       return Status::newFatal( $abortError );
                }
 
                // Hook point to check for exempt from account creation throttle

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I333d5468820994625348316ebf6c57d4df025284
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>
Gerrit-Reviewer: Bartosz DziewoƄski <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Sumanah <[email protected]>
Gerrit-Reviewer: Swalling <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to