mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
(bug 49142) Notifications Productivity A/B Test
Change-Id: I209a55bc78fc307603710296b75ebe774ebdcbac
This commit is contained in:
parent
e4640e4d0a
commit
7c19d0243f
9
Echo.php
9
Echo.php
|
@ -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(
|
||||
|
|
87
Hooks.php
87
Hooks.php
|
@ -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,19 +658,25 @@ 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;
|
||||
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;
|
||||
}
|
||||
// Don't abort watchlist email notifications
|
||||
return true;
|
||||
|
||||
// Echo talk page email notification
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue