* @return bool|array
*/
public static function processForm( array $data, IContextSource $context ) {
- global $wgBlockAllowsUTEdit, $wgHideUserContribLimit;
-
$performer = $context->getUser();
$enablePartialBlocks = $context->getConfig()->get( 'EnablePartialBlocks' );
$isPartialBlock = $enablePartialBlocks &&
}
# 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 );
$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'] );
"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.",
"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.",
'partial' => true,
'pagerestrictions' => $title,
'namespacerestrictions' => $namespace,
+ 'allowusertalk' => true,
] );
$block = DatabaseBlock::newFromTarget( $this->mUser->getName() );
$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