Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/232064

Change subject: Allow to set the language used to get the license message
......................................................................

Allow to set the language used to get the license message

Instead of always using the site language, use the user language or,
as an alternative, a given language code to generate the license message.
The new parameter to override the default (user) language in getLicense()
is needed to allow to get the correct language for a ResourceLoaderContext,
e.g. in hook ResourceLoaderGetConfigVars.

Bug: T93058
Change-Id: I0a3b1b866baf89ef2b50446e8047355afea2dd00
---
M includes/MobileFrontend.hooks.php
M includes/skins/SkinMinerva.php
2 files changed, 18 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/64/232064/1

diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 861c0bc..989d5a1 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -346,7 +346,7 @@
                $config = $context->getMFConfig();
 
                // Get the licensing agreement that is displayed in the 
uploading interface.
-               $wgMFUploadLicense = SkinMinerva::getLicense( 'upload' );
+               $wgMFUploadLicense = SkinMinerva::getLicense( 'upload', 
array(), $vars['wgUserLanguage'] );
                $vars += array(
                        'wgMFExperiments' => $config->get( 'MFExperiments' ),
                        'wgMFNearbyEndpoint' => $config->get( 
'MFNearbyEndpoint' ),
@@ -356,7 +356,7 @@
                        ),
                        'wgMFContentNamespace' => $config->get( 
'MFContentNamespace' ),
                        'wgMFEditorOptions' => $config->get( 'MFEditorOptions' 
),
-                       'wgMFLicense' => SkinMinerva::getLicense( 'editor' ),
+                       'wgMFLicense' => SkinMinerva::getLicense( 'editor', 
array(), $vars['wgUserLanguage'] ),
                        'wgMFUploadLicenseLink' => $wgMFUploadLicense['link'],
                );
 
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index bf28adf..88743bb 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -1280,13 +1280,25 @@
         * @param string $context The context in which the license link 
appears, e.g. footer,
         *   editor, talk, or upload.
         * @param array $attribs An associative array of extra HTML attributes 
to add to the link
+        * @param string $lang Language code to use instead of default language 
(IContextSource::getLanguage())
         * @return string
         */
-       public static function getLicense( $context, $attribs = array() ) {
-               $config = MobileContext::singleton()->getConfig();
+       public static function getLicense( $context, $attribs = array(), $lang 
= null ) {
+               $mobileContext = MobileContext::singleton();
+               $config = $mobileContext->getConfig();
                $rightsPage = $config->get( 'RightsPage' );
                $rightsUrl = $config->get( 'RightsUrl' );
                $rightsText = $config->get( 'RightsText' );
+
+               if ( $lang !== null && $lang !== 
$mobileContext->getLanguage()->getCode() ) {
+                       $derivativeMobileContext = new DerivativeContext( 
$mobileContext );
+                       $derivativeMobileContext->setLanguage(
+                               Language::factory( 
RequestContext::sanitizeLangCode( $lang ) )
+                       );
+                       $contextSource = $derivativeMobileContext;
+               } else {
+                       $contextSource = $mobileContext;
+               }
 
                // Construct the link to the licensing terms
                if ( $rightsText ) {
@@ -1321,14 +1333,14 @@
                }
 
                // Allow other extensions (for example, WikimediaMessages) to 
override
-               Hooks::run( 'MobileLicenseLink', array( &$link, $context, 
$attribs ) );
+               Hooks::run( 'MobileLicenseLink', array( &$link, $context, 
$attribs, $contextSource ) );
 
                // for plural support we need the info, if there is one or more 
licenses used in the license text
                // this check if very simple and works on the base, that more 
than one license will
                // use "and" as a connective
                // 1 - no plural
                // 2 - plural
-               $delimiterMsg = wfMessage( 'and' );
+               $delimiterMsg = $contextSource->msg( 'and' );
                // check, if "and" isn't disabled and exists in site language
                $isPlural = (
                        !$delimiterMsg->isDisabled() && strpos( $rightsText, 
$delimiterMsg->text() ) === false ? 1 : 2

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0a3b1b866baf89ef2b50446e8047355afea2dd00
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to