From 351a699180b6dc9999afeb1646168146f608da2d Mon Sep 17 00:00:00 2001 From: Eddie Greiner-Petter Date: Fri, 19 May 2017 15:49:20 +0200 Subject: [PATCH] Hide "hideuser" on Special:Block for non-infinite blocks Users with the hideuser right have an extra checkmark on Special:Block to hide user, however this functionality can only be used on registered users (not IPs) and only if a block is set to never expire. With this js enhancement, hide the "hideuser" checkbox and label if the block time is not set to infinite (either as selected from the dropdown or written into the "other" input box). Attribution to meta.wikimedia.org/wiki/User:Margott who uploaded a draft for this patch on the task a while ago. Bug: T133036 Change-Id: Ia8c3e25d923e1df57d5afd69e9de3d6f2543f628 --- includes/GlobalFunctions.php | 1 + .../mediawiki.special.block.js | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 92cb8d8569..70784ba5a7 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3617,6 +3617,7 @@ function wfCanIPUseHTTPS( $ip ) { * @since 1.25 */ function wfIsInfinity( $str ) { + // These are hardcoded elsewhere in MediaWiki (e.g. mediawiki.special.block.js). $infinityValues = [ 'infinite', 'indefinite', 'infinity', 'never' ]; return in_array( $str, $infinityValues ); } diff --git a/resources/src/mediawiki.special/mediawiki.special.block.js b/resources/src/mediawiki.special/mediawiki.special.block.js index aca335ee50..8d8841099b 100644 --- a/resources/src/mediawiki.special/mediawiki.special.block.js +++ b/resources/src/mediawiki.special/mediawiki.special.block.js @@ -7,19 +7,30 @@ $anonOnlyRow = $( '#mw-input-wpHardBlock' ).closest( 'tr' ), $enableAutoblockRow = $( '#mw-input-wpAutoBlock' ).closest( 'tr' ), $hideUser = $( '#mw-input-wpHideUser' ).closest( 'tr' ), - $watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' ); + $watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' ), + $expiry = $( '#mw-input-wpExpiry' ), + $otherExpiry = $( '#mw-input-wpExpiry-other' ); function updateBlockOptions( instant ) { var blocktarget = $.trim( $blockTarget.val() ), isEmpty = blocktarget === '', isIp = mw.util.isIPAddress( blocktarget, true ), - isIpRange = isIp && blocktarget.match( /\/\d+$/ ); + isIpRange = isIp && blocktarget.match( /\/\d+$/ ), + isNonEmptyIp = isIp && !isEmpty, + expiryValue = $expiry.val(), + // infinityValues are the values the SpecialBlock class accepts as infinity (sf. wfIsInfinity) + infinityValues = [ 'infinite', 'indefinite', 'infinity', 'never' ], + isIndefinite = $.inArray( expiryValue, infinityValues ) !== -1 || + ( expiryValue === 'other' && $.inArray( $otherExpiry.val(), infinityValues ) !== -1 ); - if ( isIp && !isEmpty ) { + if ( isNonEmptyIp ) { $enableAutoblockRow.goOut( instant ); - $hideUser.goOut( instant ); } else { $enableAutoblockRow.goIn( instant ); + } + if ( isNonEmptyIp || !isIndefinite ) { + $hideUser.goOut( instant ); + } else { $hideUser.goIn( instant ); } if ( !isIp && !isEmpty ) { @@ -37,6 +48,8 @@ if ( $blockTarget.length ) { // Bind functions so they're checked whenever stuff changes $blockTarget.keyup( updateBlockOptions ); + $expiry.change( updateBlockOptions ); + $otherExpiry.keyup( updateBlockOptions ); // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours) updateBlockOptions( /* instant= */ true ); -- 2.20.1