$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 )
] );
}
}
// 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 ) {
$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 );
$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();
ApiBase::PARAM_ISMULTI => true
],
];
+ // CentralAuth's ApiGlobalUserRights subclass can't handle expiries
if ( !$this->getUserRightsPage()->canProcessExpiries() ) {
unset( $a['expiry'] );
}