From 244f88c255a553e4a3a4b501e148cea63d5c43e7 Mon Sep 17 00:00:00 2001 From: Yuriy Shnitkovskiy Date: Mon, 2 Jan 2017 13:26:36 +0200 Subject: [PATCH] Add tags support to userrights Bug: T97720 Change-Id: I4f6dacd0ddf7b45d62aff6f85c329bc15be27daf --- includes/api/ApiUserrights.php | 16 +++++++++++++++- includes/api/i18n/en.json | 1 + includes/api/i18n/qqq.json | 1 + includes/specials/SpecialUserrights.php | 11 ++++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 79c6866305..4ef974cfce 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -61,13 +61,23 @@ class ApiUserrights extends ApiBase { $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(); @@ -132,6 +142,10 @@ class ApiUserrights extends ApiBase { // Standard definition automatically inserted ApiBase::PARAM_HELP_MSG_APPEND => [ 'api-help-param-token-webui' ], ], + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true + ], ]; } diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index bdc5c805f9..bc9fbf6946 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1428,6 +1428,7 @@ "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 FooBot to group bot, and remove from groups sysop and bureaucrat.", "apihelp-userrights-example-userid": "Add the user with ID 123 to group bot, and remove from groups sysop and bureaucrat.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 69de916750..9d467cc528 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1329,6 +1329,7 @@ "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}}", diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index c86952861c..38bac297d7 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -233,9 +233,10 @@ class UserrightsPage extends SpecialPage { * @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(); @@ -289,7 +290,7 @@ class UserrightsPage extends SpecialPage { 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 ]; @@ -301,8 +302,9 @@ class UserrightsPage extends SpecialPage { * @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() ); @@ -312,6 +314,9 @@ class UserrightsPage extends SpecialPage { '5::newgroups' => $newGroups, ] ); $logid = $logEntry->insert(); + if ( count( $tags ) ) { + $logEntry->setTags( $tags ); + } $logEntry->publish( $logid ); } -- 2.20.1