jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/321407 )

Change subject: API: Add deprecation warnings for Iae0e2ce3
......................................................................


API: Add deprecation warnings for Iae0e2ce3

Change-Id: Ib0c9d5a18803b406a1266eb24238536d122ff6e7
---
M includes/api/ApiBase.php
M includes/api/ApiMain.php
M includes/api/ApiUsageException.php
M tests/phpunit/includes/api/ApiErrorFormatterTest.php
M tests/phpunit/includes/api/ApiMainTest.php
5 files changed, 32 insertions(+), 4 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index aa970f4..a22f3ec 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -2573,6 +2573,7 @@
         * @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 @@
         * @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 @@
         * @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 @@
         * @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 @@
         * @throws ApiUsageException always
         */
        public function dieUsageMsg( $error ) {
+               wfDeprecated( __METHOD__, '1.29' );
                $this->dieWithError( $this->parseMsgInternal( $error ) );
        }
 
@@ -2860,6 +2865,7 @@
         * @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 d7586e0..c644e87 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -1038,7 +1038,7 @@
                        // 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 9dc1f92..fb49e2d 100644
--- a/includes/api/ApiUsageException.php
+++ b/includes/api/ApiUsageException.php
@@ -45,6 +45,10 @@
                $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 @@
         * @return string
         */
        public function getCodeString() {
+               wfDeprecated( __METHOD__, '1.29' );
                return $this->mCodestr;
        }
 
@@ -65,6 +70,7 @@
         * @return array
         */
        public function getMessageArray() {
+               wfDeprecated( __METHOD__, '1.29' );
                $result = [
                        'code' => $this->mCodestr,
                        'info' => $this->getMessage()
@@ -183,6 +189,7 @@
         * @inheritdoc
         */
        public function getCodeString() {
+               wfDeprecated( __METHOD__, '1.29' );
                return $this->getApiMessage()->getApiCode();
        }
 
@@ -192,6 +199,7 @@
         * @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 a2c0d39..d47481c 100644
--- a/tests/phpunit/includes/api/ApiErrorFormatterTest.php
+++ b/tests/phpunit/includes/api/ApiErrorFormatterTest.php
@@ -526,6 +526,10 @@
         * @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 @@
        }
 
        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 @@
                                ]
                        ],
                        'UsageException' => [
-                               new UsageException( '<b>Something broke!</b>', 
'ue-code', 0, [ 'xxx' => 'yyy', 'baz' => 23 ] ),
+                               $usageException,
                                [],
                                [
                                        'text' => '&#60;b&#62;Something 
broke!&#60;/b&#62;',
@@ -600,7 +610,7 @@
                                ]
                        ],
                        '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' => '(&#60;b&#62;Something 
broke!&#60;/b&#62;)',
diff --git a/tests/phpunit/includes/api/ApiMainTest.php 
b/tests/phpunit/includes/api/ApiMainTest.php
index ea33a9e..ad334e9 100644
--- a/tests/phpunit/includes/api/ApiMainTest.php
+++ b/tests/phpunit/includes/api/ApiMainTest.php
@@ -500,6 +500,10 @@
                        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 @@
                                ]
                        ],
                        [
-                               new UsageException( 'Usage exception!', 'ue', 
0, [ 'foo' => 'bar' ] ),
+                               $usageEx,
                                [ 'existing-error', 'ue' ],
                                [
                                        'warnings' => [

-- 
To view, visit https://gerrit.wikimedia.org/r/321407
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib0c9d5a18803b406a1266eb24238536d122ff6e7
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to