Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53123
Change subject: (bug 27551) Global group renaming
......................................................................
(bug 27551) Global group renaming
Change-Id: Ib400ebfdd90e6073d5f3a3d528e787e6a3582930
---
M CentralAuth.i18n.php
M CentralAuth.php
M CentralAuthUser.php
M specials/SpecialGlobalGroupPermissions.php
4 files changed, 107 insertions(+), 35 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/23/53123/1
diff --git a/CentralAuth.i18n.php b/CentralAuth.i18n.php
index c4ddd21..6c45c13 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-globalgrouppermissions-knownwiki' => "Wiki on which
they have an account:",
@@ -707,6 +709,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''\")",
@@ -726,7 +731,11 @@
Parameters:
* $1 - Name of the group',
'centralauth-editgroup-noset' => '{{Identical|None}}',
+ '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-reason' => '{{Identical|Reason}}',
+ 'centralauth-editgroup-submit' => 'Label of the button to submit
changes to the global group',
+ '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-globalgrouppermissions-knownwiki' =>
'{{doc-singularthey}}',
'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.',
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/CentralAuthUser.php b/CentralAuthUser.php
index b981fc4..fb19ee8 100644
--- a/CentralAuthUser.php
+++ b/CentralAuthUser.php
@@ -173,7 +173,7 @@
// since we're caching it.
$dbr = self::getCentralDB();
- $row = $dbr->selectRow(
+ $row = $dbr->selectRow(
array( 'globaluser', 'localuser' ),
array(
'gu_id', 'lu_wiki', 'gu_salt', 'gu_password',
'gu_auth_token',
diff --git a/specials/SpecialGlobalGroupPermissions.php
b/specials/SpecialGlobalGroupPermissions.php
index 1b24193..46c46e4 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();
@@ -254,16 +259,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_user'
+ );
+
+ 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 );
@@ -287,14 +324,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 );
@@ -347,20 +384,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( 'GlobalUsers', $newName ),
+ $reason,
+ array( SpecialPage::getTitleFor( 'GlobalUsers',
$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 ),
)
);
}
@@ -397,25 +477,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
*/
@@ -432,6 +493,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: newchange
Gerrit-Change-Id: Ib400ebfdd90e6073d5f3a3d528e787e6a3582930
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits