diff --git a/Notifier.php b/Notifier.php index 22d730fd7..1d6015bae 100644 --- a/Notifier.php +++ b/Notifier.php @@ -12,6 +12,13 @@ class EchoNotifier { public static function notifyWithNotification( $user, $event ) { global $wgEchoConfig, $wgEchoNotifications; + // Only create the notification if the user wants to recieve that type + // of notification and they are eligible to recieve it. See bug 47664. + $userWebNotifications = EchoNotificationController::getUserEnabledEvents( $user, 'web' ); + if ( !in_array( $event->getType(), $userWebNotifications ) ) { + return; + } + EchoNotification::create( array( 'user' => $user, 'event' => $event ) ); self::logEvent( $user, $event, 'web' ); diff --git a/controller/NotificationController.php b/controller/NotificationController.php index e9ce8553d..d7d219a3a 100644 --- a/controller/NotificationController.php +++ b/controller/NotificationController.php @@ -30,6 +30,29 @@ class EchoNotificationController { return $count; } + /** + * Get the enabled events for a user, which excludes user-dismissed events + * from the general enabled events + * @param $user User + * @param $outputFormat string + * @return array + */ + public static function getUserEnabledEvents( $user, $outputFormat ) { + global $wgEchoNotifications; + $eventTypesToLoad = $wgEchoNotifications; + foreach ( $eventTypesToLoad as $eventType => $eventData ) { + $category = self::getNotificationCategory( $eventType ); + // Make sure the user is eligible to recieve this type of notification + if ( !self::getCategoryEligibility( $user, $category ) ) { + unset( $eventTypesToLoad[$eventType] ); + } + if ( !$user->getOption( 'echo-subscriptions-' . $outputFormat . '-' . $category ) ) { + unset( $eventTypesToLoad[$eventType] ); + } + } + return array_keys( $eventTypesToLoad ); + } + /** * See if a user is eligible to recieve a certain type of notification * (based on user groups, not user preferences) diff --git a/includes/DbEchoBackend.php b/includes/DbEchoBackend.php index d73e64715..3e570d2b0 100644 --- a/includes/DbEchoBackend.php +++ b/includes/DbEchoBackend.php @@ -42,7 +42,7 @@ class MWDbEchoBackend extends MWEchoBackend { public function loadNotifications( $user, $limit, $timestamp, $offset, $outputFormat = 'web' ) { $dbr = MWEchoDbFactory::getDB( DB_SLAVE ); - $eventTypesToLoad = $this->getUserEnabledEvents( $user, $outputFormat ); + $eventTypesToLoad = EchoNotificationController::getUserEnabledEvents( $user, $outputFormat ); if ( !$eventTypesToLoad ) { return array(); } @@ -264,7 +264,7 @@ class MWDbEchoBackend extends MWEchoBackend { $dbSource = DB_SLAVE; } - $eventTypesToLoad = $this->getUserEnabledEvents( $user, 'web' ); + $eventTypesToLoad = EchoNotificationController::getUserEnabledEvents( $user, 'web' ); if ( !$eventTypesToLoad ) { return false; diff --git a/includes/EchoBackend.php b/includes/EchoBackend.php index d1d212349..8f1cde7b0 100644 --- a/includes/EchoBackend.php +++ b/includes/EchoBackend.php @@ -25,30 +25,6 @@ abstract class MWEchoBackend { return new $className(); } - /** - * Get the enabled events for a user, which excludes user-dismissed events - * from the general enabled events - * @param $user User - * @param $outputFormat string - * @return array - */ - protected function getUserEnabledEvents( $user, $outputFormat ) { - global $wgEchoNotifications; - $eventTypesToLoad = $wgEchoNotifications; - foreach ( $eventTypesToLoad as $eventType => $eventData ) { - $category = EchoNotificationController::getNotificationCategory( $eventType ); - // Make sure the user is eligible to recieve this type of notification - if ( !EchoNotificationController::getCategoryEligibility( $user, $category ) ) { - unset( $eventTypesToLoad[$eventType] ); - } - if ( !$user->getOption( 'echo-subscriptions-' . $outputFormat . '-' . $category ) ) { - unset( $eventTypesToLoad[$eventType] ); - } - } - - return array_keys( $eventTypesToLoad ); - } - /** * Create a new notification * @param $row array