[MediaWiki-commits] [Gerrit] Archive page and overlay should respect ?uselang=xxx - change (mediawiki...Echo)
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'] ) -
[MediaWiki-commits] [Gerrit] archive page and overlay should respect ?uselang=xxx - change (mediawiki...Echo)
Bsitu has uploaded a new change for review. https://gerrit.wikimedia.org/r/81170 Change subject: archive page and overlay should respect ?uselang=xxx .. archive page and overlay should respect ?uselang=xxx This has not been fully tested yet and this is just a draft implentation bug: 52992 Change-Id: I3585f28d4ec97b86a467958bdfd603791f293d52 --- M Echo.php M api/ApiEchoNotifications.php M formatters/BasicFormatter.php M formatters/PageLinkFormatter.php M includes/EmailFormatter.php M modules/overlay/ext.echo.overlay.js M modules/special/ext.echo.special.js 7 files changed, 37 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/70/81170/1 diff --git a/Echo.php b/Echo.php index 897baec..4a27caf 100644 --- a/Echo.php +++ b/Echo.php @@ -143,6 +143,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 5c7ed92..9e28f94 100644 --- a/formatters/BasicFormatter.php +++ b/formatters/BasicFormatter.php @@ -237,15 +237,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; @@ -339,11 +336,14 @@ * @param $details array An i18n message and parameters to pass to the message * @param $event EchoEvent that the notification is for. * @param $user User to format the notification for. +* @param $lang string The language to format the message to * @return string */ - public function formatFragment( $details, $event, $user ) { - $message = wfMessage( $details['message'] ) - -inLanguage( $user-getOption( 'language' ) ); + public function formatFragment( $details, $event, $user, $lang = '' ) { + $message = wfMessage( $details['message'] ); + if ( $lang ) { + $message-inLanguage( $lang ); + } $this-processParams( $details['params'], $event, $message, $user ); @@ -627,7 +627,7 @@ * 'border: 1px solid green; text-decoration: none;' (optional) * @return String URL for link, or HTML for anchor tag, or empty string */ - public function getLink( $event, $user, $rank = 'primary', $local = true, $urlOnly = false, $style = '' ) { + public function getLink( $event, $user, $rank = 'primary', $local = true, $urlOnly = false, $style = '', $inUserLang = false ) { $destination = $event-getLinkDestination( $rank ); if ( !$destination ) { return ''; @@ -645,7 +645,11 @@ return $target-getFullURL( $query, false, PROTO_HTTPS ); } } else { - $message = wfMessage( $event-getLinkMessage( $rank ) )-inLanguage( $user-getOption( 'language' ) )-text(); + $message = wfMessage( $event-getLinkMessage( $rank ) ); + if (