Fix account create checkbox bug
authorDayllan Maza <dmaza@wikimedia.org>
Tue, 12 Mar 2019 16:42:03 +0000 (12:42 -0400)
committerDayllan Maza <dmaza@wikimedia.org>
Thu, 21 Mar 2019 03:28:33 +0000 (23:28 -0400)
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
resources/src/mediawiki.special.block.js

index 7330e77..02a8d00 100644 (file)
@@ -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';
index 02e380a..3e6f684 100644 (file)
@@ -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() {