Restore ApiQueryUserInfo::getBlockInfo() as a stub.
authordaniel <dkinzler@wikimedia.org>
Thu, 9 May 2019 10:13:30 +0000 (12:13 +0200)
committerDaniel Kinzler <dkinzler@wikimedia.org>
Sat, 11 May 2019 07:33:25 +0000 (07:33 +0000)
Fixes unintended breaking change made by I84ed21641c44b2f65ebe.
ApiQueryUserInfo::getBlockInfo() is restoed as a hard deprecated stub.

This renames the method in the new ApiBlockInfoTrait to
getBlockDetails.

Depends-On: I9f40666a31bd4af50762c197c2ce5bf089a5e68c
Change-Id: If47a93878f87d69800e5f305404c22528dac5e94

includes/api/ApiBase.php
includes/api/ApiBlock.php
includes/api/ApiBlockInfoTrait.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiUnblock.php
tests/phpunit/includes/api/ApiBaseTest.php
tests/phpunit/includes/api/ApiBlockInfoTraitTest.php
tests/phpunit/includes/api/ApiQueryUserInfoTest.php [new file with mode: 0644]

index bc62906..b76a4ea 100644 (file)
@@ -1816,7 +1816,7 @@ abstract class ApiBase extends ContextSource {
                        if ( is_string( $error[0] ) && isset( self::$blockMsgMap[$error[0]] ) && $user->getBlock() ) {
                                list( $msg, $code ) = self::$blockMsgMap[$error[0]];
                                $status->fatal( ApiMessage::create( $msg, $code,
-                                       [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
                                ) );
                        } else {
                                $status->fatal( ...$error );
@@ -1839,7 +1839,7 @@ abstract class ApiBase extends ContextSource {
                foreach ( self::$blockMsgMap as $msg => list( $apiMsg, $code ) ) {
                        if ( $status->hasMessage( $msg ) && $user->getBlock() ) {
                                $status->replaceMessage( $msg, ApiMessage::create( $apiMsg, $code,
-                                       [ 'blockinfo' => $this->getBlockInfo( $user->getBlock() ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $user->getBlock() ) ]
                                ) );
                        }
                }
@@ -2038,19 +2038,19 @@ abstract class ApiBase extends ContextSource {
                        $this->dieWithError(
                                'apierror-autoblocked',
                                'autoblocked',
-                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                } elseif ( !$block->isSitewide() ) {
                        $this->dieWithError(
                                'apierror-blocked-partial',
                                'blocked',
-                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                } else {
                        $this->dieWithError(
                                'apierror-blocked',
                                'blocked',
-                               [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                               [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                        );
                }
        }
index 336943d..f7c2bce 100644 (file)
@@ -52,7 +52,7 @@ class ApiBlock extends ApiBase {
                                $this->dieWithError(
                                        $status,
                                        null,
-                                       [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                                );
                        }
                }
index 51da835..d16cd21 100644 (file)
@@ -38,7 +38,7 @@ trait ApiBlockInfoTrait {
         *  - blockexpiry - expiry time of the block
         *  - systemblocktype - system block type, if any
         */
-       private function getBlockInfo( AbstractBlock $block ) {
+       private function getBlockDetails( AbstractBlock $block ) {
                $vals = [];
                $vals['blockid'] = $block->getId();
                $vals['blockedby'] = $block->getByName();
index c495c6d..d73fbc4 100644 (file)
@@ -52,6 +52,26 @@ class ApiQueryUserInfo extends ApiQueryBase {
                $result->addValue( 'query', $this->getModuleName(), $r );
        }
 
+       /**
+        * Get basic info about a given block
+        *
+        * @deprecated since 1.34 Use ApiBlockInfoTrait::getBlockDetails() instead.
+        * @param Block $block
+        * @return array See ApiBlockInfoTrait::getBlockDetails
+        */
+       public static function getBlockInfo( Block $block ) {
+               wfDeprecated( __METHOD__, '1.34' );
+
+               // Hack to access a private method from a trait:
+               $dummy = new class {
+                       use ApiBlockInfoTrait {
+                               getBlockDetails as public;
+                       }
+               };
+
+               return $dummy->getBlockDetails( $block );
+       }
+
        /**
         * Get central user info
         * @param Config $config
@@ -104,7 +124,7 @@ class ApiQueryUserInfo extends ApiQueryBase {
                if ( isset( $this->prop['blockinfo'] ) ) {
                        $block = $user->getBlock();
                        if ( $block ) {
-                               $vals = array_merge( $vals, $this->getBlockInfo( $block ) );
+                               $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
                        }
                }
 
index f038b96..1c72b67 100644 (file)
@@ -50,7 +50,7 @@ class ApiUnblock extends ApiBase {
                                $this->dieWithError(
                                        $status,
                                        null,
-                                       [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+                                       [ 'blockinfo' => $this->getBlockDetails( $block ) ]
                                );
                        }
                }
index 4e19822..64b2cd6 100644 (file)
@@ -1336,7 +1336,7 @@ class ApiBaseTest extends ApiTestCase {
                $userInfoTrait = TestingAccessWrapper::newFromObject(
                        $this->getMockForTrait( ApiBlockInfoTrait::class )
                );
-               $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockInfo( $block ) ];
+               $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ];
 
                $expect = Status::newGood();
                $expect->fatal( ApiMessage::create( 'apierror-blocked', 'blocked', $blockinfo ) );
@@ -1394,7 +1394,7 @@ class ApiBaseTest extends ApiTestCase {
                $userInfoTrait = TestingAccessWrapper::newFromObject(
                        $this->getObjectForTrait( ApiBlockInfoTrait::class )
                );
-               $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockInfo( $block ) ];
+               $blockinfo = [ 'blockinfo' => $userInfoTrait->getBlockDetails( $block ) ];
 
                $expect = Status::newGood();
                $expect->fatal( ApiMessage::create( 'apierror-blocked', 'blocked', $blockinfo ) );
index 932495a..a6e2d0d 100644 (file)
@@ -8,11 +8,11 @@ use MediaWiki\Block\SystemBlock;
  */
 class ApiBlockInfoTraitTest extends MediaWikiTestCase {
        /**
-        * @dataProvider provideGetBlockInfo
+        * @dataProvider provideGetBlockDetails
         */
-       public function testGetBlockInfo( $block, $expectedInfo ) {
+       public function testGetBlockDetails( $block, $expectedInfo ) {
                $mock = $this->getMockForTrait( ApiBlockInfoTrait::class );
-               $info = TestingAccessWrapper::newFromObject( $mock )->getBlockInfo( $block );
+               $info = TestingAccessWrapper::newFromObject( $mock )->getBlockDetails( $block );
                $subset = array_merge( [
                        'blockid' => null,
                        'blockedby' => '',
@@ -23,7 +23,7 @@ class ApiBlockInfoTraitTest extends MediaWikiTestCase {
                $this->assertArraySubset( $subset, $info );
        }
 
-       public static function provideGetBlockInfo() {
+       public static function provideGetBlockDetails() {
                return [
                        'Sitewide block' => [
                                new Block(),
diff --git a/tests/phpunit/includes/api/ApiQueryUserInfoTest.php b/tests/phpunit/includes/api/ApiQueryUserInfoTest.php
new file mode 100644 (file)
index 0000000..703c150
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * @group medium
+ * @covers ApiQueryUserInfo
+ */
+class ApiQueryUserInfoTest extends ApiTestCase {
+       public function testGetBlockInfo() {
+               $this->hideDeprecated( 'ApiQueryUserInfo::getBlockInfo' );
+
+               $apiQueryUserInfo = new ApiQueryUserInfo(
+                       new ApiQuery( new ApiMain( $this->apiContext ), 'userinfo' ),
+                       'userinfo'
+               );
+
+               $block = new Block();
+               $info = $apiQueryUserInfo->getBlockInfo( $block );
+               $subset = [
+                       'blockid' => null,
+                       'blockedby' => '',
+                       'blockedbyid' => 0,
+                       'blockreason' => '',
+                       'blockexpiry' => 'infinite',
+                       'blockpartial' => false,
+               ];
+               $this->assertArraySubset( $subset, $info );
+       }
+
+       public function testGetBlockInfoPartial() {
+               $this->hideDeprecated( 'ApiQueryUserInfo::getBlockInfo' );
+
+               $apiQueryUserInfo = new ApiQueryUserInfo(
+                       new ApiQuery( new ApiMain( $this->apiContext ), 'userinfo' ),
+                       'userinfo'
+               );
+
+               $block = new Block( [
+                       'sitewide' => false,
+               ] );
+               $info = $apiQueryUserInfo->getBlockInfo( $block );
+               $subset = [
+                       'blockid' => null,
+                       'blockedby' => '',
+                       'blockedbyid' => 0,
+                       'blockreason' => '',
+                       'blockexpiry' => 'infinite',
+                       'blockpartial' => true,
+               ];
+               $this->assertArraySubset( $subset, $info );
+       }
+}