From 96a9a3e1019e158b4935b1e61934be8a4d926d82 Mon Sep 17 00:00:00 2001 From: Tyler Anthony Romeo Date: Sun, 30 Jun 2013 22:45:45 +0200 Subject: [PATCH] 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 --- includes/Message.php | 7 ++- includes/Status.php | 63 ++++++++++++++++++++------ includes/specials/SpecialUserlogin.php | 12 +++-- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/includes/Message.php b/includes/Message.php index 208f96e0f1..57c6264dfa 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -799,7 +799,7 @@ class Message { * @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 @@ class Message { ); 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 7a84fed109..ab242011c7 100644 --- a/includes/Status.php +++ b/includes/Status.php @@ -188,15 +188,18 @@ class Status { } } 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 ) { @@ -206,6 +209,49 @@ class Status { 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; + } + /** * Return the message for a single error. * @param $error Mixed With an array & two values keyed by @@ -230,7 +276,7 @@ class Status { } else { $msg = wfMessage( $error ); } - return $msg->plain(); + return $msg; } /** @@ -371,15 +417,6 @@ class Status { return $replaced; } - /** - * Backward compatibility function for WikiError -> Status migration - * - * @return String - */ - public function getMessage() { - return $this->getWikiText(); - } - /** * @return mixed */ diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index 90c4c35841..5ac3e6546e 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -221,8 +221,8 @@ class LoginForm extends SpecialPage { $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 @@ class LoginForm extends SpecialPage { # 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 @@ class LoginForm extends SpecialPage { 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 -- 2.20.1