Georggi199 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/330116 )

Change subject: Add tags support to userrights
......................................................................

Add tags support to userrights

Bug: T97720
Change-Id: I4f6dacd0ddf7b45d62aff6f85c329bc15be27daf
---
M includes/api/ApiUserrights.php
M includes/specials/SpecialUserrights.php
2 files changed, 23 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/16/330116/1

diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php
index 79c6866..d5392a6 100644
--- a/includes/api/ApiUserrights.php
+++ b/includes/api/ApiUserrights.php
@@ -61,13 +61,23 @@
 
                $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'], 
$params['tags']
                );
 
                $result = $this->getResult();
@@ -111,6 +121,10 @@
 
        public function getAllowedParams() {
                return [
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true
+                       ],
                        'user' => [
                                ApiBase::PARAM_TYPE => 'user',
                        ],
diff --git a/includes/specials/SpecialUserrights.php 
b/includes/specials/SpecialUserrights.php
index c869528..aeec2d6 100644
--- a/includes/specials/SpecialUserrights.php
+++ b/includes/specials/SpecialUserrights.php
@@ -233,9 +233,10 @@
         * @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
         * @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 @@
                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 @@
         * @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 @@
                        '5::newgroups' => $newGroups,
                ] );
                $logid = $logEntry->insert();
+               if ( count( $tags ) ) {
+                       $logEntry->setTags( $tags );
+               }
                $logEntry->publish( $logid );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/330116
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f6dacd0ddf7b45d62aff6f85c329bc15be27daf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Georggi199 <bmp2...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to