From: Legoktm Date: Mon, 3 Dec 2018 00:12:19 +0000 (+0000) Subject: Revert "Title::checkUserBlock should call User::isBlockedFrom for every action" X-Git-Tag: 1.34.0-rc.0~3368^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=91fc7480301c8b2404cc280511c2fc83a6c3aa5d;p=lhc%2Fweb%2Fwiklou.git Revert "Title::checkUserBlock should call User::isBlockedFrom for every action" This reverts commit b1e4ca70b8e375d52c35b46fb3157fb852948263. Introduced a breaking change, and didn't follow the deprecation policy. Bug: T210953 Change-Id: I11806165912d9188261d3c4c37dbae5cfd2865ec --- diff --git a/includes/Title.php b/includes/Title.php index c151f4a7e5..997063b3d1 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2688,30 +2688,14 @@ class Title implements LinkTarget { } $useReplica = ( $rigor !== 'secure' ); - $block = $user->getBlock( $useReplica ); - - // The block may explicitly allow an action (like "read" or "upload"). - if ( $block && $block->prevents( $action ) === false ) { - return $errors; - } - - // Determine if the user is blocked from this action on this page. - try { + if ( ( $action == 'edit' || $action == 'create' ) + && !$user->isBlockedFrom( $this, $useReplica ) + ) { + // Don't block the user from editing their own talk page unless they've been + // explicitly blocked from that too. + } elseif ( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) { // @todo FIXME: Pass the relevant context into this function. - $action = Action::factory( $action, WikiPage::factory( $this ), RequestContext::getMain() ); - } catch ( Exception $e ) { - $action = null; - } - - // If no action object is returned, assume that the action requires unblock - // which is the default. - if ( !$action || $action->requiresUnblock() ) { - if ( $user->isBlockedFrom( $this, $useReplica ) ) { - // @todo FIXME: Pass the relevant context into this function. - $errors[] = $block - ? $block->getPermissionsError( RequestContext::getMain() ) - : [ 'badaccess-group0' ]; - } + $errors[] = $user->getBlock()->getPermissionsError( RequestContext::getMain() ); } return $errors; diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index cb5e1f8a79..11b9c012f8 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -1,6 +1,5 @@ true, ] ); - $this->setUserPerm( [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ] ); + $this->setUserPerm( [ "createpage", "move" ] ); $this->setTitle( NS_HELP, "test page" ); # $wgEmailConfirmToEdit only applies to 'edit' action @@ -965,24 +964,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase { 'expiry' => 10, 'systemBlock' => 'test', ] ); - - $errors = [ [ 'systemblockedtext', + $this->assertEquals( [ [ 'systemblockedtext', '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', 'Useruser', 'test', '23:00, 31 December 1969', '127.0.8.1', - $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; - - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); - $this->assertEquals( $errors, + $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'rollback', $this->user ) ); - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'patrol', $this->user ) ); - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'upload', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'purge', $this->user ) ); // partial block message test $this->user->mBlockedby = $this->user->getName(); @@ -995,39 +981,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase { 'expiry' => 10, ] ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'rollback', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'patrol', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'upload', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'purge', $this->user ) ); - - $this->user->mBlock->setRestrictions( [ - ( new PageRestriction( 0, $this->title->getArticleID() ) )->setTitle( $this->title ), - ] ); - - $errors = [ [ 'blockedtext-partial', + $this->assertEquals( [ [ 'blockedtext-partial', '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', - $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; - - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); - $this->assertEquals( $errors, + $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'rollback', $this->user ) ); - $this->assertEquals( $errors, - $this->title->getUserPermissionsErrors( 'patrol', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'upload', $this->user ) ); - $this->assertEquals( [], - $this->title->getUserPermissionsErrors( 'purge', $this->user ) ); } }