From: David Barratt Date: Sat, 16 Feb 2019 06:08:10 +0000 (-0500) Subject: Return early in Title::checkUserBlock() if user does not have a block. X-Git-Tag: 1.34.0-rc.0~2745^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=29bd18322949e03bbeca263965308f77e0858903;p=lhc%2Fweb%2Fwiklou.git Return early in Title::checkUserBlock() if user does not have a block. To reduce the overhead of the block checks, return early if the user does not have a block. Bug: T216309 Change-Id: I14930fcb7987cbc83294497ab54fcfeeedc94bfe --- diff --git a/includes/Title.php b/includes/Title.php index 6dd21c463f..4075bd5122 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2620,8 +2620,9 @@ class Title implements LinkTarget, IDBAccessObject { $useReplica = ( $rigor !== 'secure' ); $block = $user->getBlock( $useReplica ); - // The block may explicitly allow an action (like "read" or "upload"). - if ( $block && $block->appliesToRight( $action ) === false ) { + // If the user does not have a block, or the block they do have explicitly + // allows the action (like "read" or "upload"). + if ( !$block || $block->appliesToRight( $action ) === false ) { return $errors; } @@ -2650,9 +2651,7 @@ class Title implements LinkTarget, IDBAccessObject { if ( !$actionObj || $actionObj->requiresUnblock() ) { if ( $user->isBlockedFrom( $this, $useReplica ) ) { // @todo FIXME: Pass the relevant context into this function. - $errors[] = $block - ? $block->getPermissionsError( RequestContext::getMain() ) - : [ 'actionblockedtext' ]; + $errors[] = $block->getPermissionsError( RequestContext::getMain() ); } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 7416d3f816..c371cc2e6c 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -673,7 +673,6 @@ "blockedtext": "Your username or IP address has been blocked.\n\nThe block was made by $1.\nThe reason given is $2.\n\n* Start of block: $8\n* Expiration of block: $6\n* Intended blockee: $7\n\nYou can contact $1 or another [[{{MediaWiki:Grouppage-sysop}}|administrator]] to discuss the block.\nYou cannot use the \"{{int:emailuser}}\" feature unless a valid email address is specified in your [[Special:Preferences|account preferences]] and you have not been blocked from using it.\nYour current IP address is $3, and the block ID is #$5.\nPlease include all above details in any queries you make.", "autoblockedtext": "Your IP address has been automatically blocked because it was used by another user, who was blocked by $1.\nThe reason given is:\n\n:$2\n\n* Start of block: $8\n* Expiration of block: $6\n* Intended blockee: $7\n\nYou may contact $1 or one of the other [[{{MediaWiki:Grouppage-sysop}}|administrators]] to discuss the block.\n\nNote that you may not use the \"{{int:emailuser}}\" feature unless you have a valid email address registered in your [[Special:Preferences|user preferences]] and you have not been blocked from using it.\n\nYour current IP address is $3, and the block ID is #$5.\nPlease include all above details in any queries you make.", "systemblockedtext": "Your username or IP address has been automatically blocked by MediaWiki.\nThe reason given is:\n\n:$2\n\n* Start of block: $8\n* Expiration of block: $6\n* Intended blockee: $7\n\nYour current IP address is $3.\nPlease include all above details in any queries you make.", - "actionblockedtext": "You have been blocked from performing this action.", "blockednoreason": "no reason given", "whitelistedittext": "Please $1 to edit pages.", "confirmedittext": "You must confirm your email address before editing pages.\nPlease set and validate your email address through your [[Special:Preferences|user preferences]].", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 796d4362c5..686022069a 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -879,7 +879,6 @@ "blockedtext": "Text displayed to blocked users.\n\n\"email this user\" should be consistent with {{msg-mw|Emailuser}}.\n\nParameters:\n* $1 - the blocking sysop (with a link to his/her userpage)\n* $2 - the reason for the block\n* $3 - the current IP address of the blocked user\n* $4 - (Unused) the blocking sysop's username (plain text, without the link)\n* $5 - the unique numeric identifier of the applied autoblock\n* $6 - the expiry of the block\n* $7 - the intended target of the block (what the blocking user specified in the blocking form)\n* $8 - the timestamp when the block started\nSee also:\n* {{msg-mw|Grouppage-sysop}}\n* {{msg-mw|Autoblockedtext|notext=1}}\n* {{msg-mw|Systemblockedtext|notext=1}}", "autoblockedtext": "Text displayed to automatically blocked users.\n\n\"email this user\" should be consistent with {{msg-mw|Emailuser}}.\n\nParameters:\n* $1 - the blocking sysop (with a link to his/her userpage)\n* $2 - the reason for the block (in case of autoblocks: {{msg-mw|autoblocker}})\n* $3 - the current IP address of the blocked user\n* $4 - (Unused) the blocking sysop's username (plain text, without the link). Use it for GENDER.\n* $5 - the unique numeric identifier of the applied autoblock\n* $6 - the expiry of the block\n* $7 - the intended target of the block (what the blocking user specified in the blocking form)\n* $8 - the timestamp when the block started\nSee also:\n* {{msg-mw|Grouppage-sysop}}\n* {{msg-mw|Blockedtext|notext=1}}\n* {{msg-mw|Systemblockedtext|notext=1}}", "systemblockedtext": "Text displayed to requests blocked by MediaWiki configuration.\n\n\"email this user\" should be consistent with {{msg-mw|Emailuser}}.\n\nParameters:\n* $1 - (Unused) A dummy user attributed as the blocker, possibly as a link to a user page.\n* $2 - the reason for the block\n* $3 - the current IP address of the blocked user\n* $4 - (Unused) the dummy blocking user's username (plain text, without the link).\n* $5 - A short string indicating the type of system block.\n* $6 - the expiry of the block\n* $7 - the intended target of the block\n* $8 - the timestamp when the block started\nSee also:\n* {{msg-mw|Grouppage-sysop}}\n* {{msg-mw|Blockedtext|notext=1}}\n* {{msg-mw|Autoblockedtext|notext=1}}", - "actionblockedtext": "Text displayed when a user is blocked from performing an action, but no matching block for the user exists. This can happen if an extension forces a user to be blocked.", "blockednoreason": "Substituted with $2 in the following message if the reason is not given:\n* {{msg-mw|cantcreateaccount-text}}.\n{{Identical|No reason given}}", "whitelistedittext": "Used as error message. Parameters:\n* $1 - a link to [[Special:UserLogin]] with {{msg-mw|loginreqlink}} as link description\n* $2 - an URL to the same\n\nSee also:\n* {{msg-mw|Nocreatetext}}\n* {{msg-mw|Uploadnologintext}}\n* {{msg-mw|Loginreqpagetext}}", "confirmedittext": "Used as error message.", diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index cb5e1f8a79..1157331eec 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -1029,5 +1029,12 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->getUserPermissionsErrors( 'upload', $this->user ) ); $this->assertEquals( [], $this->title->getUserPermissionsErrors( 'purge', $this->user ) ); + + // Test no block. + $this->user->mBlockedby = null; + $this->user->mBlock = null; + + $this->assertEquals( [], + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); } }