From: Brad Jorsch Date: Thu, 3 Nov 2016 21:16:18 +0000 (-0400) Subject: API: Add deprecation warnings for Iae0e2ce3 X-Git-Tag: 1.31.0-rc.0~2640^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22upgrade%22%2C%22reinstall=non%22%29%20.%20%22?a=commitdiff_plain;h=efaaa2c1d61964dffcd8427cf52568020f9067ea;p=lhc%2Fweb%2Fwiklou.git API: Add deprecation warnings for Iae0e2ce3 Change-Id: Ib0c9d5a18803b406a1266eb24238536d122ff6e7 --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index aa970f4476..a22f3ec42f 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -2573,6 +2573,7 @@ abstract class ApiBase extends ContextSource { * @param string $warning Warning message */ public function setWarning( $warning ) { + wfDeprecated( __METHOD__, '1.29' ); $msg = new ApiRawMessage( $warning, 'warning' ); $this->getErrorFormatter()->addWarning( $this->getModulePath(), $msg ); } @@ -2591,6 +2592,7 @@ abstract class ApiBase extends ContextSource { * @throws ApiUsageException always */ public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithError( new RawMessage( '$1', [ $description ] ), $errorCode, @@ -2610,6 +2612,7 @@ abstract class ApiBase extends ContextSource { * @throws MWException */ public function getErrorFromStatus( $status, &$extraData = null ) { + wfDeprecated( __METHOD__, '1.29' ); if ( $status->isGood() ) { throw new MWException( 'Successful status passed to ApiBase::dieStatus' ); } @@ -2819,6 +2822,7 @@ abstract class ApiBase extends ContextSource { * @return [ 'code' => code, 'info' => info ] */ public function parseMsg( $error ) { + wfDeprecated( __METHOD__, '1.29' ); // Check whether someone passed the whole array, instead of one element as // documented. This breaks if it's actually an array of fallback keys, but // that's long-standing misbehavior introduced in r87627 to incorrectly @@ -2848,6 +2852,7 @@ abstract class ApiBase extends ContextSource { * @throws ApiUsageException always */ public function dieUsageMsg( $error ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithError( $this->parseMsgInternal( $error ) ); } @@ -2860,6 +2865,7 @@ abstract class ApiBase extends ContextSource { * @since 1.21 */ public function dieUsageMsgOrDebug( $error ) { + wfDeprecated( __METHOD__, '1.29' ); $this->dieWithErrorOrDebug( $this->parseMsgInternal( $error ) ); } diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index d7586e0822..c644e8704a 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1038,7 +1038,7 @@ class ApiMain extends ApiBase { // None of the rest have any messages for non-error types } elseif ( $e instanceof UsageException ) { // User entered incorrect parameters - generate error response - $data = $e->getMessageArray(); + $data = MediaWiki\quietCall( [ $e, 'getMessageArray' ] ); $code = $data['code']; $info = $data['info']; unset( $data['code'], $data['info'] ); diff --git a/includes/api/ApiUsageException.php b/includes/api/ApiUsageException.php index 9dc1f92bbc..fb49e2dbe2 100644 --- a/includes/api/ApiUsageException.php +++ b/includes/api/ApiUsageException.php @@ -45,6 +45,10 @@ class UsageException extends MWException { $this->mCodestr = $codestr; $this->mExtraData = $extradata; + if ( !$this instanceof ApiUsageException ) { + wfDeprecated( __METHOD__, '1.29' ); + } + // This should never happen, so throw an exception about it that will // hopefully get logged with a backtrace (T138585) if ( !is_string( $codestr ) || $codestr === '' ) { @@ -58,6 +62,7 @@ class UsageException extends MWException { * @return string */ public function getCodeString() { + wfDeprecated( __METHOD__, '1.29' ); return $this->mCodestr; } @@ -65,6 +70,7 @@ class UsageException extends MWException { * @return array */ public function getMessageArray() { + wfDeprecated( __METHOD__, '1.29' ); $result = [ 'code' => $this->mCodestr, 'info' => $this->getMessage() @@ -183,6 +189,7 @@ class ApiUsageException extends UsageException implements ILocalizedException { * @inheritdoc */ public function getCodeString() { + wfDeprecated( __METHOD__, '1.29' ); return $this->getApiMessage()->getApiCode(); } @@ -192,6 +199,7 @@ class ApiUsageException extends UsageException implements ILocalizedException { * @inheritdoc */ public function getMessageArray() { + wfDeprecated( __METHOD__, '1.29' ); $enMsg = clone $this->getApiMessage(); $enMsg->inLanguage( 'en' )->useDatabase( false ); diff --git a/tests/phpunit/includes/api/ApiErrorFormatterTest.php b/tests/phpunit/includes/api/ApiErrorFormatterTest.php index a2c0d3978e..d47481cbe4 100644 --- a/tests/phpunit/includes/api/ApiErrorFormatterTest.php +++ b/tests/phpunit/includes/api/ApiErrorFormatterTest.php @@ -526,6 +526,10 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase { * @param array $expect */ public function testGetMessageFromException( $exception, $options, $expect ) { + if ( $exception instanceof UsageException ) { + $this->hideDeprecated( 'UsageException::getMessageArray' ); + } + $result = new ApiResult( 8388608 ); $formatter = new ApiErrorFormatter( $result, Language::factory( 'en' ), 'html', false ); @@ -571,6 +575,12 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase { } public static function provideGetMessageFromException() { + MediaWiki\suppressWarnings(); + $usageException = new UsageException( + 'Something broke!', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] + ); + MediaWiki\restoreWarnings(); + return [ 'Normal exception' => [ new RuntimeException( 'Something broke!' ), @@ -591,7 +601,7 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase { ] ], 'UsageException' => [ - new UsageException( 'Something broke!', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ), + $usageException, [], [ 'text' => '<b>Something broke!</b>', @@ -600,7 +610,7 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase { ] ], 'UsageException, wrapped' => [ - new UsageException( 'Something broke!', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ), + $usageException, [ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ], [ 'text' => '(<b>Something broke!</b>)', diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index ea33a9e3ad..ad334e9401 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -500,6 +500,10 @@ class ApiMainTest extends ApiTestCase { MWExceptionHandler::getRedactedTraceAsString( $dbex ) )->inLanguage( 'en' )->useDatabase( false )->text(); + MediaWiki\suppressWarnings(); + $usageEx = new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ); + MediaWiki\restoreWarnings(); + $apiEx1 = new ApiUsageException( null, StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) ); TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar'; @@ -545,7 +549,7 @@ class ApiMainTest extends ApiTestCase { ] ], [ - new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ), + $usageEx, [ 'existing-error', 'ue' ], [ 'warnings' => [