EBernhardson (WMF) has submitted this change and it was merged.

Change subject: Archive page and overlay should respect ?uselang=xxx
......................................................................


Archive page and overlay should respect ?uselang=xxx

In addition, any message used in the email should be
sent in the user's language.

Bug: 52992
Change-Id: I3585f28d4ec97b86a467958bdfd603791f293d52
---
M Echo.php
M api/ApiEchoNotifications.php
M formatters/BasicFormatter.php
M formatters/CommentFormatter.php
M formatters/EditFormatter.php
M formatters/PageLinkFormatter.php
M formatters/UserRightsFormatter.php
M modules/overlay/ext.echo.overlay.js
M modules/special/ext.echo.special.js
9 files changed, 65 insertions(+), 26 deletions(-)

Approvals:
  Ricordisamoa: Looks good to me, but someone else must approve
  Bartosz Dziewoński: Looks good to me, but someone else must approve
  EBernhardson (WMF): Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Echo.php b/Echo.php
index 62c2eb4..0fde7b3 100644
--- a/Echo.php
+++ b/Echo.php
@@ -145,6 +145,7 @@
                'dependencies' => array(
                        'jquery.ui.button',
                        'mediawiki.api',
+                       'mediawiki.Uri'
                ),
                'messages' => array(
                        'cancel',
diff --git a/api/ApiEchoNotifications.php b/api/ApiEchoNotifications.php
index 25ddb83..2d5c67c 100644
--- a/api/ApiEchoNotifications.php
+++ b/api/ApiEchoNotifications.php
@@ -199,6 +199,7 @@
                        ),
                        'index' => false,
                        'continue' => null,
+                       'uselang' => null
                );
        }
 
@@ -211,6 +212,7 @@
                        'index' => 'If specified, a list of notification IDs, 
in order, will be returned.',
                        'limit' => 'The maximum number of notifications to 
return.',
                        'continue' => 'When more results are available, use 
this to continue',
+                       'uselang' => 'the desired language to format the output'
                );
        }
 
diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php
index d9bcada..f0fda00 100644
--- a/formatters/BasicFormatter.php
+++ b/formatters/BasicFormatter.php
@@ -37,6 +37,13 @@
        protected $icon;
 
        /**
+        * The language to format a message, default language
+        * is the current language
+        * @param mixed Language code or Language object
+        */
+       protected $language;
+
+       /**
         * Required parameters
         * @param array
         */
@@ -237,15 +244,12 @@
                $userLanguage = $user->getOption( 'language' );
 
                $dismissTitle = wfMessage( 'echo-category-title-' . 
$event->getCategory() )
-                       ->inLanguage( $userLanguage )
                        ->numParams( 1 )
                        ->text();
                $dismissMessage = wfMessage( 'echo-dismiss-message', 
$dismissTitle )
-                       ->inLanguage( $userLanguage )
                        ->escaped();
                $dismiss = Xml::tags( 'div', array( 'class' => 
'mw-echo-dismiss-message' ), $dismissMessage ) . "\n";
                $prefsMessage = wfMessage( 'echo-dismiss-prefs-message' )
-                       ->inLanguage( $userLanguage )
                        ->escaped();
                $dismiss .= Xml::tags( 'div', array( 'class' => 
'mw-echo-prefs-dismiss-message' ), $prefsMessage ) . "\n";
                $dismiss = Xml::tags( 'div', array( 'class' => 
'mw-echo-dismiss', 'style' => 'display:none;' ), $dismiss ) . "\n";
@@ -274,6 +278,9 @@
         * @return array
         */
        protected function formatEmail( $event, $user, $type ) {
+               // Email should be always sent in user language
+               $this->language = $user->getOption( 'language' );
+
                // Email digest
                if ( $type === 'emaildigest' ) {
                        return $this->formatEmailDigest( $event, $user );
@@ -334,6 +341,20 @@
        }
 
        /**
+        * Get Message object in the desired language, use this method instead
+        * of wfMessage() if a message would be used in either web or email
+        * @param $msgStr string message string
+        * @return Message
+        */
+       public function getMessage( $msgStr ) {
+               $message = wfMessage( $msgStr );
+               if ( $this->language ) {
+                       $message->inLanguage( $this->language );
+               }
+               return $message;
+       }
+
+       /**
         * Creates a notification fragment based on a message and parameters
         *
         * @param $details array An i18n message and parameters to pass to the 
message
@@ -342,9 +363,7 @@
         * @return string
         */
        public function formatFragment( $details, $event, $user ) {
-               $message = wfMessage( $details['message'] )
-                       ->inLanguage( $user->getOption( 'language' ) );
-
+               $message = $this->getMessage( $details['message'] );
                $this->processParams( $details['params'], $event, $message, 
$user );
 
                return $message;
@@ -392,7 +411,7 @@
         */
        protected function formatCommentText( EchoEvent $event, $user ) {
                if ( !$event->userCan( Revision::DELETED_TEXT, $user ) ) {
-                       return wfMessage( 'echo-rev-deleted-text-view' 
)->text();
+                       return $this->getMessage( 'echo-rev-deleted-text-view' 
)->text();
                }
                $extra = $event->getExtra();
                if ( !isset( $extra['content'] ) ) {
@@ -415,7 +434,7 @@
                global $wgParser, $wgUser;
 
                if ( !$event->userCan( Revision::DELETED_TEXT, $wgUser ) ) {
-                       return wfMessage( 'echo-rev-deleted-text-view' 
)->text();
+                       return $this->getMessage( 'echo-rev-deleted-text-view' 
)->text();
                }
                $extra = $event->getExtra();
                if ( empty( $extra['section-title'] ) ) {
@@ -452,7 +471,7 @@
         */
        protected function setTitleLink( $event, $message, $props = array() ) {
                if ( !$event->getTitle() ) {
-                       $message->params( wfMessage( 'echo-no-title' )->text() 
);
+                       $message->params( $this->getMessage( 'echo-no-title' 
)->text() );
                        return;
                }
 
@@ -650,7 +669,7 @@
                                return $target->getFullURL( $query, false, 
PROTO_HTTPS );
                        }
                } else {
-                       $message = wfMessage( $event->getLinkMessage( $rank ) 
)->inLanguage( $user->getOption( 'language' ) )->text();
+                       $message = $this->getMessage( $event->getLinkMessage( 
$rank ) )->text();
                        $attribs = array( 'class' => 
"mw-echo-notification-{$rank}-link" );
                        if ( $style ) {
                                $attribs['style'] = $style;
@@ -733,9 +752,9 @@
                if ( $param === 'agent' ) {
                        $agent = $event->getAgent();
                        if ( !$agent ) {
-                               $message->params( wfMessage( 'echo-no-agent' 
)->text() );
+                               $message->params( $this->getMessage( 
'echo-no-agent' )->text() );
                        } elseif ( !$event->userCan( Revision::DELETED_USER, 
$user ) ) {
-                               $message->params( wfMessage( 'rev-deleted-user' 
)->text() );
+                               $message->params( $this->getMessage( 
'rev-deleted-user' )->text() );
                        } else {
                                if ( $this->outputFormat === 'htmlemail' ) {
                                        $message->rawParams(
@@ -757,8 +776,7 @@
 
                        if ( $this->bundleData['agent-other-count'] > 
$wgEchoMaxNotificationCount ) {
                                $message->params(
-                                       wfMessage( 'echo-notification-count' )
-                                       ->inLanguage( $user->getOption( 
'language' ) )
+                                       $this->getMessage( 
'echo-notification-count' )
                                        ->params( $wgEchoMaxNotificationCount )
                                        ->text()
                                );
@@ -772,7 +790,7 @@
                        $message->params( $user->getName() );
                } elseif ( $param === 'title' ) {
                        if ( !$event->getTitle() ) {
-                               $message->params( wfMessage( 'echo-no-title' 
)->text() );
+                               $message->params( $this->getMessage( 
'echo-no-title' )->text() );
                        } else {
                                if ( $this->outputFormat === 'htmlemail' ) {
                                        $props = array (
@@ -809,4 +827,5 @@
                }
                return $this->$key;
        }
+
 }
diff --git a/formatters/CommentFormatter.php b/formatters/CommentFormatter.php
index 15a277f..c966dd9 100644
--- a/formatters/CommentFormatter.php
+++ b/formatters/CommentFormatter.php
@@ -23,7 +23,7 @@
                // The title text without namespace
                } elseif ( $param === 'main-title-text' ) {
                        if ( !$event->getTitle() ) {
-                               $message->params( wfMessage( 'echo-no-title' 
)->text() );
+                               $message->params( $this->getMessage( 
'echo-no-title' )->text() );
                        } else {
                                $message->params( $event->getTitle()->getText() 
);      
                        }
diff --git a/formatters/EditFormatter.php b/formatters/EditFormatter.php
index 30770b7..eb5474a 100644
--- a/formatters/EditFormatter.php
+++ b/formatters/EditFormatter.php
@@ -21,7 +21,10 @@
                        }
                        $props = array(
                                'attribs' => array( 'class' => 'mw-echo-diff' ),
-                               'linkText' => wfMessage( 'parentheses', 
wfMessage( 'showdiff' )->text() )->escaped(),
+                               'linkText' => $this->getMessage( 'parentheses' )
+                                               ->params(
+                                                       $this->getMessage( 
'showdiff' )->text()
+                                               )->escaped(),
                                'param' => array(
                                        'oldid' => $revid,
                                        'diff' => 'prev',
diff --git a/formatters/PageLinkFormatter.php b/formatters/PageLinkFormatter.php
index a718be6..da23518 100644
--- a/formatters/PageLinkFormatter.php
+++ b/formatters/PageLinkFormatter.php
@@ -135,7 +135,7 @@
                                }
 
                                if ( !$title ) {
-                                       $message->params( wfMessage( 
'echo-no-title' ) );
+                                       $message->params( $this->getMessage( 
'echo-no-title' ) );
                                }
                                break;
 
@@ -145,8 +145,7 @@
 
                                if ( 
$this->bundleData['link-from-page-other-count'] > $wgEchoMaxNotificationCount ) 
{
                                        $message->params(
-                                               wfMessage( 
'echo-notification-count' )
-                                               ->inLanguage( $user->getOption( 
'language' ) )
+                                               $this->getMessage( 
'echo-notification-count' )
                                                ->params( 
$wgEchoMaxNotificationCount )
                                                ->text()
                                        );
diff --git a/formatters/UserRightsFormatter.php 
b/formatters/UserRightsFormatter.php
index 480f00b..7e66bd9 100644
--- a/formatters/UserRightsFormatter.php
+++ b/formatters/UserRightsFormatter.php
@@ -26,7 +26,7 @@
                                                // Messages that can be used 
here:
                                                // * 
notification-user-rights-add
                                                // * 
notification-user-rights-remove
-                                               $list[] = wfMessage( 
'notification-user-rights-' . $action )
+                                               $list[] = $this->getMessage( 
'notification-user-rights-' . $action )
                                                        ->params( 
$wgLang->commaList( $extra[$action] ), count( $extra[$action] ) )
                                                        ->escaped();
                                        }
diff --git a/modules/overlay/ext.echo.overlay.js 
b/modules/overlay/ext.echo.overlay.js
index 508a426..06395ce 100644
--- a/modules/overlay/ext.echo.overlay.js
+++ b/modules/overlay/ext.echo.overlay.js
@@ -23,6 +23,8 @@
                                $overlay = $( '<div></div>' ).addClass( 
'mw-echo-overlay' ),
                                $prefLink = $( '#pt-preferences a' ),
                                count = 0,
+                               apiData,
+                               curUri = new mw.Uri(),
                                api = new mw.Api( { ajax: { cache: false } } );
 
                        // Set notification limit based on height of the window
@@ -34,13 +36,19 @@
                                notificationLimit = 8;
                        }
 
-                       api.get( {
+                       apiData = {
                                'action' : 'query',
                                'meta' : 'notifications',
                                'notformat' : 'flyout',
                                'notlimit' : notificationLimit,
                                'notprop' : 'index|list|count'
-                       } ).done( function ( result ) {
+                       };
+
+                       if ( curUri.query.uselang !== undefined ) {
+                               apiData.uselang = curUri.query.uselang;
+                       }
+
+                       api.get( apiData ).done( function ( result ) {
                                var notifications = result.query.notifications,
                                        unread = [],
                                        unreadTotalCount = 
result.query.notifications.count,
diff --git a/modules/special/ext.echo.special.js 
b/modules/special/ext.echo.special.js
index 8903930..187e6d4 100644
--- a/modules/special/ext.echo.special.js
+++ b/modules/special/ext.echo.special.js
@@ -60,16 +60,23 @@
                 * Load more notification records.
                 */
                loadMore: function () {
-                       var api = new mw.Api( { ajax: { cache: false } } ), 
notifications, data, container, $li, that = this, unread = [];
+                       var api = new mw.Api( { ajax: { cache: false } } ), 
curUri = new mw.Uri(),
+                               notifications, data, container, $li, that = 
this, unread = [], apiData;
 
-                       api.get( {
+                       apiData = {
                                'action' : 'query',
                                'meta' : 'notifications',
                                'notformat' : 'html',
                                'notprop' : 'index|list',
                                'notcontinue': this.notcontinue,
                                'notlimit': mw.config.get( 'wgEchoDisplayNum' )
-                       } ).done( function ( result ) {
+                       };
+
+                       if ( curUri.query.uselang !== undefined ) {
+                               apiData.uselang = curUri.query.uselang;
+                       }
+
+                       api.get( apiData ).done( function ( result ) {
                                container = $( '#mw-echo-special-container' );
                                notifications = result.query.notifications;
                                unread = [];

-- 
To view, visit https://gerrit.wikimedia.org/r/81170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3585f28d4ec97b86a467958bdfd603791f293d52
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: EBernhardson (WMF) <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Ricordisamoa <ricordisa...@live.it>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to