API: Add deprecation warnings for Iae0e2ce3
Change-Id: Ib0c9d5a18803b406a1266eb24238536d122ff6e7
This commit is contained in:
parent
f7e1770fb8
commit
efaaa2c1d6
5 changed files with 32 additions and 4 deletions
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'] );
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
'<b>Something broke!</b>', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ]
|
||||
);
|
||||
MediaWiki\restoreWarnings();
|
||||
|
||||
return [
|
||||
'Normal exception' => [
|
||||
new RuntimeException( '<b>Something broke!</b>' ),
|
||||
|
|
@ -591,7 +601,7 @@ class ApiErrorFormatterTest extends MediaWikiLangTestCase {
|
|||
]
|
||||
],
|
||||
'UsageException' => [
|
||||
new UsageException( '<b>Something broke!</b>', '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( '<b>Something broke!</b>', 'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ),
|
||||
$usageException,
|
||||
[ 'wrap' => 'parentheses', 'code' => 'some-code', 'data' => [ 'foo' => 'bar', 'baz' => 42 ] ],
|
||||
[
|
||||
'text' => '(<b>Something broke!</b>)',
|
||||
|
|
|
|||
|
|
@ -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' => [
|
||||
|
|
|
|||
Loading…
Reference in a new issue