(bug 49142) Notifications Productivity A/B Test

Change-Id: I209a55bc78fc307603710296b75ebe774ebdcbac
This commit is contained in:
bsitu 2013-06-07 18:05:35 -07:00
parent e4640e4d0a
commit 7c19d0243f
3 changed files with 87 additions and 14 deletions

View file

@ -218,8 +218,7 @@ $wgHooks['ArticleRollbackComplete'][] = 'EchoHooks::onRollbackComplete';
$wgHooks['UserSaveSettings'][] = 'EchoHooks::onUserSaveSettings';
// Disable ordinary user talk page email notifications
$wgHooks['AbortEmailNotification'][] = 'EchoHooks::disableStandUserTalkEnotif';
$wgHooks['UpdateUserMailerFormattedPageStatus'][] = 'EchoHooks::disableStandUserTalkEnotif';
$wgHooks['AbortTalkPageEmailNotification'][] = 'EchoHooks::onAbortTalkPageEmailNotification';
// Disable the yellow bar of death
$wgHooks['GetNewMessagesAlert'][] = 'EchoHooks::abortNewMessagesAlert';
$wgHooks['LinksUpdateAfterInsert'][] = 'EchoHooks::onLinksUpdateAfterInsert';
@ -277,6 +276,12 @@ $wgEchoBundleEmailInterval = 0;
// Whether or not to enable a new talk page message alert for logged in users
$wgEchoNewMsgAlert = true;
// Cohort study period. This array should consist of 3 TS_MW format timestamps
// in ascending order, the 1st one is when the bucketing and study start, the 2nd
// one is when the bucketing ends, the 3rd one is when the study ends. Set this
// to empty array to disable Cohort study, this should be defined in LocalSettings.php
$wgEchoCohortInterval = array();
// Define which output formats are available for each notification category
$wgEchoDefaultNotificationTypes = array(
'all' => array(

View file

@ -234,6 +234,11 @@ class EchoHooks {
$wgEchoNotifiers, $wgEchoNotificationCategories, $wgEchoNotifications,
$wgEchoHelpPage, $wgEchoNewMsgAlert;
// Don't show echo preference page if echo is disabled for this user
if ( self::isEchoDisabled( $user ) ) {
return true;
}
// Show email frequency options
$never = wfMessage( 'echo-pref-email-frequency-never' )->plain();
$immediately = wfMessage( 'echo-pref-email-frequency-immediately' )->plain();
@ -596,6 +601,12 @@ class EchoHooks {
static function beforePageDisplay( $out, $skin ) {
global $wgEchoNewMsgAlert;
$user = $out->getUser();
// Don't show the alert message and badge if echo is disabled for this user
if ( self::isEchoDisabled( $user ) ) {
return true;
}
if ( $user->isLoggedIn() && $user->getOption( 'echo-notify-show-link' ) ) {
global $wgEchoFeedbackPage;
// Load the module for the Notifications flyout
@ -622,7 +633,7 @@ class EchoHooks {
static function onPersonalUrls( &$personal_urls, &$title ) {
global $wgUser;
// Add a "My notifications" item to personal URLs
if ( $wgUser->isAnon() || !$wgUser->getOption( 'echo-notify-show-link' ) ) {
if ( $wgUser->isAnon() || self::isEchoDisabled( $wgUser ) || !$wgUser->getOption( 'echo-notify-show-link' ) ) {
return true;
}
@ -647,21 +658,27 @@ class EchoHooks {
}
/**
* Handler for AbortEmailNotification and UpdateUserMailerFormattedPageStatus hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AbortEmailNotification
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UpdateUserMailerFormattedPageStatus
* @return bool true in all cases
* Handler for AbortTalkPageEmailNotification hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AbortTalkPageEmailNotification
* @param $targetUser User
* @param $title Title
* @return bool
*/
static function disableStandUserTalkEnotif() {
global $wgEchoNotifications, $wgEnotifUserTalk;
if ( isset( $wgEchoNotifications['edit-user-talk'] ) ) {
// Disable the standard email notification for talk page messages
$wgEnotifUserTalk = false;
}
// Don't abort watchlist email notifications
static function onAbortTalkPageEmailNotification( $targetUser, $title ) {
global $wgEchoNotifications;
// Send legacy talk page email notification if
// 1. echo is disabled for them or
// 2. echo talk page notification is disabled
if ( self::isEchoDisabled( $targetUser ) || !isset( $wgEchoNotifications['edit-user-talk'] ) ) {
// Legacy talk page email notification
return true;
}
// Echo talk page email notification
return false;
}
/**
* Handler for MakeGlobalVariablesScript hook.
* @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
@ -716,12 +733,17 @@ class EchoHooks {
*/
static function abortNewMessagesAlert( &$newMessagesAlert, $newtalks, $user, $out ) {
global $wgEchoNotifications;
// If the user has the notifications flyout turned on and is receiving
// notifications for talk page messages, disable the new messages alert.
if ( $user->isLoggedIn()
&& $user->getOption( 'echo-notify-show-link' )
&& isset( $wgEchoNotifications['edit-user-talk'] )
) {
// Show the new messages alert for users with echo disabled
if ( self::isEchoDisabled( $user ) ) {
return true;
}
// hide new messages alert
return false;
} else {
@ -866,4 +888,45 @@ class EchoHooks {
return true;
}
/**
* Echo should be disabled for users who are under cohort study
* @param $user User
* @return bool
*/
public static function isEchoDisabled( User $user ) {
global $wgEchoCohortInterval;
// Make sure the user has an id and cohort study timestamp is specified
if ( !$wgEchoCohortInterval || !$user->getId() ) {
return false;
}
list( $start, $bucketEnd, $cohortEnd ) = $wgEchoCohortInterval;
$regTimestamp = $user->getRegistration();
// Cohort study is for user with a registration timestamp
if ( !$regTimestamp ) {
return false;
}
// Cohort study is for even user_id
if ( $user->getId() % 2 === 1 ) {
return false;
}
$now = wfTimestampNow();
// Make sure the user is registered during the bucketing period
// and the cohort study doesn't end yet
if ( $start <= $regTimestamp && $regTimestamp <= $bucketEnd
&& $start <= $now && $now <= $cohortEnd
) {
return true;
}
return false;
}
}

View file

@ -261,6 +261,11 @@ class EchoNotificationController {
throw new MWException( "Invalid notification type $type" );
}
// Don't send any notification if Echo is disabled
if ( EchoHooks::isEchoDisabled( $user ) ) {
return;
}
call_user_func_array( $wgEchoNotifiers[$type], array( $user, $event ) );
}