From: Dayllan Maza Date: Tue, 30 Jul 2019 02:15:56 +0000 (-0400) Subject: Fix SpecialBlock validation for ipb_allow_usertalk X-Git-Tag: 1.34.0-rc.0~832^2 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_user_edit%27%2C%20iduser=user.userid%29%20%7D%7D?a=commitdiff_plain;h=fd70b59dc5ae577a8bcc28f9c63cc2f3978248a5;p=lhc%2Fweb%2Fwiklou.git Fix SpecialBlock validation for ipb_allow_usertalk ipb_allow_usertalk should be saved as false only when: A block is sitewide A block is partial and there is a restriction on the User_talk namespace Bug: T224468 Change-Id: Ic85368991b5905af1bab99b0cb5fcba0e993405e --- diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index ea4f18d287..a55a9c8694 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -754,8 +754,6 @@ class SpecialBlock extends FormSpecialPage { * @return bool|array */ public static function processForm( array $data, IContextSource $context ) { - global $wgBlockAllowsUTEdit, $wgHideUserContribLimit; - $performer = $context->getUser(); $enablePartialBlocks = $context->getConfig()->get( 'EnablePartialBlocks' ); $isPartialBlock = $enablePartialBlocks && @@ -843,23 +841,33 @@ class SpecialBlock extends FormSpecialPage { } # Recheck params here... + $hideUserContribLimit = $context->getConfig()->get( 'HideUserContribLimit' ); if ( $type != DatabaseBlock::TYPE_USER ) { $data['HideUser'] = false; # IP users should not be hidden } elseif ( !wfIsInfinity( $data['Expiry'] ) ) { # Bad expiry. return [ 'ipb_expiry_temp' ]; - } elseif ( $wgHideUserContribLimit !== false - && $user->getEditCount() > $wgHideUserContribLimit + } elseif ( $hideUserContribLimit !== false + && $user->getEditCount() > $hideUserContribLimit ) { # Typically, the user should have a handful of edits. # Disallow hiding users with many edits for performance. return [ [ 'ipb_hide_invalid', - Message::numParam( $wgHideUserContribLimit ) ] ]; + Message::numParam( $hideUserContribLimit ) ] ]; } elseif ( !$data['Confirm'] ) { return [ 'ipb-confirmhideuser', 'ipb-confirmaction' ]; } } + $blockAllowsUTEdit = $context->getConfig()->get( 'BlockAllowsUTEdit' ); + $userTalkEditAllowed = !$blockAllowsUTEdit || !$data['DisableUTEdit']; + if ( !$userTalkEditAllowed && + $isPartialBlock && + !in_array( NS_USER_TALK, explode( "\n", $data['NamespaceRestrictions'] ) ) + ) { + return [ 'ipb-prevent-user-talk-edit' ]; + } + # Create block object. $block = new DatabaseBlock(); $block->setTarget( $target ); @@ -867,7 +875,7 @@ class SpecialBlock extends FormSpecialPage { $block->setReason( $data['Reason'][0] ); $block->setExpiry( $expiryTime ); $block->isCreateAccountBlocked( $data['CreateAccount'] ); - $block->isUsertalkEditAllowed( !$wgBlockAllowsUTEdit || !$data['DisableUTEdit'] ); + $block->isUsertalkEditAllowed( $userTalkEditAllowed ); $block->isEmailBlocked( $data['DisableEmail'] ); $block->isHardblock( $data['HardBlock'] ); $block->isAutoblocking( $data['AutoBlock'] ); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 01e1007da4..51b98464a7 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2738,6 +2738,7 @@ "block-log-flags-angry-autoblock": "enhanced autoblock enabled", "block-log-flags-hiddenname": "username hidden", "range_block_disabled": "The administrator ability to create range blocks is disabled.", + "ipb-prevent-user-talk-edit": "Editing their own talk page must be allowed for a partial block, unless it includes a restriction on the User Talk namespace.", "ipb_expiry_invalid": "Expiry time invalid.", "ipb_expiry_old": "Expiry time is in the past.", "ipb_expiry_temp": "Hidden username blocks must be permanent.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 081bb66f43..6c8942c0f5 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2947,6 +2947,7 @@ "block-log-flags-angry-autoblock": "Used as a block log flag in [[Special:Log/block]].\n{{Related|Block-log-flags}}", "block-log-flags-hiddenname": "Used as a block log flag in [[Special:Log/block]] and in [[Special:Block]].\n\n{{Related|Block-log-flags}}", "range_block_disabled": "Used as error message in [[Special:Block]].\n\nSee also:\n* {{msg-mw|Range block disabled}}\n* {{msg-mw|Ip range invalid}}\n* {{msg-mw|Ip range toolarge}}", + "ipb-prevent-user-talk-edit": "Used as error message in [[Special:Block]] if invalid options are selected regarding \"Edit own user talk\".\n\nSee also:\n{{msg-mw|ipb-disableusertalk}}", "ipb_expiry_invalid": "Used as error message in [[Special:Block]].", "ipb_expiry_old": "Used as error message in [[Special:Block]], if the expiry time is in the past.\n{{Identical|protect_expiry_old}}", "ipb_expiry_temp": "Warning message displayed on [[Special:Block]] if the option \"hide username\" is selected but the expiry time is not infinite.", diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index b29d333cb2..c2917b66b9 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -265,6 +265,7 @@ class ApiBlockTest extends ApiTestCase { 'partial' => true, 'pagerestrictions' => $title, 'namespacerestrictions' => $namespace, + 'allowusertalk' => true, ] ); $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php index 86e3295eb8..5f11a016bf 100644 --- a/tests/phpunit/includes/specials/SpecialBlockTest.php +++ b/tests/phpunit/includes/specials/SpecialBlockTest.php @@ -391,6 +391,78 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertSame( 0, $count ); } + /** + * @dataProvider provideProcessFormErrors + * @covers ::processForm() + */ + public function testProcessFormErrors( $data, $expected, $config = [] ) { + $defaultConfig = [ + 'wgEnablePartialBlocks' => true, + 'wgBlockAllowsUTEdit' => true, + ]; + + $this->setMwGlobals( array_merge( $defaultConfig, $config ) ); + + $defaultData = [ + 'Target' => '1.2.3.4', + 'Expiry' => 'infinity', + 'Reason' => [ 'bad reason' ], + 'Confirm' => false, + 'PageRestrictions' => '', + 'NamespaceRestrictions' => '', + ]; + + $context = RequestContext::getMain(); + $page = $this->newSpecialPage(); + $result = $page->processForm( array_merge( $defaultData, $data ), $context ); + + $this->assertEquals( $result[0], $expected ); + } + + public function provideProcessFormErrors() { + return [ + 'Invalid expiry' => [ + [ + 'Expiry' => 'invalid', + ], + 'ipb_expiry_invalid', + ], + 'Expiry is in the past' => [ + [ + 'Expiry' => 'yesterday', + ], + 'ipb_expiry_old', + ], + 'HideUser with wrong permissions' => [ + [ + 'HideUser' => 1, + ], + 'badaccess-group0', + ], + 'Bad ip address' => [ + [ + 'Target' => '1.2.3.4/1234', + ], + 'badipaddress', + ], + 'Edit user talk page invalid with no restrictions' => [ + [ + 'EditingRestriction' => 'partial', + 'DisableUTEdit' => 1, + ], + 'ipb-prevent-user-talk-edit', + ], + 'Edit user talk page invalid with namespace restriction != NS_USER_TALK ' => [ + [ + 'EditingRestriction' => 'partial', + 'DisableUTEdit' => 1, + 'NamespaceRestrictions' => NS_USER + ], + 'ipb-prevent-user-talk-edit', + ], + ]; + } + /** * @dataProvider provideCheckUnblockSelf * @covers ::checkUnblockSelf