Merge "Initial version of user-right notification"

This commit is contained in:
Kaldari 2013-03-21 17:49:24 +00:00 committed by Gerrit Code Review
commit 556ad065f2
4 changed files with 127 additions and 2 deletions

View file

@ -63,6 +63,10 @@ $messages['en'] = array(
'notification-add-comment-yours2' => '[[User:$1|$1]] {{GENDER:$1|commented}} on "[[$3#$2|$2]]" on your talk page',
'notification-mention' => '[[User:$1|$1]] {{GENDER:$1|mentioned}} you on [[$3#$2|$3]].',
'notification-mention-flyout' => '$1 {{GENDER:$1|mentioned}} you on [[$3#$2|$3]].',
'notification-user-rights' => 'Your user rights were {{GENDER:$1|changed}} by [[User:$1|$1]]. $2. [[Special:ListGroupRights|Learn more]]',
'notification-user-rights-flyout' => 'Your user rights were {{GENDER:$1|changed}} by $1. $2. [[Special:ListGroupRights|Learn more]]',
'notification-user-rights-add' => 'You are now a member of {{PLURAL:$2|this group|these groups}}: $1',
'notification-user-rights-remove' => 'You are no longer a member of {{PLURAL:$2|this group|these groups}}: $1',
'notification-talkpage-content' => '$1', ## Do not translate unless you deliberately want to change behaviour
'notification-new-user' => 'Welcome to {{SITENAME}}, $1!',
'notification-new-user-content' => 'Please remember to sign any comments on talk pages with 4 tildes (~~~~).',
@ -110,6 +114,15 @@ $4
$5',
'notification-mention-email-batch-body' => '$1 {{GENDER:$1|mentioned}} you on $2',
'notification-user-rights-email-subject' => 'Your user rights have changed on {{SITENAME}}',
'notification-user-rights-email-body' => 'Your user rights were {{GENDER:$1|changed}} by $1. $2
View more:
{{canonicalurl:{{#special:ListGroupRights}}}}
$3',
'notification-user-rights-email-batch-body' => 'Your user rights were {{GENDER:$1|changed}} by $1. $2',
'echo-notification-count' => '$1+',
// Email notification
'echo-email-subject-default' => 'New notification at {{SITENAME}}',
@ -338,11 +351,22 @@ See also:
* $2 - the section title of the discussion
* $3 - the page title of the discussion",
'notification-mention-flyout' => "Flyout-specific format for displaying notifications of a comment including a link to another user's user page.
Parameters:
* $1 - the username of the person who mentioned you, plain text. Can be used for GENDER.
* $2 - the section title of the discussion
* $3 - the page title of the discussion",
'notification-user-rights' => 'Format for displaying notifications of a user right change in notification page. Parameters:
* $1 is the username of the person who made the user right change. Can be used for GENDER support
* $2 is a semicolon separated list of {{msg-mw}|notification-user-rights-add}, {{msg-mw|notification-user-rights-remove}}',
'notification-user-rights-flyout' => 'Format for displaying notifications of a user right change in notification flyout. Parameters:
* $1 is the username of the person who made the user right change. Can be used for GENDER support
* $2 is a semicolon separated list of {{msg-mw}|notification-user-rights-add}, {{msg-mw|notification-user-rights-remove}}',
'notification-user-rights-add' => 'Message indicating that a user was added to a user group. Parameters:
* $1 is a comma separated list of user group names
* $2 is the number of user groups, this is used for PLURAL support',
'notification-user-rights-remove' => 'Message indicating that a user was removed from a user group. Parameters:
* $1 is a comma separated list of user group names
* $2 is the number of user groups, this is used for PLURAL support',
'notification-talkpage-content' => 'Message shown as the "content" of a talkpage-related action.
* $1 is the content of the talk page post.
@ -431,6 +455,14 @@ See also:
'notification-mention-email-batch-body' => 'E-mail notification batch body. Parameters:
* $1 is a username, plaintext. Can be used for gender support
* $2 is talk page title',
'notification-user-rights-email-subject' => 'E-mail subject for user rights notification',
'notification-user-rights-email-body' => 'E-mail notification. Parameters:
* $1 is a user name, plaintext. Can be used for gender support
* $2 is a semicolon separated list of {{msg-mw}|notification-user-rights-add}, {{msg-mw|notification-user-rights-remove}}
* $3 is the email footer',
'notification-user-rights-email-batch-body' => 'Email notification batch body. Parameters:
* $1 is a user name, plaintext. Can be used for gender support
* $2 is a semicolon separated list of {{msg-mw}|notification-user-rights-add}, {{msg-mw|notification-user-rights-remove}}',
'echo-notification-count' => '{{optional}}
The new notification count next to notification link, for example: 99+
* $1 is the count',

View file

@ -57,6 +57,7 @@ $wgAutoloadClasses['EchoBasicFormatter'] = $dir . 'formatters/BasicFormatter.php
$wgAutoloadClasses['EchoEditFormatter'] = $dir . 'formatters/EditFormatter.php';
$wgAutoloadClasses['EchoCommentFormatter'] = $dir . 'formatters/CommentFormatter.php';
$wgAutoloadClasses['EchoArticleLinkedFormatter'] = $dir . 'formatters/ArticleLinkedFormatter.php';
$wgAutoloadClasses['EchoUserRightsFormatter'] = $dir . 'formatters/UserRightsFormatter.php';
// Internal stuff
$wgAutoloadClasses['EchoNotifier'] = $dir . 'Notifier.php';
@ -88,6 +89,7 @@ $wgHooks['BeforePageDisplay'][] = 'EchoHooks::beforePageDisplay';
$wgHooks['MakeGlobalVariablesScript'][] = 'EchoHooks::makeGlobalVariablesScript';
$wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
$wgHooks['ResourceLoaderRegisterModules'][] = 'EchoHooks::onResourceLoaderRegisterModules';
$wgHooks['UserRights'][] = 'EchoHooks::onUserRights';
// Extension initialization
$wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
@ -342,7 +344,24 @@ $wgEchoNotifications = array(
'content-message' => 'notification-talkpage-content',
'content-params' => array( 'commentText' ),
'icon' => 'chat',
)
),
'user-rights' => array(
'category' => 'system',
'group' => 'interactive',
'formatter-class' => 'EchoUserRightsFormatter',
'title-message' => 'notification-user-rights',
'title-params' => array( 'agent', 'user-rights-list' ),
'payload' => array(),
'flyout-message' => 'notification-user-rights-flyout',
'flyout-params' => array( 'agent', 'user-rights-list' ),
'email-subject-message' => 'notification-user-rights-email-subject',
'email-subject-params' => array(),
'email-body-message' => 'notification-user-rights-email-body',
'email-body-params' => array( 'agent', 'user-rights-list', 'email-footer' ),
'email-body-batch-message' => 'notification-user-rights-email-batch-body',
'email-body-batch-params' => array( 'agent', 'user-rights-list' ),
'icon' => 'w',
),
);
// Enable notifications for all logged in users by default

View file

@ -200,6 +200,10 @@ class EchoHooks {
}
}
break;
case 'user-rights':
$extraData = $event->getExtra();
$users[$extraData['user']] = User::newFromId( $extraData['user'] );
break;
}
return true;
@ -445,6 +449,33 @@ class EchoHooks {
return true;
}
/**
* Handler for UserRights hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UserRights
* @param $user User User object that was changed
* @param $add array Array of strings corresponding to groups added
* @param $remove array Array of strings corresponding to groups removed
*/
public static function onUserRights( &$user, $add, $remove ) {
global $wgUser;
if ( !$user->isAnon() && $wgUser->getId() != $user->getId() && ( $add || $remove ) ) {
EchoEvent::create(
array(
'type' => 'user-rights',
'title' => Title::newMainPage(),
'extra' => array(
'user' => $user->getID(),
'add' => $add,
'remove' => $remove
),
'agent' => $wgUser,
)
);
}
return true;
}
/**
* Handler for LinksUpdateAfterInsert hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateAfterInsert

View file

@ -0,0 +1,43 @@
<?php
/**
* Formatter for 'user-rights' notifications
*/
class EchoUserRightsFormatter extends EchoBasicFormatter {
/**
* @param $event EchoEvent
* @param $param string
* @param $message Message
* @param $user User
*/
protected function processParam( $event, $param, $message, $user ) {
$extra = $event->getExtra();
switch ( $param ) {
// List of user rights that are granted or revoked
case 'user-rights-list':
global $wgLang;
$list = array();
foreach ( array( 'add', 'remove' ) as $action ) {
if ( $extra[$action] ) {
// Messages that can be used here:
// * notification-user-rights-add
// * notification-user-rights-remove
$list[] = wfMessage( 'notification-user-rights-' . $action )
->params( $wgLang->commaList( $extra[$action] ), count( $extra[$action] ) )
->escaped();
}
}
$message->params( $wgLang->semicolonList( $list ) );
break;
default:
parent::processParam( $event, $param, $message, $user );
break;
}
}
}