From 83407d97a136101dd130eb1dbb7186345a89b733 Mon Sep 17 00:00:00 2001 From: Thalia Date: Mon, 14 Jan 2019 14:21:50 +0000 Subject: [PATCH] Disallow user suppression in a partial block Hide the "hide user" checkbox on Special:Block if the block parameters specify a partial block. Return an error message if a partial block with user suppression is specified via the API. Also, make sure that an existing user suppression is lifted if the user's block is reset to a partial block. Bug: T210002 Change-Id: If42edfc85580d6bad6f4b397517e77e63deecc87 --- includes/specials/SpecialBlock.php | 15 +++++++++------ languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + resources/src/mediawiki.special.block.js | 16 +++++++++++----- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index bab3c8c5a3..4321cde053 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -739,6 +739,9 @@ class SpecialBlock extends FormSpecialPage { $performer = $context->getUser(); $enablePartialBlocks = $context->getConfig()->get( 'EnablePartialBlocks' ); + $isPartialBlock = $enablePartialBlocks && + isset( $data['EditingRestriction'] ) && + $data['EditingRestriction'] === 'partial'; // Handled by field validator callback // self::validateTargetField( $data['Target'] ); @@ -816,6 +819,10 @@ class SpecialBlock extends FormSpecialPage { return [ 'badaccess-group0' ]; } + if ( $isPartialBlock ) { + return [ 'ipb_hide_partial' ]; + } + # Recheck params here... if ( $type != Block::TYPE_USER ) { $data['HideUser'] = false; # IP users should not be hidden @@ -847,12 +854,8 @@ class SpecialBlock extends FormSpecialPage { $block->isAutoblocking( $data['AutoBlock'] ); $block->mHideName = $data['HideUser']; - if ( - $enablePartialBlocks && - isset( $data['EditingRestriction'] ) && - $data['EditingRestriction'] === 'partial' - ) { - $block->isSitewide( false ); + if ( $isPartialBlock ) { + $block->isSitewide( false ); } $reason = [ 'hookaborted' ]; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index e86c6fa125..81c305f59f 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -2694,6 +2694,7 @@ "ipb_expiry_old": "Expiry time is in the past.", "ipb_expiry_temp": "Hidden username blocks must be permanent.", "ipb_hide_invalid": "Unable to suppress this account; it has more than {{PLURAL:$1|one edit|$1 edits}}.", + "ipb_hide_partial": "Hidden username blocks must be sitewide blocks.", "ipb_already_blocked": "\"$1\" is already blocked.", "ipb-needreblock": "$1 is already blocked. Do you want to change the settings?", "ipb-otherblocks-header": "Other {{PLURAL:$1|block|blocks}}", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index db793e0ebe..8b104dcfb8 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -2899,6 +2899,7 @@ "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:BlockIP]] if the option \"hide username\" is selected but the expiry time is not infinite.", "ipb_hide_invalid": "Used as error message in [[Special:Block]].\n* $1 - Number of edits (Value of [[mw:Manual:$wgHideUserContribLimit]])", + "ipb_hide_partial": "Warning message displayed on [[Special:Block]] if the option \"hide username\" is selected but the block is a partial block.", "ipb_already_blocked": "{{Identical|$1 is already blocked}}", "ipb-needreblock": "Used in [[Special:Block]].\n* $1 - target username, can be used for GENDER support", "ipb-otherblocks-header": "[[File:Special.Block with other blocks from GlobalBlocking and TorBlocks.png|thumb|Example]]\nUsed on [[Special:Block]] as header for other blocks, i.e. from GlobalBlocking or TorBlocks\n\nParameters:\n* $1 - number of blocks\nSee also:\n* {{msg-mw|Ipblocklist-otherblocks}}", diff --git a/resources/src/mediawiki.special.block.js b/resources/src/mediawiki.special.block.js index b777c88ba7..58409b45c5 100644 --- a/resources/src/mediawiki.special.block.js +++ b/resources/src/mediawiki.special.block.js @@ -16,6 +16,7 @@ var blockTargetWidget = infuseIfExists( $( '#mw-bi-target' ) ), anonOnlyField = infuseIfExists( $( '#mw-input-wpHardBlock' ).closest( '.oo-ui-fieldLayout' ) ), enableAutoblockField = infuseIfExists( $( '#mw-input-wpAutoBlock' ).closest( '.oo-ui-fieldLayout' ) ), + hideUserWidget = infuseIfExists( $( '#mw-input-wpHideUser' ) ), hideUserField = infuseIfExists( $( '#mw-input-wpHideUser' ).closest( '.oo-ui-fieldLayout' ) ), watchUserField = infuseIfExists( $( '#mw-input-wpWatch' ).closest( '.oo-ui-fieldLayout' ) ), expiryWidget = infuseIfExists( $( '#mw-input-wpExpiry' ) ), @@ -35,14 +36,19 @@ // infinityValues are the values the SpecialBlock class accepts as infinity (sf. wfIsInfinity) infinityValues = [ 'infinite', 'indefinite', 'infinity', 'never' ], isIndefinite = infinityValues.indexOf( expiryValue ) !== -1, - editingRestrictionValue = editingRestrictionWidget ? editingRestrictionWidget.getValue() : undefined, - editingIsSelected = editingWidget ? editingWidget.isSelected() : false; + // editingRestrictionWidget only exists if partial blocks is enabled; if not, block must be sitewide + editingRestrictionValue = editingRestrictionWidget ? editingRestrictionWidget.getValue() : 'sitewide', + editingIsSelected = editingWidget ? editingWidget.isSelected() : false, + isSitewide = editingIsSelected && editingRestrictionValue === 'sitewide'; if ( enableAutoblockField ) { enableAutoblockField.toggle( !isNonEmptyIp ); } if ( hideUserField ) { - hideUserField.toggle( !isNonEmptyIp && isIndefinite ); + hideUserField.toggle( !isNonEmptyIp && isIndefinite && isSitewide ); + if ( !hideUserField.isVisible() ) { + hideUserWidget.setSelected( false ); + } } if ( anonOnlyField ) { anonOnlyField.toggle( isIp || isEmpty ); @@ -54,10 +60,10 @@ editingRestrictionWidget.setDisabled( !editingIsSelected ); } if ( pageRestrictionsWidget ) { - pageRestrictionsWidget.setDisabled( !editingIsSelected || editingRestrictionValue === 'sitewide' ); + pageRestrictionsWidget.setDisabled( !editingIsSelected || isSitewide ); } if ( namespaceRestrictionsWidget ) { - namespaceRestrictionsWidget.setDisabled( !editingIsSelected || editingRestrictionValue === 'sitewide' ); + namespaceRestrictionsWidget.setDisabled( !editingIsSelected || isSitewide ); } if ( preventTalkPageEdit && namespaceRestrictionsWidget ) { // This option is disabled for partial blocks unless a namespace restriction -- 2.20.1