From b20e49709ff3094c99802d997d4f5a7e44d39137 Mon Sep 17 00:00:00 2001 From: Dayllan Maza Date: Tue, 12 Mar 2019 12:42:03 -0400 Subject: [PATCH] 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 --- includes/specials/SpecialBlock.php | 18 ++++++++++++++++++ resources/src/mediawiki.special.block.js | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) 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() { -- 2.20.1