Bsitu has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67570
Change subject: (bug 49141) Notifications Productivity A/B Test
......................................................................
(bug 49141) Notifications Productivity A/B Test
Change-Id: I209a55bc78fc307603710296b75ebe774ebdcbac
---
M Echo.php
M Hooks.php
M controller/NotificationController.php
3 files changed, 83 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/70/67570/1
diff --git a/Echo.php b/Echo.php
index 3b6c78a..75b57d6 100644
--- a/Echo.php
+++ b/Echo.php
@@ -277,6 +277,12 @@
// 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(
diff --git a/Hooks.php b/Hooks.php
index 1fec954..9156599 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -234,6 +234,11 @@
$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 @@
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
@@ -653,7 +664,21 @@
* @return bool true in all cases
*/
static function disableStandUserTalkEnotif() {
- global $wgEchoNotifications, $wgEnotifUserTalk;
+ global $wgEchoNotifications, $wgEnotifUserTalk, $wgOut;
+
+ $title = $wgOut->getContext()->getTitle();
+ if ( $title && $title->getNamespace() === NS_USER_TALK ) {
+ $targetUser = User::newFromName( $title->getText() );
+ if ( $targetUser ) {
+ // User should receive legacy talk page email
notification if echo
+ // is disabled for them, this is done by not
modifying global
+ // $wgEnotifUserTalk on the fly
+ if ( self::isEchoDisabled( $targetUser ) ) {
+ return true;
+ }
+ }
+ }
+
if ( isset( $wgEchoNotifications['edit-user-talk'] ) ) {
// Disable the standard email notification for talk
page messages
$wgEnotifUserTalk = false;
@@ -716,12 +741,17 @@
*/
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 +896,45 @@
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;
+ }
+
}
diff --git a/controller/NotificationController.php
b/controller/NotificationController.php
index 1809691..cfec362 100644
--- a/controller/NotificationController.php
+++ b/controller/NotificationController.php
@@ -261,6 +261,11 @@
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 ) );
}
--
To view, visit https://gerrit.wikimedia.org/r/67570
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I209a55bc78fc307603710296b75ebe774ebdcbac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits