X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.special.block.js;h=b6d9b48164a50fd136d8e8963464de099dca45f4;hb=d773ec9dcd71bd584556fc53dda170b172ac2372;hp=1852231e50adf938f0f408add1c753b5ad4a47c4;hpb=988af574cb66f560f37feb2700a514a2287d445f;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.special.block.js b/resources/src/mediawiki.special.block.js index 1852231e50..b6d9b48164 100644 --- a/resources/src/mediawiki.special.block.js +++ b/resources/src/mediawiki.special.block.js @@ -3,25 +3,26 @@ */ ( function () { // Like OO.ui.infuse(), but if the element doesn't exist, return null instead of throwing an exception. - function infuseOrNull( elem ) { - try { - return OO.ui.infuse( elem ); - } catch ( er ) { + function infuseIfExists( $el ) { + if ( !$el.length ) { return null; } + return OO.ui.infuse( $el ); } $( function () { // This code is also loaded on the "block succeeded" page where there is no form, // so username and expiry fields might also be missing. - var blockTargetWidget = infuseOrNull( 'mw-bi-target' ), - anonOnlyField = infuseOrNull( $( '#mw-input-wpHardBlock' ).closest( '.oo-ui-fieldLayout' ) ), - enableAutoblockField = infuseOrNull( $( '#mw-input-wpAutoBlock' ).closest( '.oo-ui-fieldLayout' ) ), - hideUserField = infuseOrNull( $( '#mw-input-wpHideUser' ).closest( '.oo-ui-fieldLayout' ) ), - watchUserField = infuseOrNull( $( '#mw-input-wpWatch' ).closest( '.oo-ui-fieldLayout' ) ), - expiryWidget = infuseOrNull( 'mw-input-wpExpiry' ), - editingRestrictionWidget = infuseOrNull( 'mw-input-wpEditingRestriction' ), - pageRestrictionsWidget = infuseOrNull( 'mw-input-wpPageRestrictions' ); + var blockTargetWidget = infuseIfExists( $( '#mw-bi-target' ) ), + anonOnlyField = infuseIfExists( $( '#mw-input-wpHardBlock' ).closest( '.oo-ui-fieldLayout' ) ), + enableAutoblockField = infuseIfExists( $( '#mw-input-wpAutoBlock' ).closest( '.oo-ui-fieldLayout' ) ), + hideUserField = infuseIfExists( $( '#mw-input-wpHideUser' ).closest( '.oo-ui-fieldLayout' ) ), + watchUserField = infuseIfExists( $( '#mw-input-wpWatch' ).closest( '.oo-ui-fieldLayout' ) ), + expiryWidget = infuseIfExists( $( '#mw-input-wpExpiry' ) ), + editingWidget = infuseIfExists( $( '#mw-input-wpEditing' ) ), + editingRestrictionWidget = infuseIfExists( $( '#mw-input-wpEditingRestriction' ) ), + preventTalkPageEdit = infuseIfExists( $( '#mw-input-wpDisableUTEdit' ) ), + pageRestrictionsWidget = infuseIfExists( $( '#mw-input-wpPageRestrictions' ) ); function updateBlockOptions() { var blocktarget = blockTargetWidget.getValue().trim(), @@ -30,33 +31,47 @@ 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; + editingRestrictionValue = editingRestrictionWidget ? editingRestrictionWidget.getValue() : 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 ) { - pageRestrictionsWidget.setDisabled( editingRestrictionValue === 'sitewide' ); + editingRestrictionWidget.setDisabled( !editingIsSelected ); + pageRestrictionsWidget.setDisabled( !editingIsSelected || editingRestrictionValue === 'sitewide' ); } + if ( preventTalkPageEdit ) { + // 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 + preventTalkPageEdit.setDisabled( editingRestrictionValue === 'partial' && editingIsSelected ); + } + } if ( blockTargetWidget ) { // Bind functions so they're checked whenever stuff changes blockTargetWidget.on( 'change', updateBlockOptions ); expiryWidget.on( 'change', updateBlockOptions ); - editingRestrictionWidget.on( 'change', updateBlockOptions ); + if ( editingRestrictionWidget ) { + editingRestrictionWidget.on( 'change', updateBlockOptions ); + } + if ( editingWidget ) { + editingWidget.on( 'change', updateBlockOptions ); + } // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours) updateBlockOptions();