mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-12 09:26:05 +00:00
Merge "Add proper message when user group expiry is changed"
This commit is contained in:
commit
658b4a6a7d
36
Hooks.php
36
Hooks.php
|
@ -688,7 +688,9 @@ class EchoHooks {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function onUserGroupsChanged( $user, $add, $remove, $performer, $reason ) {
|
||||
public static function onUserGroupsChanged( $user, $add, $remove, $performer,
|
||||
$reason, array $oldUGMs = [], array $newUGMs = [] ) {
|
||||
|
||||
if ( !$performer ) {
|
||||
// TODO: Implement support for autopromotion
|
||||
return true;
|
||||
|
@ -704,13 +706,41 @@ class EchoHooks {
|
|||
return true;
|
||||
}
|
||||
|
||||
if ( $add || $remove ) {
|
||||
// If any old groups are in $add, those groups are having their expiry
|
||||
// changed, not actually being added
|
||||
$expiryChanged = [];
|
||||
$reallyAdded = [];
|
||||
foreach ( $add as $group ) {
|
||||
if ( isset( $oldUGMs[$group] ) ) {
|
||||
$expiryChanged[] = $group;
|
||||
} else {
|
||||
$reallyAdded[] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $expiryChanged ) {
|
||||
// use a separate notification for these, so the notification text doesn't
|
||||
// get too long
|
||||
EchoEvent::create(
|
||||
[
|
||||
'type' => 'user-rights',
|
||||
'extra' => [
|
||||
'user' => $user->getID(),
|
||||
'add' => $add,
|
||||
'expiry-changed' => $expiryChanged,
|
||||
'reason' => $reason,
|
||||
],
|
||||
'agent' => $performer,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if ( $reallyAdded || $remove ) {
|
||||
EchoEvent::create(
|
||||
[
|
||||
'type' => 'user-rights',
|
||||
'extra' => [
|
||||
'user' => $user->getID(),
|
||||
'add' => $reallyAdded,
|
||||
'remove' => $remove,
|
||||
'reason' => $reason,
|
||||
],
|
||||
|
|
|
@ -166,6 +166,7 @@
|
|||
"notification-header-user-rights-add-only": "{{GENDER:$4|Your}} user rights were {{GENDER:$1|changed}}. You have been added to: $2.",
|
||||
"notification-header-user-rights-remove-only": "{{GENDER:$4|Your}} user rights were {{GENDER:$1|changed}}. You are no longer a member of: $2.",
|
||||
"notification-header-user-rights-add-and-remove": "{{GENDER:$6|Your}} user rights were {{GENDER:$1|changed}}. You have been added to: $2. You are no longer a member of: $4.",
|
||||
"notification-header-user-rights-expiry-change": "The expiry of {{GENDER:$4|your}} membership in the following {{PLURAL:$3|group|groups}} has been {{GENDER:$1|changed}}: $2.",
|
||||
"notification-body-user-rights": "$1",
|
||||
"notification-header-welcome": "{{GENDER:$2|Welcome}} to {{SITENAME}}, $1! We're glad {{GENDER:$2|you're}} here.",
|
||||
"notification-welcome-link": "",
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
"notification-header-user-rights-add-only": "Notifications header message when a user is added to groups. Parameters:\n* $1 - the raw username of the person who made the user rights change, can be used for GENDER support\n* $2 - a localized list of the groups that were added\n* $3 - the number of groups that were added, can be used for PLURAL\n* $4 - name of the user viewing the notification, can be used for GENDER",
|
||||
"notification-header-user-rights-remove-only": "Notifications header message when a user is removed from groups. Parameters:\n* $1 - the raw username of the person who made the user rights change, can be used for GENDER support\n* $2 - a localized list of the groups that were removed\n* $3 - the number of groups that were removed, can be used for PLURAL\n* $4 - name of the user viewing the notification, can be used for GENDER",
|
||||
"notification-header-user-rights-add-and-remove": "Notifications header message when a user is added to groups and removed from groups. Parameters:\n* $1 - the raw username of the person who made the user rights change, can be used for GENDER support\n* $2 - a localized list of the groups that were added\n* $4 - a localized list of the groups that were removed\n* $6 - name of the user viewing the notification, can be used for GENDER",
|
||||
"notification-header-user-rights-expiry-change": "Notifications header message when a user's group membership is extended or reduced in duration. Parameters:\n* $1 - the raw username of the person who made the user rights change, can be used for GENDER support\n* $2 - a localized list of the groups for which the expiry was changed\n* $3 - the number of groups that were changed, can be used for PLURAL\n* $4 - name of the user viewing the notification, can be used for GENDER",
|
||||
"notification-body-user-rights": "{{notranslate}}",
|
||||
"notification-header-welcome": "Text of the welcome notification. Parameters:\n* $1 - the name of the new user.\nSee also:\n* {{msg-mw|Guidedtour-tour-gettingstarted-start-title}}",
|
||||
"notification-welcome-link": "{{notranslate}}",
|
||||
|
|
|
@ -19,7 +19,18 @@ class EchoUserRightsPresentationModel extends EchoEventPresentationModel {
|
|||
[ $this->language, 'embedBidi' ],
|
||||
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'remove', [] ) ) )
|
||||
);
|
||||
if ( $add && !$remove ) {
|
||||
$expiryChanged = array_map(
|
||||
[ $this->language, 'embedBidi' ],
|
||||
$this->getLocalizedGroupNames( array_values( $this->event->getExtraParam( 'expiry-changed', [] ) ) )
|
||||
);
|
||||
if ( $expiryChanged ) {
|
||||
$msg = $this->msg( 'notification-header-user-rights-expiry-change' );
|
||||
$msg->params( $genderName );
|
||||
$msg->params( $this->language->commaList( $expiryChanged ) );
|
||||
$msg->params( count( $expiryChanged ) );
|
||||
$msg->params( $this->getViewingUserForGender() );
|
||||
return $msg;
|
||||
} elseif ( $add && !$remove ) {
|
||||
$msg = $this->msg( 'notification-header-user-rights-add-only' );
|
||||
$msg->params( $genderName );
|
||||
$msg->params( $this->language->commaList( $add ) );
|
||||
|
|
Loading…
Reference in a new issue