From: Brad Jorsch Date: Wed, 11 May 2016 18:21:08 +0000 (-0400) Subject: Fix ApiBase::getErrorFromStatus() and ApiMessages X-Git-Tag: 1.31.0-rc.0~7016^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22statistiques_visites%22%2C%22%22%29%20.%20%22?a=commitdiff_plain;h=f2874e2355ee8a54059dac8678937b4fb49af64f;p=lhc%2Fweb%2Fwiklou.git 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 --- 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