diff options
author | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2024-07-18 00:43:48 +0200 |
---|---|---|
committer | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2025-02-18 20:25:33 +0000 |
commit | fa245bab5fcaedfa1ce5af58dc21b0bac279438f (patch) | |
tree | 6813f2db56c373426e0f6ec6ff01fe7595d1c32c /includes/block/BlockErrorFormatter.php | |
parent | 509616e3066e75125303613c71f47f956e050c4a (diff) | |
download | mediawikicore-fa245bab5fcaedfa1ce5af58dc21b0bac279438f.tar.gz mediawikicore-fa245bab5fcaedfa1ce5af58dc21b0bac279438f.zip |
Generate machine-readable block info in BlockErrorFormatter
Previously, BlockErrorFormatter would only generate a human-readable
error message for permission errors caused by blocks, and
PermissionManager would build a PermissionStatus object out of them.
Machine-readable block info was added later: UserAuthority would add
a Block object to each one, then finally each API module (via
ApiBlockInfoTrait) would generate block info from these Block objects.
Now all of this happens in BlockErrorFormatter and PermissionManager.
For compatibility with older code, remove the extra information when
using the deprecated PermissionManager::getPermissionErrors() method.
This is a small hack that can be removed together with that method in
the future.
The changes seem to make a workaround for T357063 in ApiQueryInfo
unnecessary (tests added in c55d33ef11 still pass).
Bug: T357063
Change-Id: Id121d51a24fbb1d8210e60bdd54c61b16938dd70
Diffstat (limited to 'includes/block/BlockErrorFormatter.php')
-rw-r--r-- | includes/block/BlockErrorFormatter.php | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/includes/block/BlockErrorFormatter.php b/includes/block/BlockErrorFormatter.php index 77348d456fbd..06adf7c85f15 100644 --- a/includes/block/BlockErrorFormatter.php +++ b/includes/block/BlockErrorFormatter.php @@ -20,6 +20,8 @@ namespace MediaWiki\Block; +use MediaWiki\Api\ApiBlockInfoHelper; +use MediaWiki\Api\ApiMessage; use MediaWiki\CommentStore\CommentStoreComment; use MediaWiki\HookContainer\HookContainer; use MediaWiki\HookContainer\HookRunner; @@ -68,7 +70,7 @@ class BlockErrorFormatter { /** * Get a block error message. Different message keys are chosen depending on the * block features. Message parameters are formatted for the specified user and - * language. + * language. The message includes machine-readable data for API error responses. * * If passed a CompositeBlock, will get a generic message stating that there are * multiple blocks. To get all the block messages, use getMessages instead. @@ -77,7 +79,7 @@ class BlockErrorFormatter { * @param UserIdentity $user * @param mixed $language Unused since 1.42 * @param string $ip - * @return Message + * @return ApiMessage */ public function getMessage( Block $block, @@ -87,7 +89,14 @@ class BlockErrorFormatter { ): Message { $key = $this->getBlockErrorMessageKey( $block, $user ); $params = $this->getBlockErrorMessageParams( $block, $user, $ip ); - return $this->uiContext->msg( $key, $params ); + $apiHelper = new ApiBlockInfoHelper; + + // @phan-suppress-next-line PhanTypeMismatchReturnSuperType + return ApiMessage::create( + $this->uiContext->msg( $key, $params ), + $apiHelper->getBlockCode( $block ), + [ 'blockinfo' => $apiHelper->getBlockDetails( $block, $this->getLanguage(), $user ) ] + ); } /** |