$user = $this->getUrUser( $params );
+ $tags = $params['tags'];
+
+ // Check if user can add tags
+ if ( !is_null( $tags ) ) {
+ $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $pUser );
+ if ( !$ableToTag->isOK() ) {
+ $this->dieStatus( $ableToTag );
+ }
+ }
+
$form = $this->getUserRightsPage();
$form->setContext( $this->getContext() );
$r['user'] = $user->getName();
$r['userid'] = $user->getId();
list( $r['added'], $r['removed'] ) = $form->doSaveUserGroups(
$user, (array)$params['add'],
- (array)$params['remove'], $params['reason']
+ (array)$params['remove'], $params['reason'], $tags
);
$result = $this->getResult();
// Standard definition automatically inserted
ApiBase::PARAM_HELP_MSG_APPEND => [ 'api-help-param-token-webui' ],
],
+ 'tags' => [
+ ApiBase::PARAM_TYPE => 'tags',
+ ApiBase::PARAM_ISMULTI => true
+ ],
];
}
"apihelp-userrights-param-add": "Add the user to these groups.",
"apihelp-userrights-param-remove": "Remove the user from these groups.",
"apihelp-userrights-param-reason": "Reason for the change.",
+ "apihelp-userrights-param-tags": "Change tags to apply to the entry in the user rights log.",
"apihelp-userrights-example-user": "Add user <kbd>FooBot</kbd> to group <kbd>bot</kbd>, and remove from groups <kbd>sysop</kbd> and <kbd>bureaucrat</kbd>.",
"apihelp-userrights-example-userid": "Add the user with ID <kbd>123</kbd> to group <kbd>bot</kbd>, and remove from groups <kbd>sysop</kbd> and <kbd>bureaucrat</kbd>.",
"apihelp-userrights-param-add": "{{doc-apihelp-param|userrights|add}}",
"apihelp-userrights-param-remove": "{{doc-apihelp-param|userrights|remove}}",
"apihelp-userrights-param-reason": "{{doc-apihelp-param|userrights|reason}}",
+ "apihelp-userrights-param-tags": "{{doc-apihelp-param|userrights|tags}}",
"apihelp-userrights-example-user": "{{doc-apihelp-example|userrights}}",
"apihelp-userrights-example-userid": "{{doc-apihelp-example|userrights}}",
"apihelp-validatepassword-description": "{{doc-apihelp-description|validatepassword}}",
* @param array $add Array of groups to add
* @param array $remove Array of groups to remove
* @param string $reason Reason for group change
+ * @param array $tags Array of change tags to add to the log entry
* @return array Tuple of added, then removed groups
*/
- function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
+ function doSaveUserGroups( $user, $add, $remove, $reason = '', $tags = [] ) {
// Validate input set...
$isself = $user->getName() == $this->getUser()->getName();
$groups = $user->getGroups();
Hooks::run( 'UserRights', [ &$user, $add, $remove ], '1.26' );
if ( $newGroups != $oldGroups ) {
- $this->addLogEntry( $user, $oldGroups, $newGroups, $reason );
+ $this->addLogEntry( $user, $oldGroups, $newGroups, $reason, $tags );
}
return [ $add, $remove ];
* @param array $oldGroups
* @param array $newGroups
* @param array $reason
+ * @param array $tags
*/
- function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
+ function addLogEntry( $user, $oldGroups, $newGroups, $reason, $tags ) {
$logEntry = new ManualLogEntry( 'rights', 'rights' );
$logEntry->setPerformer( $this->getUser() );
$logEntry->setTarget( $user->getUserPage() );
'5::newgroups' => $newGroups,
] );
$logid = $logEntry->insert();
+ if ( count( $tags ) ) {
+ $logEntry->setTags( $tags );
+ }
$logEntry->publish( $logid );
}