From f7f71359a1be8460c72824d373e12dd2b9bb8bbe Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Fri, 26 Aug 2016 01:29:58 +0000 Subject: [PATCH] Make $wgEmailConfirmToEdit only affect edit actions. Previously it would affect all actions that use Title::userCan. This used to be less noticable, but recently was expanded to include the 'read' action. This only affected the case where both $wgBlockDisablesLogin and $wgEmailConfirmedToEdit were enabled. I don't think anyone was relying on the old behaviour as it was undocumented, and only affected obscure permissions (checked with Title::userCan and not depending on "edit" rights) Follow-up b675be2083 Bug: T143790 Change-Id: I4ad93ed78de4f1ed444f73df6dc26d405a67e553 (cherry picked from commit d561f646b9b8424bd79cfc14729a622a143d9f12) --- includes/Title.php | 5 ++++- .../phpunit/includes/TitlePermissionTest.php | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index b771477fad..ec9840a228 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2556,7 +2556,10 @@ class Title implements LinkTarget { return $errors; } - if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) { + if ( $wgEmailConfirmToEdit + && !$user->isEmailConfirmed() + && $action === 'edit' + ) { $errors[] = [ 'confirmedittext' ]; } diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 4e342447c4..6600aa23c7 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -842,18 +842,23 @@ class TitlePermissionTest extends MediaWikiLangTestCase { * @covers Title::checkUserBlock */ public function testUserBlock() { - global $wgEmailConfirmToEdit, $wgEmailAuthentication; - $wgEmailConfirmToEdit = true; - $wgEmailAuthentication = true; + $this->setMwGlobals( [ + 'wgEmailConfirmToEdit' => true, + 'wgEmailAuthentication' => true, + ] ); $this->setUserPerm( [ "createpage", "move" ] ); $this->setTitle( NS_HELP, "test page" ); - # $short - $this->assertEquals( [ [ 'confirmedittext' ] ], + # $wgEmailConfirmToEdit only applies to 'edit' action + $this->assertEquals( [], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); - $wgEmailConfirmToEdit = false; - $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) ); + $this->assertContains( [ 'confirmedittext' ], + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); + + $this->setMwGlobals( 'wgEmailConfirmToEdit', false ); + $this->assertNotContains( [ 'confirmedittext' ], + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' $this->assertEquals( [], -- 2.20.1