TTO has uploaded a new change for review. (
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.
Change-Id: I27d52bc5c39219c832bf63a491faa1e421b0c024
Depends-On: I5d32445f8e5b41599889b8488a2431e7a908f858
Bug: T159301
---
M Hooks.php
M i18n/en.json
M includes/formatters/UserRightsPresentationModel.php
3 files changed, 46 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/44/347144/1
diff --git a/Hooks.php b/Hooks.php
index 8891532..33284b1 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -679,7 +679,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;
@@ -695,13 +697,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[$add] ) ) {
+ $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 cf1f3ee..d95ef17 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/includes/formatters/UserRightsPresentationModel.php
b/includes/formatters/UserRightsPresentationModel.php
index 2499627..c706d3f 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( $expiryChange
) );
+ $msg->params( count( $expiryChange ) );
+ $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: newchange
Gerrit-Change-Id: I27d52bc5c39219c832bf63a491faa1e421b0c024
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: TTO <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits