API: Fix PHP Warning for "count(): Parameter must be an array"
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 19 Apr 2018 01:39:23 +0000 (02:39 +0100)
committerKrinkle <krinklemail@gmail.com>
Thu, 19 Apr 2018 17:59:53 +0000 (17:59 +0000)
Found by the new ApiUserrights test introduced in 5ab1bee6bcf:
> includes/specials/SpecialUserrights.php:462
> includes/specials/SpecialUserrights.php:405
> includes/api/ApiUserrights.php:116

The $tags parameter of the UserrightsPage::doSaveUserGroups()
method must be an array and is not nullable. Fix the caller
to not pass null, but an empty array.

Bug: T182377
Change-Id: Ic9be6a0bddfac023de765c810c07a64d651c33b4

includes/api/ApiUserrights.php

index 56c2c84..47f3bc5 100644 (file)
@@ -100,7 +100,7 @@ class ApiUserrights extends ApiBase {
                $tags = $params['tags'];
 
                // Check if user can add tags
-               if ( !is_null( $tags ) ) {
+               if ( $tags !== null ) {
                        $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $pUser );
                        if ( !$ableToTag->isOK() ) {
                                $this->dieStatus( $ableToTag );
@@ -112,8 +112,9 @@ class ApiUserrights extends ApiBase {
                $r['user'] = $user->getName();
                $r['userid'] = $user->getId();
                list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups(
+                       // Don't pass null to doSaveUserGroups() for array params, cast to empty array
                        $user, (array)$add, (array)$params['remove'],
-                       $params['reason'], $tags, $groupExpiries
+                       $params['reason'], (array)$tags, $groupExpiries
                );
 
                $result = $this->getResult();