From 1f366807d6172c69b01393d9976a6854ce9ec5dc Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 26 Oct 2015 08:37:57 -0700 Subject: [PATCH] Don't use $wgLang in DataOutputFormatter Require callers to pass it in. Change-Id: I94ec940495a681151b289294186121462d4b5b5c --- includes/DataOutputFormatter.php | 12 +++++------- includes/api/ApiEchoNotifications.php | 4 +++- includes/special/SpecialNotifications.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/includes/DataOutputFormatter.php b/includes/DataOutputFormatter.php index bee304ea1..1230c1add 100644 --- a/includes/DataOutputFormatter.php +++ b/includes/DataOutputFormatter.php @@ -18,9 +18,10 @@ class EchoDataOutputFormatter { * @param EchoNotification $notification * @param string|bool $format specifify output format, false to not format any notifications * @param User $user the target user viewing the notification + * @param Language $lang Language to format the notification in * @return array */ - public static function formatOutput( EchoNotification $notification, $format = false, User $user ) { + public static function formatOutput( EchoNotification $notification, $format = false, User $user, Language $lang ) { $event = $notification->getEvent(); $timestamp = $notification->getTimestamp(); $utcTimestampUnix = wfTimestamp( TS_UNIX, $timestamp ); @@ -108,21 +109,18 @@ class EchoDataOutputFormatter { } if ( $format ) { - $output['*'] = self::formatNotification( $event, $user, $format ); + $output['*'] = self::formatNotification( $event, $user, $format, $lang ); } return $output; } - protected static function formatNotification( EchoEvent $event, User $user, $format ) { - global $wgLang; + protected static function formatNotification( EchoEvent $event, User $user, $format, $lang ) { if ( isset( self::$formatters[$format] ) && EchoEventPresentationModel::supportsPresentationModel( $event->getType() ) ) { - // FIXME don't use $wgLang. It's ok because this is only used for the API or Special page, and not - // emails yet. /** @var EchoEventFormatter $formatter */ - $formatter = new self::$formatters[$format]( $user, $wgLang ); + $formatter = new self::$formatters[$format]( $user, $lang ); return $formatter->format( $event ); } else { // Legacy b/c diff --git a/includes/api/ApiEchoNotifications.php b/includes/api/ApiEchoNotifications.php index db2b03c22..6e7393a84 100644 --- a/includes/api/ApiEchoNotifications.php +++ b/includes/api/ApiEchoNotifications.php @@ -146,7 +146,9 @@ class ApiEchoNotifications extends ApiQueryBase { wfProfileIn( __METHOD__ . '-formatting' ); foreach ( $notifs as $notif ) { - $result['list'][$notif->getEvent()->getID()] = EchoDataOutputFormatter::formatOutput( $notif, $format, $user ); + $result['list'][$notif->getEvent()->getID()] = EchoDataOutputFormatter::formatOutput( + $notif, $format, $user, $this->getLanguage() + ); } wfProfileOut( __METHOD__ . '-formatting' ); diff --git a/includes/special/SpecialNotifications.php b/includes/special/SpecialNotifications.php index 60e344f77..51c18fe8d 100644 --- a/includes/special/SpecialNotifications.php +++ b/includes/special/SpecialNotifications.php @@ -51,7 +51,7 @@ class SpecialNotifications extends SpecialPage { $attributeManager->getUserEnabledEvents( $user, 'web' ) ); foreach ( $notifications as $notification ) { - $notif[] = EchoDataOutputFormatter::formatOutput( $notification, 'html', $user ); + $notif[] = EchoDataOutputFormatter::formatOutput( $notification, 'html', $user, $this->getLanguage() ); } // If there are no notifications, display a message saying so