X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiUserrights.php;h=2a364d9756799ee0ebea7c52de1d3010e29b8033;hb=59ce3456a8007d76875fe8fb21eff4a90b214034;hp=4ef974cfcee68ab07ded307693d8bc1b9a5112cb;hpb=f987604187b5c469916241ce4a36c03950080dbd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 4ef974cfce..2a364d9756 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -1,9 +1,7 @@ .@gmail.com" * @@ -59,6 +57,41 @@ class ApiUserrights extends ApiBase { $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']; @@ -76,8 +109,8 @@ 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 + $user, (array)$params['add'], (array)$params['remove'], + $params['reason'], $tags, $groupExpiries ); $result = $this->getResult(); @@ -120,7 +153,7 @@ class ApiUserrights extends ApiBase { } public function getAllowedParams() { - return [ + $a = [ 'user' => [ ApiBase::PARAM_TYPE => 'user', ], @@ -131,6 +164,11 @@ class ApiUserrights extends ApiBase { 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 @@ -147,6 +185,10 @@ class ApiUserrights extends ApiBase { ApiBase::PARAM_ISMULTI => true ], ]; + if ( !$this->getUserRightsPage()->canProcessExpiries() ) { + unset( $a['expiry'] ); + } + return $a; } public function needsToken() { @@ -158,15 +200,20 @@ class ApiUserrights extends ApiBase { } 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'; } }