jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/347144 )
Change subject: Add proper message when user group expiry is changed
......................................................................
Add proper message when user group expiry is changed
There's a lot more that could be done to improve user "rights"
notifications (really user group notifications), but this will do for now.
Bug: T159301
Depends-On: I5d32445f8e5b41599889b8488a2431e7a908f858
Change-Id: I27d52bc5c39219c832bf63a491faa1e421b0c024
---
M Hooks.php
M i18n/en.json
M i18n/qqq.json
M includes/formatters/UserRightsPresentationModel.php
4 files changed, 47 insertions(+), 4 deletions(-)
Approvals:
Catrope: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Hooks.php b/Hooks.php
index e12c43b..c256093 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -688,7 +688,9 @@
*
* @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 @@
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,
],
diff --git a/i18n/en.json b/i18n/en.json
index 23e99e5..28d626f 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -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": "",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index cae9ba9..f0afc55 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -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}}",
diff --git a/includes/formatters/UserRightsPresentationModel.php
b/includes/formatters/UserRightsPresentationModel.php
index 2499627..127d009 100644
--- a/includes/formatters/UserRightsPresentationModel.php
+++ b/includes/formatters/UserRightsPresentationModel.php
@@ -19,7 +19,18 @@
[ $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 ) );
--
To view, visit https://gerrit.wikimedia.org/r/347144
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I27d52bc5c39219c832bf63a491faa1e421b0c024
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: TTO <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits