CSteipp has submitted this change and it was merged.

Change subject: Allow global groups to be renamed
......................................................................


Allow global groups to be renamed

Bug: 27551
Change-Id: Ib400ebfdd90e6073d5f3a3d528e787e6a3582930
---
M CentralAuth.i18n.php
M CentralAuth.php
M specials/SpecialGlobalGroupPermissions.php
3 files changed, 106 insertions(+), 35 deletions(-)

Approvals:
  CSteipp: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/CentralAuth.i18n.php b/CentralAuth.i18n.php
index 0fbce84..54d746d 100644
--- a/CentralAuth.i18n.php
+++ b/CentralAuth.i18n.php
@@ -286,6 +286,7 @@
        'centralauth-rightslog-entry-groupperms'  => 'changed group permissions 
for $1 from $2 to $3',
        'centralauth-rightslog-entry-groupperms2' => 'changed group permissions 
for $1. Added $2; Removed $3',
        'centralauth-rightslog-entry-groupperms3' => 'changed group restricted 
wikis set for $1 from $2 to $3',
+       'centralauth-rightslog-entry-grouprename' => 'renamed group $2 to $1',
        'centralauth-rightslog-header'            => 'This log contains 
operations on global groups: membership and permissions changes',
 
        'centralauth-rightslog-entry-newset'      => 'created $2 wiki set $1 
with following wikis: $3',
@@ -329,12 +330,13 @@
        'centralauth-editgroup-members'                   => 'Member list:',
        'centralauth-editgroup-members-link'              => 
'[[Special:GlobalUsers/$1|List of users with $2 rights]]',
        'centralauth-editgroup-restrictions'              => 'Set of wikis 
where this group is active:',
+       'centralauth-editgroup-rename-taken'              => 'Renaming failed: 
There already is a group with the name $1.',
        'centralauth-editgroup-noset'                     => '(none)',
-       'centralauth-editgroup-submit'                    => 'Save changes to 
group permissions',
+       'centralauth-editgroup-submit'                    => 'Save global group 
changes',
        'centralauth-editgroup-perms'                     => 'Assigned 
permissions:',
        'centralauth-editgroup-reason'                    => 'Reason:',
-       'centralauth-editgroup-success'                   => 'Group permissions 
changed',
-       'centralauth-editgroup-success-text'              => 'You have 
successfully changed the group permissions for the $1 group.
+       'centralauth-editgroup-success'                   => 'Global group 
changed',
+       'centralauth-editgroup-success-text'              => 'Successfully 
updated the global group $1.
 [[Special:GlobalGroupPermissions|Return to group management]]',
        'centralauth-editgroup-editsets'                  => 
'([[Special:EditWikiSets|edit]])',
        'centralauth-editgroup-nowikiset'                 => 'None, applies to 
all wikis.',
@@ -708,6 +710,9 @@
 * $1 - the name of the group being changed
 * $2 - the name of the previous wiki set
 * $3 - the name of the new wiki set',
+       'centralauth-rightslog-entry-grouprename' => 'A log entry when a user 
renames a global group.
+* $1 is the title of the old group
+* $2 is the title of the new group',
        'centralauth-rightslog-entry-newset' => "* \$1 is the name of the wiki 
set (example: \"''Test''\")
 * \$2 is \"''{{msg-mw|Centralauth-rightslog-set-optin}}''\" or 
\"''{{msg-mw|Centralauth-rightslog-set-optout}}''\"
 * \$3 is a list of wikis (example: \"''srwiki, hrwiki''\")",
@@ -727,9 +732,12 @@
 Parameters:
 * $1 - Name of the group',
        'centralauth-editgroup-noset' => '{{Identical|None}}',
-       'centralauth-editgroup-reason' => '{{Identical|Reason}}',
+       'centralauth-editgroup-rename-taken'              => 'Shown in case the 
renaming of the global group failed because there already is a group with the 
new name. $1 is the name the user wanted to rename the group to.',
        'centralauth-editgroup-nowikiset' => 'Shown on 
Special:GlobalGroupPermissions for global groups which have no assigned 
WikiSet.',
        'centralauth-globalgrouppermissions-knownwiki' => 
'{{doc-singularthey}}',
+       'centralauth-editgroup-reason' => '{{Identical|Reason}}',
+       'centralauth-editgroup-success' => 'Subtitle of 
Special:GlobalGroupPermissions after a group has successfully been altered',
+       'centralauth-editgroup-success-text' => 'Text on 
Special:GlobalGroupPermissions after a group has successfully been altered. $1 
is the name of the global group.',
        'centralauth-editset' => 'Se trata de grupos (o conjuntos) de wikis que 
pueden definirse, y adonde se pueden restringir grupos de usuarios. P. ej, los 
usuarios del grupo "global bot" sólo pueden editar en las wikis del grupo 
"global bot wikis". Definitivamente no son "ajustes" (!).',
        'centralauth-editset-legend-rw' => 'The legend of the fieldset. 
Displayed when the user can edit.',
        'centralauth-editset-legend-ro' => 'The legend of the fieldset. 
Displayed when the user cannot edit.',
diff --git a/CentralAuth.php b/CentralAuth.php
index 3e275ab..22428b5 100644
--- a/CentralAuth.php
+++ b/CentralAuth.php
@@ -271,6 +271,7 @@
 $wgLogActions['gblrights/groupperms']  = 
'centralauth-rightslog-entry-groupperms';
 $wgLogActions['gblrights/groupprms2']  = 
'centralauth-rightslog-entry-groupperms2';
 $wgLogActions['gblrights/groupprms3']  = 
'centralauth-rightslog-entry-groupperms3';
+$wgLogActions['gblrights/grouprename'] = 
'centralauth-rightslog-entry-grouprename';
 
 foreach ( array( 'newset', 'setrename', 'setnewtype', 'setchange', 'deleteset' 
) as $type ) {
        $wgLogActionsHandlers["gblrights/{$type}"] = 'efHandleWikiSetLogEntry';
diff --git a/specials/SpecialGlobalGroupPermissions.php 
b/specials/SpecialGlobalGroupPermissions.php
index 94dac11..66ef338 100644
--- a/specials/SpecialGlobalGroupPermissions.php
+++ b/specials/SpecialGlobalGroupPermissions.php
@@ -132,7 +132,12 @@
 
                $fields = array();
 
-               $fields['centralauth-editgroup-name'] = $group;
+               if ( $editable ) {
+                       $fields['centralauth-editgroup-name'] = Xml::input( 
'wpGlobalGroupName', 50, $group );
+               } else {
+                       $fields['centralauth-editgroup-name'] = $group;
+               }
+
                if( $this->getUser()->isAllowed( 'editinterface' ) ) {
                        # Show edit link only to user with the editinterface 
right
                        $fields['centralauth-editgroup-display'] = $this->msg( 
'centralauth-editgroup-display-edit', $group, User::getGroupName( $group ) 
)->parse();
@@ -263,16 +268,48 @@
         */
        function doSubmit( $group ) {
                // Paranoia -- the edit token shouldn't match anyway
-               if ( !$this->userCanEdit( $this->getUser() ) )
+               if ( !$this->userCanEdit( $this->getUser() ) ) {
                        return;
+               }
+               $reason = $this->getRequest()->getVal( 'wpReason', '' );
 
+
+               // Global group rename
+               $newname = $this->getRequest()->getVal( 'wpGlobalGroupName', 
$group );
+               if ( $group != $newname ) {
+
+                       if ( in_array( $newname, 
CentralAuthUser::availableGlobalGroups() ) ) {
+                               $this->getOutput()->addWikiMsg( 
'centralauth-editgroup-rename-taken', $newname );
+                               return;
+                       }
+
+                       $dbw = CentralAuthUser::getCentralDB();
+                       $updates = array(
+                               'global_group_permissions' => 'ggp_group',
+                               'global_group_restrictions' => 'ggr_group',
+                               'global_user_groups' => 'gug_group'
+                       );
+
+                       foreach ( $updates as $table => $field ) {
+                               $dbw->update(
+                                       $table,
+                                       array( $field => $newname ),
+                                       array( $field => $group ),
+                                       __METHOD__
+                               );
+                       }
+                       $this->addRenameLog( $group, $newname, $reason );
+
+                       // The rest of the changes here will be performed on 
the "new" group
+                       $group = $newname;
+               }
+
+               // Permissions
                $newRights = array();
                $addRights = array();
                $removeRights = array();
                $oldRights = $this->getAssignedRights( $group );
                $allRights = User::getAllRights();
-
-               $reason = $this->getRequest()->getVal( 'wpReason', '' );
 
                foreach ( $allRights as $right ) {
                        $alreadyAssigned = in_array( $right, $oldRights );
@@ -296,14 +333,14 @@
 
                // Log it
                if ( !( count( $addRights ) == 0 && count( $removeRights ) == 0 
) )
-                       $this->addLogEntry( $group, $addRights, $removeRights, 
$reason );
+                       $this->addPermissionLog( $group, $addRights, 
$removeRights, $reason );
 
                // Change set
                $current = WikiSet::getWikiSetForGroup( $group );
                $new = $this->getRequest()->getVal( 'set' );
                if ( $current != $new ) {
                        $this->setRestrictions( $group, $new );
-                       $this->addLogEntry2( $group, $current, $new, $reason );
+                       $this->addWikiSetLog( $group, $current, $new, $reason );
                }
 
                $this->invalidateRightsCache( $group );
@@ -356,20 +393,63 @@
        }
 
        /**
-        * @param $group
-        * @param $addRights
-        * @param $removeRights
-        * @param $reason
+        * Log permission changes
+        *
+        * @param $group string
+        * @param $addRights array
+        * @param $removeRights array
+        * @param $reason string
         */
-       function addLogEntry( $group, $addRights, $removeRights, $reason ) {
+       function addPermissionLog( $group, $addRights, $removeRights, $reason ) 
{
                $log = new LogPage( 'gblrights' );
 
-               $log->addEntry( 'groupprms2',
+               $log->addEntry(
+                       'groupprms2',
                        SpecialPage::getTitleFor( 'GlobalUsers', $group ),
                        $reason,
                        array(
                                $this->makeRightsList( $addRights ),
                                $this->makeRightsList( $removeRights )
+                       )
+               );
+       }
+
+       /**
+        * Log the renaming of a global group
+        *
+        * @param $oldName string
+        * @param $newName string
+        * @param $reason string
+        */
+       function addRenameLog( $oldName, $newName, $reason ) {
+               $log = new LogPage( 'gblrights' );
+
+               $log->addEntry(
+                       'grouprename',
+                       SpecialPage::getTitleFor( 'GlobalGroupPermissions', 
$newName ),
+                       $reason,
+                       array( $oldName )
+               );
+       }
+
+       /**
+        * Log wikiset changes
+        *
+        * @param $group string
+        * @param $old string
+        * @param $new string
+        * @param $reason string
+        */
+       function addWikiSetLog( $group, $old, $new, $reason ) {
+               $log = new LogPage( 'gblrights' );
+
+               $log->addEntry(
+                       'groupprms3',
+                       SpecialPage::getTitleFor( 'GlobalUsers', $group ),
+                       $reason,
+                       array(
+                               $this->getWikiSetName( $old ),
+                               $this->getWikiSetName( $new ),
                        )
                );
        }
@@ -406,25 +486,6 @@
        }
 
        /**
-        * @param $group
-        * @param $old
-        * @param $new
-        * @param $reason
-        */
-       function addLogEntry2( $group, $old, $new, $reason ) {
-               $log = new LogPage( 'gblrights' );
-
-               $log->addEntry( 'groupprms3',
-                       SpecialPage::getTitleFor( 'GlobalUsers', $group ),
-                       $reason,
-                       array(
-                               $this->getWikiSetName( $old ),
-                               $this->getWikiSetName( $new ),
-                       )
-               );
-       }
-
-       /**
         * @param $id string|int
         * @return String
         */
@@ -441,6 +502,7 @@
         */
        function invalidateRightsCache( $group ) {
                // Figure out all the users in this group.
+               // Use the master over here as this could go horribly wrong 
with newly created or just renamed groups
                $dbr = CentralAuthUser::getCentralDB();
 
                $res = $dbr->select( array( 'global_user_groups', 'globaluser' 
), 'gu_name', array( 'gug_group' => $group, 'gu_id=gug_user' ), __METHOD__ );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib400ebfdd90e6073d5f3a3d528e787e6a3582930
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to