Don't use $wgLang in DataOutputFormatter

Require callers to pass it in.

Change-Id: I94ec940495a681151b289294186121462d4b5b5c
This commit is contained in:
Kunal Mehta 2015-10-26 08:37:57 -07:00
parent f40ef7019f
commit 1f366807d6
3 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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' );

View file

@ -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