37 private $mUser =
null;
49 parent::__construct( $mainModule, $moduleName );
50 $this->watchedItemStore = $watchedItemStore;
54 $this->watchlistMaxDuration =
56 $this->watchlistManager = $watchlistManager;
57 $this->userOptionsLookup = $userOptionsLookup;
65 if ( !$this->
getAuthority()->isAllowed(
'userrights' ) ) {
66 $block = $pUser->getBlock( IDBAccessObject::READ_LATEST );
67 if ( $block && $block->isSitewide() ) {
75 $expiry = (array)$params[
'expiry'];
76 $add = (array)$params[
'add'];
79 } elseif ( count( $expiry ) !== count( $add ) ) {
80 if ( count( $expiry ) === 1 ) {
81 $expiry = array_fill( 0, count( $add ), $expiry[0] );
84 'apierror-toofewexpiries',
93 foreach ( $expiry as $index => $expiryValue ) {
94 $group = $add[$index];
95 $groupExpiries[$group] = UserGroupAssignmentService::expiryToTimestamp( $expiryValue );
97 if ( $groupExpiries[$group] ===
false ) {
102 if ( $groupExpiries[$group] && $groupExpiries[$group] <
wfTimestampNow() ) {
107 $user = $this->getUrUser( $params );
109 $tags = $params[
'tags'];
112 if ( $tags !==
null ) {
113 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->
getAuthority() );
114 if ( !$ableToTag->isOK() ) {
120 $r[
'user'] = $user->getName();
121 $r[
'userid'] = $user->getId( $user->getWikiId() );
122 [ $r[
'added'], $r[
'removed'] ] = $this->userGroupAssignmentService->saveChangesToUserGroups(
127 (array)$params[
'remove'],
135 $watchuser = $params[
'watchuser'];
136 if ( $watchuser && $user->getWikiId() === UserIdentity::LOCAL ) {
137 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
140 $watchlistExpiry =
null;
142 $r[
'watchuser'] = $watchuser;
143 if ( $watchlistExpiry !==
null ) {
145 $this->watchedItemStore,
161 private function getUrUser( array $params ) {
162 if ( $this->mUser !==
null ) {
168 $userDesignator = $params[
'user'] ??
'#' . $params[
'userid'];
169 $status = $this->multiFormatUserIdentityLookup->getUserIdentity( $userDesignator, $this->
getAuthority() );
170 if ( !$status->isOK() ) {
174 $user = $status->value;
175 $canHaveRights = $this->userGroupAssignmentService->targetCanHaveUserGroups( $user );
176 if ( !$canHaveRights ) {
179 $user->isRegistered() ? [
'userrights-no-group', $user->getName() ] :
'nosuchusershort'
183 $this->mUser = $user;
200 $allGroups = $this->userGroupManager->listAllGroups();
208 ParamValidator::PARAM_TYPE =>
'user',
209 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'id' ],
212 ParamValidator::PARAM_TYPE =>
'integer',
213 ParamValidator::PARAM_DEPRECATED =>
true,
216 ParamValidator::PARAM_TYPE => $allGroups,
217 ParamValidator::PARAM_ISMULTI => true
220 ParamValidator::PARAM_ISMULTI =>
true,
221 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
222 ParamValidator::PARAM_DEFAULT =>
'infinite',
225 ParamValidator::PARAM_TYPE => $allGroups,
226 ParamValidator::PARAM_ISMULTI => true
229 ParamValidator::PARAM_DEFAULT =>
''
236 ParamValidator::PARAM_TYPE =>
'tags',
237 ParamValidator::PARAM_ISMULTI => true
239 'watchuser' =>
false,
245 if ( $this->watchlistExpiryEnabled ) {
247 'watchlistexpiry' => [
248 ParamValidator::PARAM_TYPE =>
'expiry',
249 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
250 ExpiryDef::PARAM_USE_MAX =>
true,
265 return $this->getUrUser( $params )->getName();
271 'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
272 =>
'apihelp-userrights-example-user',
273 'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
274 =>
'apihelp-userrights-example-userid',
275 'action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC'
276 =>
'apihelp-userrights-example-expiry',
282 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:User_group_membership';
287class_alias( ApiUserrights::class,
'ApiUserrights' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...