Merge "More prefs functionality for Echo"

This commit is contained in:
Bsitu 2012-12-14 01:48:29 +00:00 committed by Gerrit Code Review
commit cc49fcfe61
5 changed files with 154 additions and 50 deletions

View file

@ -14,9 +14,15 @@ $messages['en'] = array(
// Preferences
'prefs-echo' => 'Notifications',
'prefs-displaynotifications' => 'Display options',
'prefs-subscriptions' => 'Subscriptions',
'echo-pref-notify-link' => 'Show a link to your notifications at the top of every page',
'echo-pref-notify-watchlist' => 'Subscribe me to edit notifications when I add pages to my watchlist',
'prefs-emailsubscriptions' => 'Notify me by e-mail when someone',
'prefs-emailfrequency' => 'How often I receive notifications by e-mail',
'echo-pref-email-edit-user-talk' => 'Posts on my talk page',
'echo-pref-email-reverted' => 'Reverts my edit',
'echo-pref-email-frequency-never' => 'Do not send me any e-mail notifications',
'echo-pref-email-frequency-immediately' => 'Individual notifications as they come in',
'echo-pref-email-frequency-daily' => 'A daily summary of notifications',
'echo-pref-email-frequency-weekly' => 'A weekly summary of notifications',
'echo-pref-notify-hide-link' => 'Hide the link and badge for notifications in my toolbar',
// Errors
'echo-no-agent' => '[Nobody]',
@ -148,10 +154,15 @@ $messages['qqq'] = array(
'echo-desc' => '{{desc}}',
'prefs-echo' => 'Name of preferences section for Echo notifications.',
'prefs-displaynotifications' => 'Header for the section of preferences that deals with how notifications are displayed',
'prefs-subscriptions' => 'Header for the section of preferences that deals with notification subscriptions',
'echo-pref-notify-link' => "Label for a preference which enables a 'Notifications' link in the header and associated fly-out panel",
'echo-pref-notify-watchlist' => 'Label for a preference which causes
any changes to your watchlist to be replicated in Echo subscriptions',
'prefs-emailsubscriptions' => 'Header for the section of preferences that deals with which notifications the user receives emails for',
'prefs-emailfrequency' => 'Header for the section of preferences that deals with how often notification emails are sent out',
'echo-pref-email-edit-user-talk' => "Option for getting emails when someone posts on the user's talk page. This is the conclusion of the sentence begun by the header: {{msg-mw|prefs-emailsubscriptions}}.",
'echo-pref-email-reverted' => "Option for getting emails when someone reverts the user's edit. This is the conclusion of the sentence begun by the header: {{msg-mw|prefs-emailsubscriptions}}.",
'echo-pref-email-frequency-never' => "Option for users who don't want to receive any email notifications",
'echo-pref-email-frequency-immediately' => 'Option for users who want to receive email for each notification as it occurs',
'echo-pref-email-frequency-daily' => 'Option for users who want to receive a daily digest of email notifications',
'echo-pref-email-frequency-weekly' => 'Option for users who want to receive a weekly digest of email notifications',
'echo-pref-notify-hide-link' => "Label for a preference which disables the 'Notifications' link in the header and associated fly-out panel",
'echo-no-agent' => 'Shown in place of a username in a notification
if the notification has no specified user.',
'echo-no-title' => 'Shown in place of a page title in a notification

View file

@ -167,6 +167,9 @@ $wgEchoEnableEmailBatch = true;
// Otherwise, only show a badge next to the username.
$wgEchoShowFullNotificationsLink = true;
// By default, send emails for each notification as they come in
$wgDefaultUserOptions['echo-email-frequency'] = EchoHooks::EMAIL_IMMEDIATELY;
// The organization address, the value should be defined in LocalSettings.php
$wgEchoEmailFooterAddress = '';
@ -184,8 +187,11 @@ $wgEchoDefaultNotificationTypes = array( // Welcome events do not use subscripti
)
);
// Definitions of the different types of notification delivery that are possible.
// Each definition consists of a class name and a function name.
// See also: EchoNotificationController class.
$wgEchoNotifiers = array(
'notify' => array( 'EchoNotifier', 'notifyWithNotification' ),
'notify' => array( 'EchoNotifier', 'notifyWithNotification' ), // web-based notification
'email' => array( 'EchoNotifier', 'notifyWithEmail' ),
);
@ -193,11 +199,12 @@ $wgEchoNotifiers = array(
// The list here only includes event types handled by Echo itself. Other
// extensions can add to this list through the BeforeCreateEchoEvent hook.
$wgEchoEnabledEvents = array(
'edit-user-talk',
//'add-comment',
//'add-talkpage-topic',
'welcome',
'reverted',
'welcome', // A user created an account
'edit-user-talk', // User talk page is edited
'reverted', // An edit is undone or rolled-back
// These aren't ready yet, specifically they have no means of subscription
# 'add-comment', // A signed comment is added to an existing section
# 'add-talkpage-topic', // A new section is added to a talk page
);
// This array stores the category and priority for enabled events
@ -215,7 +222,12 @@ $wgEchoEventDetails = array(
),
);
// Definitions of the notifications built into Echo
// Set all of the events to email by default (won't affect events that don't email)
foreach ( $wgEchoEnabledEvents as $wgEchoEnabledEvent ) {
$wgDefaultUserOptions['echo-email-notifications' . $wgEchoEnabledEvent] = true;
}
// Definitions of the notification event types built into Echo
$wgEchoNotificationFormatters = array(
'edit-user-talk' => array(
'type' => 'edit',

101
Hooks.php
View file

@ -1,6 +1,10 @@
<?php
class EchoHooks {
const EMAIL_NEVER = -1; // Never send email notifications
const EMAIL_IMMEDIATELY = 0; // Send email notificaitons immediately as they come in
const EMAIL_DAILY_DIGEST = 1; // Send daily email digests
const EMAIL_WEEKLY_DIGEST = 7; // Send weekly email digests
/**
* @param $updater DatabaseUpdater object
@ -112,10 +116,79 @@ class EchoHooks {
* @return bool true in all cases
*/
public static function getPreferences( $user, &$preferences ) {
global $wgEchoEnabledEvents;
$preferences['echo-notify-link'] = array(
global $wgEchoDefaultNotificationTypes, $wgAuth;
// Show email frequency options
$never = wfMessage( 'echo-pref-email-frequency-never' )->plain();
$immediately = wfMessage( 'echo-pref-email-frequency-immediately' )->plain();
$daily = wfMessage( 'echo-pref-email-frequency-daily' )->plain();
$weekly = wfMessage( 'echo-pref-email-frequency-weekly' )->plain();
$preferences['echo-email-frequency'] = array(
'type' => 'select',
//'label-message' => 'echo-pref-email-frequency',
'section' => 'echo/emailfrequency',
'options' => array(
$never => self::EMAIL_NEVER,
$immediately => self::EMAIL_IMMEDIATELY,
$daily => self::EMAIL_DAILY_DIGEST,
$weekly => self::EMAIL_WEEKLY_DIGEST,
)
);
// Show email subscription options
$emailOptions = array();
foreach ( EchoEvent::gatherValidEchoEvents() as $enabledEvent ) {
// Welcome notifications don't have subscriptions
if ( $enabledEvent === 'welcome' ) {
continue;
}
// Make sure email notifications are possible for this event
if ( isset( $wgEchoDefaultNotificationTypes[$enabledEvent] ) ) {
if ( !$wgEchoDefaultNotificationTypes[$enabledEvent]['email'] ) {
continue;
}
} elseif ( !$wgEchoDefaultNotificationTypes['all']['email'] ) {
continue;
}
$eventMessage = wfMessage( 'echo-pref-email-' . $enabledEvent )->plain();
$emailOptions["$eventMessage"] = $enabledEvent;
}
$preferences['echo-email-notifications'] = array(
'type' => 'multiselect',
'section' => 'echo/emailsubscriptions',
'options' => $emailOptions,
);
// Display information about the user's currently set email address
$prefsTitle = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' );
$link = Linker::link(
SpecialPage::getTitleFor( 'ChangeEmail' ),
wfMessage( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(),
array(),
array( 'returnto' => $prefsTitle->getFullText() )
);
$emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : '';
if ( $wgAuth->allowPropChange( 'emailaddress' ) ) {
if ( $emailAddress === '' ) {
$emailAddress .= $link;
} else {
$emailAddress .= wfMessage( 'word-separator' )->escaped()
. wfMessage( 'parentheses' )->rawParams( $link )->escaped();
}
}
$emailContent = wfMessage( 'youremail' )->escaped()
. wfMessage( 'word-separator' )->escaped() . $emailAddress;
$preferences['echo-emailaddress'] = array(
'type' => 'info',
'raw' => true,
'default' => $emailContent,
'section' => 'echo/emailsubscriptions'
);
// Show fly-out display prefs
$preferences['echo-notify-hide-link'] = array(
'type' => 'toggle',
'label-message' => 'echo-pref-notify-link',
'label-message' => 'echo-pref-notify-hide-link',
'section' => 'echo/displaynotifications',
);
return true;
@ -204,7 +277,7 @@ class EchoHooks {
*/
static function beforePageDisplay( $out, $skin ) {
$user = $out->getUser();
if ( $user->isLoggedIn() && $user->getOption( 'echo-notify-link' ) ) {
if ( $user->isLoggedIn() && !$user->getOption( 'echo-notify-hide-link' ) ) {
// Load the module for the Notifications flyout
$out->addModules( array( 'ext.echo.overlay' ) );
}
@ -221,7 +294,8 @@ class EchoHooks {
*/
static function onPersonalUrls( &$personal_urls, &$title ) {
global $wgUser, $wgEchoShowFullNotificationsLink;
if ( $wgUser->isAnon() || !$wgUser->getOption( 'echo-notify-link' ) ) {
// Add a "My notifications" item to personal URLs
if ( $wgUser->isAnon() || $wgUser->getOption( 'echo-notify-hide-link' ) ) {
return true;
}
@ -253,8 +327,13 @@ class EchoHooks {
* @return bool true in all cases
*/
static function abortEmailNotification() {
global $wgEchoDisableStandardEmail;
return !$wgEchoDisableStandardEmail;
global $wgEchoEnabledEvents, $wgEnotifUserTalk;
if ( in_array( 'edit-user-talk', $wgEchoEnabledEvents ) ) {
// Disable the standard email notification for talk page messages
$wgEnotifUserTalk = false;
}
// Don't abort watchlist email notifications
return true;
}
/**
@ -297,14 +376,14 @@ class EchoHooks {
/**
* Handler for ArticleEditUpdateNewTalk hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleEditUpdateNewTalk
* @param $article The article object of the talk page being updated
* @param $page The WikiPage object of the talk page being updated
* @return bool
*/
static function abortNewTalkNotification( $article ) {
global $wgEchoEnabledEvents, $wgUser;
static function abortNewTalkNotification( $page ) {
global $wgUser, $wgEchoEnabledEvents;
// If the user has the notifications flyout turned on and is receiving
// notifications for talk page messages, disable the yellow-bar-style notice.
if ( $wgUser->getOption( 'echo-notify-link' )
if ( !$wgUser->getOption( 'echo-notify-hide-link' )
&& in_array( 'edit-user-talk', $wgEchoEnabledEvents ) )
{
return false;

View file

@ -25,32 +25,34 @@ class EchoNotifier {
// No valid email address
return false;
}
global $wgEchoEnableEmailBatch, $wgEchoEventDetails, $wgPasswordSender, $wgPasswordSenderName;
// batched email notification
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
// default priority is 10
$priority = 10;
if ( isset( $wgEchoEventDetails[$event->getType()]['priority'] ) ) {
$priority = $wgEchoEventDetails[$event->getType()]['priority'];
// See if the user wants to receive emails for this type of event
if ( $user->getOption( 'echo-email-notifications' . $event->getType() ) ) {
global $wgEchoEnableEmailBatch, $wgEchoEventDetails, $wgPasswordSender, $wgPasswordSenderName;
// batched email notification
if ( $wgEchoEnableEmailBatch && $user->getOption( 'echo-email-frequency' ) > 0 ) {
// default priority is 10
$priority = 10;
if ( isset( $wgEchoEventDetails[$event->getType()]['priority'] ) ) {
$priority = $wgEchoEventDetails[$event->getType()]['priority'];
}
MWEchoEmailBatch::addToQueue( $user->getId(), $event->getId(), $priority );
return true;
}
MWEchoEmailBatch::addToQueue( $user->getId(), $event->getId(), $priority );
return true;
// no email notification
if ( $user->getOption( 'echo-email-frequency' ) < 0 ) {
return false;
}
// instant email notification
$adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
$address = new MailAddress( $user );
$email = EchoNotificationController::formatNotification( $event, $user, 'email' );
$subject = $email['subject'];
$body = $email['body'];
UserMailer::send( $address, $adminAddress, $subject, $body );
}
// no email notification
if ( $user->getOption( 'echo-email-frequency' ) < 0 ) {
return false;
}
// instant email notification
$adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
$address = new MailAddress( $user );
$email = EchoNotificationController::formatNotification( $event, $user, 'email' );
$subject = $email['subject'];
$body = $email['body'];
UserMailer::send( $address, $adminAddress, $subject, $body );
return true;
}

View file

@ -161,7 +161,7 @@ class EchoNotificationController {
*
* @param $event EchoEvent to do a notification for.
* @param $user User object to notify.
* @param $type string The type of notification to process.
* @param $type string The type of notification delivery to process, e.g. 'email'.
* @throws MWException
*/
public static function doNotification( $event, $user, $type ) {