Merge "mediawiki.loader: Clean up unit tests"
[lhc/web/wiklou.git] / includes / api / ApiUserrights.php
index d857e4a..56c2c84 100644 (file)
@@ -58,20 +58,23 @@ class ApiUserrights extends ApiBase {
                $params = $this->extractRequestParams();
 
                // Figure out expiry times from the input
-               // @todo Remove this isset check when removing $wgDisableUserGroupExpiry
+               // $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 ) {
@@ -109,7 +112,7 @@ 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'],
+                       $user, (array)$add, (array)$params['remove'],
                        $params['reason'], $tags, $groupExpiries
                );
 
@@ -185,6 +188,7 @@ class ApiUserrights extends ApiBase {
                                ApiBase::PARAM_ISMULTI => true
                        ],
                ];
+               // CentralAuth's ApiGlobalUserRights subclass can't handle expiries
                if ( !$this->getUserRightsPage()->canProcessExpiries() ) {
                        unset( $a['expiry'] );
                }