From: Dayllan Maza Date: Tue, 12 Mar 2019 16:42:03 +0000 (-0400) Subject: Fix account create checkbox bug X-Git-Tag: 1.34.0-rc.0~2434^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/voir.php?a=commitdiff_plain;h=b20e49709ff3094c99802d997d4f5a7e44d39137;p=lhc%2Fweb%2Fwiklou.git Fix account create checkbox bug When a block is being created on Special:Block, the "create account" checkbox is checked by default if the block is set to "Sitewide" and unchecked by default if the block is set to "partial". There are multiple scenarios where the checkbox should not check and uncheck according to the type of block. 1.- When editing a block. This means that an admin already saved the the block so we shouldn't mess with the options 2.- After posting the form. An admin was ready to save and it didn't happen for whatever reason. Still we shouldn't mess with the options 3.- After manually clicking the checkbox itself (already working before this patch) Bug: T216845 Change-Id: I39b723d1f638d016c74ec20639efeecac95d8cdd --- diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 7330e7751e..02a8d009d4 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -308,6 +308,18 @@ class SpecialBlock extends FormSpecialPage { 'cssclass' => 'mw-block-confirm', ]; + // Block Id if a block already exists matching the target + $a['BlockId'] = [ + 'type' => 'hidden', + 'default' => '', + ]; + + // Has the form been submitted + $a['WasPosted'] = [ + 'type' => 'hidden', + 'default' => '', + ]; + $this->maybeAlterFormDefaults( $a ); // Allow extensions to add more fields @@ -383,10 +395,16 @@ class SpecialBlock extends FormSpecialPage { $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry ); } + $fields['BlockId']['default'] = $block->getId(); + $this->alreadyBlocked = true; $this->preErrors[] = [ 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ]; } + if ( $this->getRequest()->wasPosted() ) { + $fields['WasPosted']['default'] = true; + } + # We always need confirmation to do HideUser if ( $this->requestedHideUser ) { $fields['Confirm']['type'] = 'check'; diff --git a/resources/src/mediawiki.special.block.js b/resources/src/mediawiki.special.block.js index 02e380ae59..3e6f684515 100644 --- a/resources/src/mediawiki.special.block.js +++ b/resources/src/mediawiki.special.block.js @@ -26,7 +26,7 @@ pageRestrictionsWidget = infuseIfExists( $( '#mw-input-wpPageRestrictions' ) ), namespaceRestrictionsWidget = infuseIfExists( $( '#mw-input-wpNamespaceRestrictions' ) ), createAccountWidget = infuseIfExists( $( '#mw-input-wpCreateAccount' ) ), - userChangedCreateAccount = false, + userChangedCreateAccount = $( '#mw-input-wpBlockId' ).val() || $( '#mw-input-wpWasPosted' ).val() || false, updatingBlockOptions = false; function updateBlockOptions() {