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
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 );
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() ) ]
) );
}
}
$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 ) ]
);
}
}
$this->dieWithError(
$status,
null,
- [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+ [ 'blockinfo' => $this->getBlockDetails( $block ) ]
);
}
}
* - 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();
$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
if ( isset( $this->prop['blockinfo'] ) ) {
$block = $user->getBlock();
if ( $block ) {
- $vals = array_merge( $vals, $this->getBlockInfo( $block ) );
+ $vals = array_merge( $vals, $this->getBlockDetails( $block ) );
}
}
$this->dieWithError(
$status,
null,
- [ 'blockinfo' => $this->getBlockInfo( $block ) ]
+ [ 'blockinfo' => $this->getBlockDetails( $block ) ]
);
}
}
$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 ) );
$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 ) );
*/
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' => '',
$this->assertArraySubset( $subset, $info );
}
- public static function provideGetBlockInfo() {
+ public static function provideGetBlockDetails() {
return [
'Sitewide block' => [
new Block(),
--- /dev/null
+<?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 );
+ }
+}