Simplify boolean logic for Special:Block widgets
authorThalia <thalia.e.chan@googlemail.com>
Mon, 14 Jan 2019 20:51:20 +0000 (20:51 +0000)
committerThalia <thalia.e.chan@googlemail.com>
Wed, 16 Jan 2019 15:37:43 +0000 (15:37 +0000)
The boolean logic controlling the showing/hiding of widgets on
Special:Block could be expressed more simply. The logic is
becoming more complex due to partial blocks, so now is a good
time to rephrase it.

This removes safeguards against passing undefined to toggle,
so make sure none of the checks ever return undefined.

Change-Id: I1e0eb288db708be951fe5cf11f658725a38a7c4d

resources/src/mediawiki.special.block.js

index cd50369..b6d9b48 100644 (file)
                                isIpRange = isIp && blocktarget.match( /\/\d+$/ ),
                                isNonEmptyIp = isIp && !isEmpty,
                                expiryValue = expiryWidget.getValue(),
-                               // infinityValues  are the values the SpecialBlock class accepts as infinity (sf. wfIsInfinity)
+                               // 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() : undefined;
+                               editingIsSelected = editingWidget ? editingWidget.isSelected() : false;
 
                        if ( enableAutoblockField ) {
-                               enableAutoblockField.toggle( !( isNonEmptyIp ) );
+                               enableAutoblockField.toggle( !isNonEmptyIp );
                        }
                        if ( hideUserField ) {
-                               hideUserField.toggle( !( isNonEmptyIp || !isIndefinite ) );
+                               hideUserField.toggle( !isNonEmptyIp && isIndefinite );
                        }
                        if ( anonOnlyField ) {
-                               anonOnlyField.toggle( !( !isIp && !isEmpty ) );
+                               anonOnlyField.toggle( isIp || isEmpty );
                        }
                        if ( watchUserField ) {
-                               watchUserField.toggle( !( isIpRange && !isEmpty ) );
+                               watchUserField.toggle( !isIpRange || isEmpty );
                        }
                        if ( pageRestrictionsWidget ) {
                                editingRestrictionWidget.setDisabled( !editingIsSelected );
                                // TODO: (T210475) this option is disabled for partial blocks unless
                                // a namespace restriction for User_talk namespace is in place.
                                // This needs to be updated once Namespace restrictions is available
-                               if ( editingRestrictionValue === 'partial' && editingIsSelected ) {
-                                       preventTalkPageEdit.setDisabled( true );
-                               } else {
-                                       preventTalkPageEdit.setDisabled( false );
-                               }
+                               preventTalkPageEdit.setDisabled( editingRestrictionValue === 'partial' && editingIsSelected );
                        }
 
                }