From 5714adf8f4b3c2a6e163b665325a931287b45d92 Mon Sep 17 00:00:00 2001 From: Krenair Date: Sat, 1 Sep 2012 00:35:16 +0100 Subject: [PATCH] Add welcome notification for new users. Change-Id: I14032b71ebe63bb6ef951ba0c14d6acf44e69d6b --- Echo.i18n.php | 5 +++++ Echo.php | 12 +++++++++++- Hooks.php | 18 ++++++++++++++++++ controller/NotificationController.php | 20 ++++++++++++-------- formatters/NotificationFormatter.php | 1 + 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Echo.i18n.php b/Echo.i18n.php index 42d5beb21..42d22869f 100644 --- a/Echo.i18n.php +++ b/Echo.i18n.php @@ -33,6 +33,9 @@ $messages['en'] = array( 'notification-add-talkpage-topic-yours' => '$2 {{GENDER:$1|sent}} you a message: "[[$4#$3|$3]]"', 'notification-add-comment-yours' => '$2 {{GENDER:$1|commented}} on "[[$4#$3|$3]]" on your talk page', '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' => 'Hi $1, and welcome to {{SITENAME}}.
+Please remember to sign any comments on talk pages with 4 tildes (~~~~).', 'notification-edit-email-subject' => '{{SITENAME}} notification: $3 has been edited by $2', 'notification-edit-email-body' => 'Hello $5, @@ -121,6 +124,8 @@ $messages['qqq'] = array( * $2 Linked Username; * $3 Discussion name; * $4 link to user talk page.', + 'notification-new-user' => 'Title for the welcome notification. $1 is the name of the new user.', + 'notification-new-user-content' => 'The content shown to users on their welcome notification. $1 is the name of the new user.', 'notification-edit-email-subject' => 'E-mail subject. Parameters: * $2 is a username * $3 is a page title', diff --git a/Echo.php b/Echo.php index 673dbbcab..d954f32f7 100644 --- a/Echo.php +++ b/Echo.php @@ -139,6 +139,7 @@ $wgHooks['EchoGetNotificationTypes'] = array( 'EchoHooks::getNotificationTypes' $wgHooks['WatchArticleComplete'][] = 'EchoHooks::onWatch'; $wgHooks['UnwatchArticleComplete'][] = 'EchoHooks::onUnwatch'; $wgHooks['ArticleSaveComplete'][] = 'EchoHooks::onArticleSaved'; +$wgHooks['AddNewAccount'][] = 'EchoHooks::onAccountCreated'; // Disable ordinary email notifications $wgHooks['AbortEmailNotification'][] = 'EchoHooks::abortEmailNotification'; @@ -149,7 +150,7 @@ $wgHooks['ArticleEditUpdateNewTalk'][] = 'EchoHooks::abortNewtalkNotification'; $wgEchoDisableStandardEmail = true; -$wgEchoDefaultNotificationTypes = array( +$wgEchoDefaultNotificationTypes = array( // Welcome events do not use subscription, and will only trigger notify, not email. 'all' => array( 'notify' => true, 'email' => true, @@ -165,6 +166,7 @@ $wgEchoEnabledEvents = array( 'edit-user-talk', 'add-comment', 'add-talkpage-topic', + 'welcome', ); $wgEchoNotificationFormatters = array( @@ -202,4 +204,12 @@ $wgEchoNotificationFormatters = array( 'content-params' => array( 'commentText' ), 'icon' => 'chat', ), + 'welcome' => array( + 'type' => 'welcome', + 'title-message' => 'notification-new-user', + 'title-params' => array( 'agent' ), + 'content-message' => 'notification-new-user-content', + 'content-params' => array( 'agent' ), + 'icon' => 'w', + ) ); diff --git a/Hooks.php b/Hooks.php index a78285e3b..ebfe4ce8e 100644 --- a/Hooks.php +++ b/Hooks.php @@ -59,6 +59,9 @@ class EchoHooks { EchoDiscussionParser::getNotifiedUsersForComment( $revision ) ); break; + case 'welcome': + $users[$event->getAgent()->getId()] = $event->getAgent(); + break; } return true; @@ -190,6 +193,21 @@ class EchoHooks { return true; } + /** + * Handler for AddNewAccount hook. + * @see http://www.mediawiki.org/wiki/Manual:Hooks/AddNewAccount + * @param $user User object that was created. + * @param $byEmail bool True when account was created "by email". + */ + public static function onAccountCreated( $user, $byEmail ) { + $event = EchoEvent::create( array( + 'type' => 'welcome', + 'agent' => $user, + ) ); + + return true; + } + /** * Handler for BeforePageDisplay hook. * @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay diff --git a/controller/NotificationController.php b/controller/NotificationController.php index 67b615336..a44c02a2c 100644 --- a/controller/NotificationController.php +++ b/controller/NotificationController.php @@ -79,18 +79,22 @@ class EchoNotificationController { return; } - $subscriptions = self::getSubscriptionsForEvent( $event ); + if ( $event->getType() == 'welcome' ) { // Welcome events should only be sent to the new user, no need for subscriptions. + self::doNotification( $event, $event->getAgent(), 'notify' ); + } else { + $subscriptions = self::getSubscriptionsForEvent( $event ); - foreach ( $subscriptions as $subscription ) { - $user = $subscription->getUser(); - $notifyTypes = $subscription->getNotificationTypes(); + foreach ( $subscriptions as $subscription ) { + $user = $subscription->getUser(); + $notifyTypes = $subscription->getNotificationTypes(); - $notifyTypes = array_keys( array_filter( $notifyTypes ) ); + $notifyTypes = array_keys( array_filter( $notifyTypes ) ); - wfRunHooks( 'EchoGetNotificationTypes', array( $subscription, $event, &$notifyTypes ) ); + wfRunHooks( 'EchoGetNotificationTypes', array( $subscription, $event, &$notifyTypes ) ); - foreach ( $notifyTypes as $type ) { - self::doNotification( $event, $user, $type ); + foreach ( $notifyTypes as $type ) { + self::doNotification( $event, $user, $type ); + } } } } diff --git a/formatters/NotificationFormatter.php b/formatters/NotificationFormatter.php index a0e75476b..d66a62a94 100644 --- a/formatters/NotificationFormatter.php +++ b/formatters/NotificationFormatter.php @@ -5,6 +5,7 @@ abstract class EchoNotificationFormatter { 'basic' => 'EchoBasicFormatter', 'edit' => 'EchoEditFormatter', 'comment' => 'EchoCommentFormatter', + 'welcome' => 'EchoBasicFormatter', ); protected $validOutputFormats = array( 'text', 'html', 'email' ); protected $outputFormat = 'text';