Disallow user suppression in a partial block
authorThalia <thalia.e.chan@googlemail.com>
Mon, 14 Jan 2019 14:21:50 +0000 (14:21 +0000)
committerDmaza <dmaza@wikimedia.org>
Tue, 5 Feb 2019 23:11:12 +0000 (23:11 +0000)
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
languages/i18n/en.json
languages/i18n/qqq.json
resources/src/mediawiki.special.block.js

index bab3c8c..4321cde 100644 (file)
@@ -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' ];
index e86c6fa..81c305f 100644 (file)
        "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}}",
index db793e0..8b104dc 100644 (file)
        "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}}",
index b777c88..58409b4 100644 (file)
@@ -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' ) ),
                                // 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 );
                                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