Fix non-editing partial block creation on Special:Block
authorThalia <thalia.e.chan@googlemail.com>
Mon, 14 Jan 2019 14:58:42 +0000 (14:58 +0000)
committerThalia <thalia.e.chan@googlemail.com>
Tue, 15 Jan 2019 01:18:36 +0000 (01:18 +0000)
Bug: T213707
Change-Id: Iaf8b3a6a0b2715808c9e6f8de94d315404368b12

includes/specials/SpecialBlock.php

index 47d61b8..e47ef06 100644 (file)
@@ -399,6 +399,10 @@ class SpecialBlock extends FormSpecialPage {
                                        $pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
                                }
 
+                               if ( !$block->isSitewide() && empty( $pageRestrictions ) ) {
+                                       $fields['Editing']['default'] = false;
+                               }
+
                                // Sort the restrictions so they are in alphabetical order.
                                sort( $pageRestrictions );
                                $fields['PageRestrictions']['default'] = implode( "\n", $pageRestrictions );
@@ -1158,6 +1162,12 @@ class SpecialBlock extends FormSpecialPage {
         * @return bool|array True for success, false for didn't-try, array of errors on failure
         */
        public function onSubmit( array $data, HTMLForm $form = null ) {
+               // If "Editing" checkbox is unchecked, the block must be a partial block affecting
+               // actions other than editing, and there must be no restrictions.
+               if ( isset( $data['Editing'] ) && $data['Editing'] === false ) {
+                       $data['EditingRestriction'] = 'partial';
+                       $data['PageRestrictions'] = [];
+               }
                return self::processForm( $data, $form->getContext() );
        }