aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Permissions/UserAuthority.php
diff options
context:
space:
mode:
authorBartosz Dziewoński <dziewonski@fastmail.fm>2024-07-18 00:43:48 +0200
committerBartosz Dziewoński <dziewonski@fastmail.fm>2025-02-18 20:25:33 +0000
commitfa245bab5fcaedfa1ce5af58dc21b0bac279438f (patch)
tree6813f2db56c373426e0f6ec6ff01fe7595d1c32c /includes/Permissions/UserAuthority.php
parent509616e3066e75125303613c71f47f956e050c4a (diff)
downloadmediawikicore-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/Permissions/UserAuthority.php')
-rw-r--r--includes/Permissions/UserAuthority.php40
1 files changed, 5 insertions, 35 deletions
diff --git a/includes/Permissions/UserAuthority.php b/includes/Permissions/UserAuthority.php
index fca1534344bb..a138eaccbf0b 100644
--- a/includes/Permissions/UserAuthority.php
+++ b/includes/Permissions/UserAuthority.php
@@ -324,17 +324,6 @@ class UserAuthority implements Authority {
return !$status || $status->isOK();
}
- // See ApiBase::BLOCK_CODE_MAP
- private const BLOCK_CODES = [
- 'blockedtext',
- 'blockedtext-partial',
- 'autoblockedtext',
- 'systemblockedtext',
- 'blockedtext-composite',
- 'blockedtext-tempuser',
- 'autoblockedtext-tempuser',
- ];
-
/**
* @param string $rigor
* @param string $action
@@ -376,32 +365,13 @@ class UserAuthority implements Authority {
$rigor
);
- if ( $tempStatus->isGood() ) {
- // Nothing to merge, return early
- return $status->isOK();
- }
-
- // Instead of `$status->merge( $tempStatus )`, process the messages like this to ensure that
- // the resulting status contains Message objects instead of strings+arrays, and thus does not
- // trigger wikitext escaping in a legacy code path. See T368821 for more information about
- // that behavior, and see T306494 for the specific bug this fixes.
- foreach ( $tempStatus->getMessages() as $msg ) {
- $status->fatal( $msg );
+ if ( !$tempStatus->isGood() ) {
+ $status->merge( $tempStatus );
}
- foreach ( self::BLOCK_CODES as $code ) {
- // HACK: Detect whether the permission was denied because the user is blocked.
- // A similar hack exists in ApiBase::BLOCK_CODE_MAP.
- // When permission checking logic is moved out of PermissionManager,
- // we can record the block info directly when first checking the block,
- // rather than doing that here.
- if ( $tempStatus->hasMessage( $code ) ) {
- $block = $this->getBlock();
- if ( $block ) {
- $status->setBlock( $block );
- }
- break;
- }
+ $block = $tempStatus->getBlock();
+ if ( $block ) {
+ $status->setBlock( $block );
}
return $status->isOK();