| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
( function () { |
| 5 |
|
| 6 |
function infuseIfExists( $el ) { |
| 7 |
if ( !$el.length ) { |
| 8 |
return null; |
| 9 |
} |
| 10 |
return OO.ui.infuse( $el ); |
| 11 |
} |
| 12 |
|
| 13 |
$( () => { |
| 14 |
let blockTargetWidget, anonOnlyWidget, enableAutoblockWidget, hideUserWidget, watchUserWidget = null, |
| 15 |
expiryWidget, editingRestrictionWidget, partialActionsRestrictionsWidget, preventTalkPageEditWidget, |
| 16 |
pageRestrictionsWidget, namespaceRestrictionsWidget, createAccountWidget, |
| 17 |
userChangedCreateAccount, updatingBlockOptions; |
| 18 |
|
| 19 |
function preserveSelectedStateOnDisable( widget ) { |
| 20 |
let widgetWasSelected; |
| 21 |
|
| 22 |
if ( !widget ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
widget.on( 'disable', ( disabled ) => { |
| 28 |
if ( disabled ) { |
| 29 |
|
| 30 |
|
| 31 |
widgetWasSelected = widget.isSelected(); |
| 32 |
widget.setSelected( false ); |
| 33 |
} else { |
| 34 |
|
| 35 |
|
| 36 |
if ( widgetWasSelected !== undefined ) { |
| 37 |
widget.setSelected( widgetWasSelected ); |
| 38 |
} |
| 39 |
widgetWasSelected = undefined; |
| 40 |
} |
| 41 |
} ); |
| 42 |
} |
| 43 |
|
| 44 |
function updateBlockOptions() { |
| 45 |
const blocktarget = blockTargetWidget.getValue().trim(), |
| 46 |
isEmpty = blocktarget === '', |
| 47 |
isIp = mw.util.isIPAddress( blocktarget, true ), |
| 48 |
isNonEmptyIp = isIp && !isEmpty, |
| 49 |
expiryValue = expiryWidget.getValue(), |
| 50 |
isIndefinite = mw.util.isInfinity( expiryValue ), |
| 51 |
editingRestrictionValue = editingRestrictionWidget.getValue(), |
| 52 |
isSitewide = editingRestrictionValue === 'sitewide'; |
| 53 |
|
| 54 |
enableAutoblockWidget.setDisabled( isNonEmptyIp ); |
| 55 |
|
| 56 |
anonOnlyWidget.setDisabled( !isIp && !isEmpty ); |
| 57 |
|
| 58 |
if ( hideUserWidget ) { |
| 59 |
hideUserWidget.setDisabled( isNonEmptyIp || !isIndefinite || !isSitewide ); |
| 60 |
} |
| 61 |
|
| 62 |
updateWatchOption( blocktarget ); |
| 63 |
|
| 64 |
pageRestrictionsWidget.setDisabled( isSitewide ); |
| 65 |
namespaceRestrictionsWidget.setDisabled( isSitewide ); |
| 66 |
if ( preventTalkPageEditWidget ) { |
| 67 |
|
| 68 |
preventTalkPageEditWidget.setDisabled( |
| 69 |
|
| 70 |
( |
| 71 |
editingRestrictionValue === 'partial' && |
| 72 |
namespaceRestrictionsWidget.getValue().indexOf( |
| 73 |
String( mw.config.get( 'wgNamespaceIds' ).user_talk ) |
| 74 |
) === -1 |
| 75 |
) |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
if ( !userChangedCreateAccount ) { |
| 80 |
updatingBlockOptions = true; |
| 81 |
createAccountWidget.setSelected( isSitewide ); |
| 82 |
updatingBlockOptions = false; |
| 83 |
} |
| 84 |
|
| 85 |
if ( partialActionsRestrictionsWidget ) { |
| 86 |
partialActionsRestrictionsWidget.setDisabled( isSitewide ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
function updateWatchOption( blocktarget ) { |
| 91 |
const isEmpty = blocktarget === '', |
| 92 |
isIp = mw.util.isIPAddress( blocktarget, true ), |
| 93 |
isIpRange = isIp && blocktarget.match( /\/\d+$/ ), |
| 94 |
isAutoBlock = blocktarget.match( /^#\d+$/ ); |
| 95 |
|
| 96 |
if ( watchUserWidget ) { |
| 97 |
watchUserWidget.setDisabled( ( isAutoBlock || isIpRange ) && !isEmpty ); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
watchUserWidget = infuseIfExists( $( '#mw-input-wpWatch' ) ); |
| 102 |
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Unblock' ) { |
| 103 |
const $wpTarget = $( '#mw-input-wpTarget' ); |
| 104 |
if ( $wpTarget.attr( 'type' ) === 'hidden' ) { |
| 105 |
|
| 106 |
updateWatchOption( $wpTarget.val() ); |
| 107 |
return; |
| 108 |
} |
| 109 |
blockTargetWidget = infuseIfExists( $wpTarget ); |
| 110 |
if ( blockTargetWidget ) { |
| 111 |
blockTargetWidget.on( 'change', () => { |
| 112 |
updateWatchOption( blockTargetWidget.getValue().trim() ); |
| 113 |
} ); |
| 114 |
updateWatchOption( blockTargetWidget.getValue().trim() ); |
| 115 |
} |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
blockTargetWidget = infuseIfExists( $( '#mw-bi-target' ) ); |
| 122 |
|
| 123 |
if ( blockTargetWidget ) { |
| 124 |
userChangedCreateAccount = mw.config.get( 'wgCreateAccountDirty' ); |
| 125 |
updatingBlockOptions = false; |
| 126 |
|
| 127 |
|
| 128 |
expiryWidget = OO.ui.infuse( $( '#mw-input-wpExpiry' ) ); |
| 129 |
createAccountWidget = OO.ui.infuse( $( '#mw-input-wpCreateAccount' ) ); |
| 130 |
enableAutoblockWidget = OO.ui.infuse( $( '#mw-input-wpAutoBlock' ) ); |
| 131 |
anonOnlyWidget = OO.ui.infuse( $( '#mw-input-wpHardBlock' ) ); |
| 132 |
blockTargetWidget.on( 'change', updateBlockOptions ); |
| 133 |
expiryWidget.on( 'change', updateBlockOptions ); |
| 134 |
createAccountWidget.on( 'change', () => { |
| 135 |
if ( !updatingBlockOptions ) { |
| 136 |
userChangedCreateAccount = true; |
| 137 |
} |
| 138 |
} ); |
| 139 |
editingRestrictionWidget = OO.ui.infuse( $( '#mw-input-wpEditingRestriction' ) ); |
| 140 |
pageRestrictionsWidget = OO.ui.infuse( $( '#mw-input-wpPageRestrictions' ) ); |
| 141 |
namespaceRestrictionsWidget = OO.ui.infuse( $( '#mw-input-wpNamespaceRestrictions' ) ); |
| 142 |
editingRestrictionWidget.on( 'change', updateBlockOptions ); |
| 143 |
namespaceRestrictionsWidget.on( 'change', updateBlockOptions ); |
| 144 |
|
| 145 |
|
| 146 |
hideUserWidget = infuseIfExists( $( '#mw-input-wpHideUser' ) ); |
| 147 |
|
| 148 |
|
| 149 |
preventTalkPageEditWidget = infuseIfExists( $( '#mw-input-wpDisableUTEdit' ) ); |
| 150 |
|
| 151 |
partialActionsRestrictionsWidget = infuseIfExists( $( '.mw-block-action-restriction.oo-ui-checkboxMultiselectInputWidget' ) ); |
| 152 |
|
| 153 |
|
| 154 |
preserveSelectedStateOnDisable( enableAutoblockWidget ); |
| 155 |
preserveSelectedStateOnDisable( anonOnlyWidget ); |
| 156 |
preserveSelectedStateOnDisable( watchUserWidget ); |
| 157 |
preserveSelectedStateOnDisable( hideUserWidget ); |
| 158 |
preserveSelectedStateOnDisable( preventTalkPageEditWidget ); |
| 159 |
|
| 160 |
updateBlockOptions(); |
| 161 |
} |
| 162 |
} ); |
| 163 |
}() ); |