1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*!
* JavaScript for Special:Block
*/
( function () {
// Like OO.ui.infuse(), but if the element doesn't exist, return null instead of throwing an exception.
function infuseIfExists( $el ) {
if ( !$el.length ) {
return null;
}
return OO.ui.infuse( $el );
}
$( () => {
let blockTargetWidget, anonOnlyWidget, enableAutoblockWidget, hideUserWidget, watchUserWidget = null,
expiryWidget, editingRestrictionWidget, partialActionsRestrictionsWidget, preventTalkPageEditWidget,
pageRestrictionsWidget, namespaceRestrictionsWidget, createAccountWidget,
userChangedCreateAccount, updatingBlockOptions;
function preserveSelectedStateOnDisable( widget ) {
let widgetWasSelected;
if ( !widget ) {
return;
}
// 'disable' event fires if disabled state changes
widget.on( 'disable', ( disabled ) => {
if ( disabled ) {
// Disabling an enabled widget
// Save selected and set selected to false
widgetWasSelected = widget.isSelected();
widget.setSelected( false );
} else {
// Enabling a disabled widget
// Set selected to the saved value
if ( widgetWasSelected !== undefined ) {
widget.setSelected( widgetWasSelected );
}
widgetWasSelected = undefined;
}
} );
}
function updateBlockOptions() {
const blocktarget = blockTargetWidget.getValue().trim(),
isEmpty = blocktarget === '',
isIp = mw.util.isIPAddress( blocktarget, true ),
isNonEmptyIp = isIp && !isEmpty,
expiryValue = expiryWidget.getValue(),
isIndefinite = mw.util.isInfinity( expiryValue ),
editingRestrictionValue = editingRestrictionWidget.getValue(),
isSitewide = editingRestrictionValue === 'sitewide';
enableAutoblockWidget.setDisabled( isNonEmptyIp );
anonOnlyWidget.setDisabled( !isIp && !isEmpty );
if ( hideUserWidget ) {
hideUserWidget.setDisabled( isNonEmptyIp || !isIndefinite || !isSitewide );
}
updateWatchOption( blocktarget );
pageRestrictionsWidget.setDisabled( isSitewide );
namespaceRestrictionsWidget.setDisabled( isSitewide );
if ( preventTalkPageEditWidget ) {
// Disable for partial blocks, unless the block is against the User_talk namespace
preventTalkPageEditWidget.setDisabled(
// Partial block that blocks editing and doesn't block the User_talk namespace
(
editingRestrictionValue === 'partial' &&
namespaceRestrictionsWidget.getValue().indexOf(
String( mw.config.get( 'wgNamespaceIds' ).user_talk )
) === -1
)
);
}
if ( !userChangedCreateAccount ) {
updatingBlockOptions = true;
createAccountWidget.setSelected( isSitewide );
updatingBlockOptions = false;
}
if ( partialActionsRestrictionsWidget ) {
partialActionsRestrictionsWidget.setDisabled( isSitewide );
}
}
function updateWatchOption( blocktarget ) {
const isEmpty = blocktarget === '',
isIp = mw.util.isIPAddress( blocktarget, true ),
isIpRange = isIp && blocktarget.match( /\/\d+$/ ),
isAutoBlock = blocktarget.match( /^#\d+$/ );
if ( watchUserWidget ) {
watchUserWidget.setDisabled( ( isAutoBlock || isIpRange ) && !isEmpty );
}
}
watchUserWidget = infuseIfExists( $( '#mw-input-wpWatch' ) );
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Unblock' ) {
const $wpTarget = $( '#mw-input-wpTarget' );
if ( $wpTarget.attr( 'type' ) === 'hidden' ) {
// target is not changeable, determine watch state once
updateWatchOption( $wpTarget.val() );
return;
}
blockTargetWidget = infuseIfExists( $wpTarget );
if ( blockTargetWidget ) {
blockTargetWidget.on( 'change', () => {
updateWatchOption( blockTargetWidget.getValue().trim() );
} );
updateWatchOption( blockTargetWidget.getValue().trim() );
}
return;
}
// This code is also loaded on the "block succeeded" page where there is no form,
// so check for block target widget; if it exists, the form is present
blockTargetWidget = infuseIfExists( $( '#mw-bi-target' ) );
if ( blockTargetWidget ) {
userChangedCreateAccount = mw.config.get( 'wgCreateAccountDirty' );
updatingBlockOptions = false;
// Always present if blockTargetWidget is present
expiryWidget = OO.ui.infuse( $( '#mw-input-wpExpiry' ) );
createAccountWidget = OO.ui.infuse( $( '#mw-input-wpCreateAccount' ) );
enableAutoblockWidget = OO.ui.infuse( $( '#mw-input-wpAutoBlock' ) );
anonOnlyWidget = OO.ui.infuse( $( '#mw-input-wpHardBlock' ) );
blockTargetWidget.on( 'change', updateBlockOptions );
expiryWidget.on( 'change', updateBlockOptions );
createAccountWidget.on( 'change', () => {
if ( !updatingBlockOptions ) {
userChangedCreateAccount = true;
}
} );
editingRestrictionWidget = OO.ui.infuse( $( '#mw-input-wpEditingRestriction' ) );
pageRestrictionsWidget = OO.ui.infuse( $( '#mw-input-wpPageRestrictions' ) );
namespaceRestrictionsWidget = OO.ui.infuse( $( '#mw-input-wpNamespaceRestrictions' ) );
editingRestrictionWidget.on( 'change', updateBlockOptions );
namespaceRestrictionsWidget.on( 'change', updateBlockOptions );
// Present for certain rights
hideUserWidget = infuseIfExists( $( '#mw-input-wpHideUser' ) );
// Present for certain global configs
preventTalkPageEditWidget = infuseIfExists( $( '#mw-input-wpDisableUTEdit' ) );
// Move up and always infuse when wgEnablePartialActionBlocks gets removed
partialActionsRestrictionsWidget = infuseIfExists( $( '.mw-block-action-restriction.oo-ui-checkboxMultiselectInputWidget' ) );
// When disabling checkboxes, preserve their selected state in case they are re-enabled
preserveSelectedStateOnDisable( enableAutoblockWidget );
preserveSelectedStateOnDisable( anonOnlyWidget );
preserveSelectedStateOnDisable( watchUserWidget );
preserveSelectedStateOnDisable( hideUserWidget );
preserveSelectedStateOnDisable( preventTalkPageEditWidget );
updateBlockOptions();
}
} );
}() );
|