Add tags support to userrights
authorYuriy Shnitkovskiy <dominno@ukr.net>
Mon, 2 Jan 2017 11:26:36 +0000 (13:26 +0200)
committerYuriy Shnitkovskiy <dominno@ukr.net>
Mon, 2 Jan 2017 11:41:05 +0000 (13:41 +0200)
Bug: T97720
Change-Id: I4f6dacd0ddf7b45d62aff6f85c329bc15be27daf

includes/api/ApiUserrights.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/specials/SpecialUserrights.php

index 79c6866..4ef974c 100644 (file)
@@ -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
+                       ],
                ];
        }
 
index bdc5c80..bc9fbf6 100644 (file)
        "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>.",
 
index 69de916..9d467cc 100644 (file)
        "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}}",
index c869528..38bac29 100644 (file)
@@ -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 );
        }