Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[lhc/web/wiklou.git] / includes / api / ApiUserrights.php
index 2a364d9..47f3bc5 100644 (file)
@@ -58,20 +58,23 @@ class ApiUserrights extends ApiBase {
                $params = $this->extractRequestParams();
 
                // Figure out expiry times from the input
-               // $params['expiry'] may not be set in subclasses
+               // $params['expiry'] is not set in CentralAuth's ApiGlobalUserRights subclass
                if ( isset( $params['expiry'] ) ) {
                        $expiry = (array)$params['expiry'];
                } else {
                        $expiry = [ 'infinity' ];
                }
-               if ( count( $expiry ) !== count( $params['add'] ) ) {
+               $add = (array)$params['add'];
+               if ( !$add ) {
+                       $expiry = [];
+               } elseif ( count( $expiry ) !== count( $add ) ) {
                        if ( count( $expiry ) === 1 ) {
-                               $expiry = array_fill( 0, count( $params['add'] ), $expiry[0] );
+                               $expiry = array_fill( 0, count( $add ), $expiry[0] );
                        } else {
                                $this->dieWithError( [
                                        'apierror-toofewexpiries',
                                        count( $expiry ),
-                                       count( $params['add'] )
+                                       count( $add )
                                ] );
                        }
                }
@@ -79,7 +82,7 @@ class ApiUserrights extends ApiBase {
                // Validate the expiries
                $groupExpiries = [];
                foreach ( $expiry as $index => $expiryValue ) {
-                       $group = $params['add'][$index];
+                       $group = $add[$index];
                        $groupExpiries[$group] = UserrightsPage::expiryToTimestamp( $expiryValue );
 
                        if ( $groupExpiries[$group] === false ) {
@@ -97,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 );
@@ -109,8 +112,9 @@ class ApiUserrights extends ApiBase {
                $r['user'] = $user->getName();
                $r['userid'] = $user->getId();
                list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups(
-                       $user, (array)$params['add'], (array)$params['remove'],
-                       $params['reason'], $tags, $groupExpiries
+                       // Don't pass null to doSaveUserGroups() for array params, cast to empty array
+                       $user, (array)$add, (array)$params['remove'],
+                       $params['reason'], (array)$tags, $groupExpiries
                );
 
                $result = $this->getResult();
@@ -185,6 +189,7 @@ class ApiUserrights extends ApiBase {
                                ApiBase::PARAM_ISMULTI => true
                        ],
                ];
+               // CentralAuth's ApiGlobalUserRights subclass can't handle expiries
                if ( !$this->getUserRightsPage()->canProcessExpiries() ) {
                        unset( $a['expiry'] );
                }