<?php
/**
- *
- *
- * Created on Mar 24, 2009
+ * API userrights module
*
* Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
*
$params = $this->extractRequestParams();
+ // Figure out expiry times from the input
+ // $params['expiry'] may not be set in subclasses
+ if ( isset( $params['expiry'] ) ) {
+ $expiry = (array)$params['expiry'];
+ } else {
+ $expiry = [ 'infinity' ];
+ }
+ if ( count( $expiry ) !== count( $params['add'] ) ) {
+ if ( count( $expiry ) === 1 ) {
+ $expiry = array_fill( 0, count( $params['add'] ), $expiry[0] );
+ } else {
+ $this->dieWithError( [
+ 'apierror-toofewexpiries',
+ count( $expiry ),
+ count( $params['add'] )
+ ] );
+ }
+ }
+
+ // Validate the expiries
+ $groupExpiries = [];
+ foreach ( $expiry as $index => $expiryValue ) {
+ $group = $params['add'][$index];
+ $groupExpiries[$group] = UserrightsPage::expiryToTimestamp( $expiryValue );
+
+ if ( $groupExpiries[$group] === false ) {
+ $this->dieWithError( [ 'apierror-invalidexpiry', wfEscapeWikiText( $expiryValue ) ] );
+ }
+
+ // not allowed to have things expiring in the past
+ if ( $groupExpiries[$group] && $groupExpiries[$group] < wfTimestampNow() ) {
+ $this->dieWithError( [ 'apierror-pastexpiry', wfEscapeWikiText( $expiryValue ) ] );
+ }
+ }
+
$user = $this->getUrUser( $params );
$tags = $params['tags'];
$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
+ $user, (array)$params['add'], (array)$params['remove'],
+ $params['reason'], $tags, $groupExpiries
);
$result = $this->getResult();
}
public function getAllowedParams() {
- return [
+ $a = [
'user' => [
ApiBase::PARAM_TYPE => 'user',
],
ApiBase::PARAM_TYPE => $this->getAllGroups(),
ApiBase::PARAM_ISMULTI => true
],
+ 'expiry' => [
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_ALLOW_DUPLICATES => true,
+ ApiBase::PARAM_DFLT => 'infinite',
+ ],
'remove' => [
ApiBase::PARAM_TYPE => $this->getAllGroups(),
ApiBase::PARAM_ISMULTI => true
ApiBase::PARAM_ISMULTI => true
],
];
+ if ( !$this->getUserRightsPage()->canProcessExpiries() ) {
+ unset( $a['expiry'] );
+ }
+ return $a;
}
public function needsToken() {
}
protected function getExamplesMessages() {
- return [
+ $a = [
'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
=> 'apihelp-userrights-example-user',
'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
=> 'apihelp-userrights-example-userid',
];
+ if ( $this->getUserRightsPage()->canProcessExpiries() ) {
+ $a['action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC']
+ = 'apihelp-userrights-example-expiry';
+ }
+ return $a;
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:User_group_membership';
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:User_group_membership';
}
}