From 1d47038e627b8ac6cef77e2e11d4f3be672ee7d2 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Wed, 1 Aug 2012 11:20:21 -0700 Subject: [PATCH] Echo: Make it possible to specify exactly which events are active with $wgEchoEnabledEvents Change-Id: Iecf77f1e0dd80a209ef9be013fb2adf44e69a604 --- Echo.i18n.php | 4 ++++ Echo.php | 6 ++++++ Hooks.php | 15 +++++++++++++++ controller/NotificationController.php | 3 ++- model/Event.php | 9 +++++++++ special/SpecialNotifications.php | 2 +- 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Echo.i18n.php b/Echo.i18n.php index fefc5224a..b6c845116 100644 --- a/Echo.i18n.php +++ b/Echo.i18n.php @@ -68,6 +68,8 @@ $1', 'echo-link' => 'My notifications', 'echo-overlay-link' => 'All notifications…', 'echo-overlay-title' => 'My notifications', + + 'echo-error-no-formatter' => 'Error: Unable to find notification formatter for event type "$1".', ); /** Message documentation (Message documentation) @@ -115,6 +117,8 @@ $4 is the page on which the discussion was added, plain text.', 'echo-link' => 'Shown in "personal links" when a user has JS. New notifications are indicated with a badge.', 'echo-overlay-link' => 'Link to "all notifications" at the bottom of the overlay', 'echo-overlay-title' => 'Title at the top of the notifications overlay', + 'echo-error-no-formatter' => 'Internal error condition shown when a notification cannot be formatted. +$1 is the type of notification (e.g. "add-talkpage-section").', ); /** Belarusian (Taraškievica orthography) (‪беларуская (тарашкевіца)‬) diff --git a/Echo.php b/Echo.php index ca2e77c93..d93e90588 100644 --- a/Echo.php +++ b/Echo.php @@ -159,6 +159,12 @@ $wgEchoNotifiers = array( 'email' => array('EchoNotifier', 'notifyWithEmail'), ); +$wgEchoEnabledEvents = array( + 'edit-user-talk', + 'add-comment', + 'add-talkpage-topic', +); + $wgEchoNotificationFormatters = array( 'edit-user-talk' => array( 'type' => 'edit', diff --git a/Hooks.php b/Hooks.php index faa5bc113..82e0741ce 100644 --- a/Hooks.php +++ b/Hooks.php @@ -98,6 +98,11 @@ class EchoHooks { * @return true in all cases */ public static function getPreferences( $user, &$preferences ) { + global $wgEchoEnabledEvents; + if ( $wgEchoEnabledEvents !== false && ! in_array( 'edit', $wgEchoEnabledEvents ) ) { + return true; + } + $preferences['echo-notify-watchlist'] = array( 'type' => 'toggle', 'label-message' => 'echo-pref-notify-watchlist', @@ -114,6 +119,11 @@ class EchoHooks { * @return true in all cases */ public static function onWatch( $user, $article ) { + global $wgEchoEnabledEvents; + if ( $wgEchoEnabledEvents !== false && ! in_array( 'edit', $wgEchoEnabledEvents ) ) { + return true; + } + if ( ! $user->getOption('echo-notify-watchlist') ) { return true; } @@ -132,6 +142,11 @@ class EchoHooks { * @return true in all cases */ public static function onUnwatch( $user, $article ) { + global $wgEchoEnabledEvents; + if ( $wgEchoEnabledEvents !== false && ! in_array( 'edit', $wgEchoEnabledEvents ) ) { + return true; + } + $subscription = new EchoSubscription( $user, 'edit', $article->getTitle() ); $subscription->disableNotification('notify'); $subscription->save(); diff --git a/controller/NotificationController.php b/controller/NotificationController.php index 0e01a27b2..c88917a07 100644 --- a/controller/NotificationController.php +++ b/controller/NotificationController.php @@ -186,6 +186,7 @@ class EchoNotificationController { return $notifier->format($event, $user, $type); } - // throw new MWException( "Unable to find notification formatter for event " . $event->getType() ); + return Xml::tags( 'span', array( 'class' => 'error' ), + wfMessage( 'echo-error-no-formatter', $event->getType() )->escaped() ); } } diff --git a/model/Event.php b/model/Event.php index 036d133b6..06ba17f60 100644 --- a/model/Event.php +++ b/model/Event.php @@ -63,6 +63,15 @@ class EchoEvent { throw new MWException( "'type' parameter is mandatory" ); } + global $wgEchoEnabledEvents; + + if ( + $wgEchoEnabledEvents !== false && + ! in_array( $info['type'], $wgEchoEnabledEvents ) + ) { + return false; + } + $obj->id = false; $obj->timestamp = wfTimestampNow(); diff --git a/special/SpecialNotifications.php b/special/SpecialNotifications.php index 76f4de18f..c1b564923 100644 --- a/special/SpecialNotifications.php +++ b/special/SpecialNotifications.php @@ -45,7 +45,7 @@ class SpecialNotifications extends SpecialPage { $event = EchoEvent::newFromRow( $row ); $class = 'mw-echo-notification'; - $formatted = EchoNotificationController::formatNotification( $event, $user(), 'html' ); + $formatted = EchoNotificationController::formatNotification( $event, $user, 'html' ); if ( $row->notification_read_timestamp === null ) { $class .= ' mw-echo-unread';