ApiBlock: Avoid PHP warning when partial blocks are enabled but not used
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 19 Dec 2018 16:11:59 +0000 (11:11 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 19 Dec 2018 16:14:50 +0000 (11:14 -0500)
If partial blocks are available but a sitewide block is being made,
$params['pagerestrictions'] is null and implode() raises a warning.
Since null casts to the empty array, it's easy enough to work around.

Also add a test hitting this case.

Change-Id: Id7e2559d7569031b7c1228adb0c0a14b3c1527c3

includes/api/ApiBlock.php
tests/phpunit/includes/api/ApiBlockTest.php

index 8976626..ed3d01c 100644 (file)
@@ -61,7 +61,7 @@ class ApiBlock extends ApiBase {
                                $editingRestriction = 'partial';
                        }
 
                                $editingRestriction = 'partial';
                        }
 
-                       $pageRestrictions = implode( "\n", $params['pagerestrictions'] );
+                       $pageRestrictions = implode( "\n", (array)$params['pagerestrictions'] );
                }
 
                if ( $params['userid'] !== null ) {
                }
 
                if ( $params['userid'] !== null ) {
index e229f0c..feafdef 100644 (file)
@@ -215,6 +215,19 @@ class ApiBlockTest extends ApiTestCase {
                $this->doBlock( [ 'expiry' => '' ] );
        }
 
                $this->doBlock( [ 'expiry' => '' ] );
        }
 
+       public function testBlockWithoutRestrictions() {
+               $this->setMwGlobals( [
+                       'wgEnablePartialBlocks' => true,
+               ] );
+
+               $this->doBlock();
+
+               $block = Block::newFromTarget( $this->mUser->getName() );
+
+               $this->assertTrue( $block->isSitewide() );
+               $this->assertCount( 0, $block->getRestrictions() );
+       }
+
        public function testBlockWithRestrictions() {
                $this->setMwGlobals( [
                        'wgEnablePartialBlocks' => true,
        public function testBlockWithRestrictions() {
                $this->setMwGlobals( [
                        'wgEnablePartialBlocks' => true,