From f2874e2355ee8a54059dac8678937b4fb49af64f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 11 May 2016 14:21:08 -0400 Subject: [PATCH] Fix ApiBase::getErrorFromStatus() and ApiMessages When the code was written, $status->getErrorsArray() would return the Message objects unchanged. But I0deaa988 broke that and apparently didn't bother fixing callers. Now that I'm trying to actually use it for something, I find it's broken, so I fixed it. Change-Id: I763729c5bdd63448b50229774ef1f9d12cfb795d --- includes/api/ApiBase.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index da64c038af..7d0ae32c6a 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1522,20 +1522,20 @@ abstract class ApiBase extends ContextSource { throw new MWException( 'Successful status passed to ApiBase::dieStatus' ); } - $errors = $status->getErrorsArray(); + $errors = $status->getErrorsByType( 'error' ); if ( !$errors ) { // No errors? Assume the warnings should be treated as errors - $errors = $status->getWarningsArray(); + $errors = $status->getErrorsByType( 'warning' ); } if ( !$errors ) { // Still no errors? Punt - $errors = [ [ 'unknownerror-nocode' ] ]; + $errors = [ [ 'message' => 'unknownerror-nocode', 'params' => [] ] ]; } // Cannot use dieUsageMsg() because extensions might return custom // error messages. - if ( $errors[0] instanceof Message ) { - $msg = $errors[0]; + if ( $errors[0]['message'] instanceof Message ) { + $msg = $errors[0]['message']; if ( $msg instanceof IApiMessage ) { $extraData = $msg->getApiData(); $code = $msg->getApiCode(); @@ -1543,8 +1543,8 @@ abstract class ApiBase extends ContextSource { $code = $msg->getKey(); } } else { - $code = array_shift( $errors[0] ); - $msg = wfMessage( $code, $errors[0] ); + $code = $errors[0]['message']; + $msg = wfMessage( $code, $errors[0]['params'] ); } if ( isset( ApiBase::$messageMap[$code] ) ) { // Translate message to code, for backwards compatibility -- 2.20.1