50 private $mUser =
null;
63 parent::__construct( $mainModule, $moduleName );
64 $this->userGroupManager = $userGroupManager;
65 $this->watchedItemStore = $watchedItemStore;
69 $this->watchlistMaxDuration =
71 $this->watchlistManager = $watchlistManager;
72 $this->userOptionsLookup = $userOptionsLookup;
80 if ( !$this->
getAuthority()->isAllowed(
'userrights' ) ) {
81 $block = $pUser->getBlock( IDBAccessObject::READ_LATEST );
82 if ( $block && $block->isSitewide() ) {
90 $expiry = (array)
$params[
'expiry'];
94 } elseif ( count( $expiry ) !== count( $add ) ) {
95 if ( count( $expiry ) === 1 ) {
96 $expiry = array_fill( 0, count( $add ), $expiry[0] );
99 'apierror-toofewexpiries',
108 foreach ( $expiry as $index => $expiryValue ) {
109 $group = $add[$index];
112 if ( $groupExpiries[$group] ===
false ) {
117 if ( $groupExpiries[$group] && $groupExpiries[$group] <
wfTimestampNow() ) {
122 $user = $this->getUrUser(
$params );
127 if ( $tags !==
null ) {
129 if ( !$ableToTag->isOK() ) {
137 $r[
'user'] = $user->getName();
138 $r[
'userid'] = $user->getId( $user->getWikiId() );
139 [ $r[
'added'], $r[
'removed'] ] = $form->doSaveUserGroups(
150 $watchuser =
$params[
'watchuser'];
151 $userPage = Title::makeTitle(
NS_USER, $user->getName() );
152 if ( $watchuser && $user->getWikiId() === UserIdentity::LOCAL ) {
153 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
156 $watchlistExpiry =
null;
158 $r[
'watchuser'] = $watchuser;
159 if ( $watchlistExpiry !==
null ) {
161 $this->watchedItemStore,
177 private function getUrUser( array
$params ) {
178 if ( $this->mUser !==
null ) {
186 $form =
new SpecialUserRights();
188 $status = $form->fetchUser( $user );
189 if ( !$status->isOK() ) {
193 $this->mUser = $status->value;
195 return $status->value;
207 $allGroups = $this->userGroupManager->listAllGroups();
215 ParamValidator::PARAM_TYPE =>
'user',
216 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'id' ],
219 ParamValidator::PARAM_TYPE =>
'integer',
220 ParamValidator::PARAM_DEPRECATED =>
true,
223 ParamValidator::PARAM_TYPE => $allGroups,
224 ParamValidator::PARAM_ISMULTI => true
227 ParamValidator::PARAM_ISMULTI =>
true,
228 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
229 ParamValidator::PARAM_DEFAULT =>
'infinite',
232 ParamValidator::PARAM_TYPE => $allGroups,
233 ParamValidator::PARAM_ISMULTI => true
236 ParamValidator::PARAM_DEFAULT =>
''
243 ParamValidator::PARAM_TYPE =>
'tags',
244 ParamValidator::PARAM_ISMULTI => true
246 'watchuser' =>
false,
252 if ( $this->watchlistExpiryEnabled ) {
254 'watchlistexpiry' => [
255 ParamValidator::PARAM_TYPE =>
'expiry',
256 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
257 ExpiryDef::PARAM_USE_MAX =>
true,
270 return $this->getUrUser(
$params )->getName();
275 'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
276 =>
'apihelp-userrights-example-user',
277 'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
278 =>
'apihelp-userrights-example-userid',
279 'action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC'
280 =>
'apihelp-userrights-example-expiry',
285 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:User_group_membership';
290class_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,...
array $params
The job parameters.
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...