Yurik has uploaded a new change for review.

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


Change subject: Banner fallback behavior
......................................................................

Banner fallback behavior

Now if the banner is not defined in language X, the fallback
is the default 'access-banner-text' instead of the banners
in other languages for the same carrier.

Change-Id: I15074346ab1a0e029119f8737a26d3bf4ada5902
---
M includes/PageRenderingHooks.php
M includes/ZeroConfigContent.php
2 files changed, 10 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroRatedMobileAccess 
refs/changes/56/71756/1

diff --git a/includes/PageRenderingHooks.php b/includes/PageRenderingHooks.php
index 8ff09d6..2f6d50b 100644
--- a/includes/PageRenderingHooks.php
+++ b/includes/PageRenderingHooks.php
@@ -567,15 +567,16 @@
                        global $wgLang;
                        $lang = $wgLang;
                }
-               $fallbacks = null;
-               $name = self::pickLocalizedString( $config['name'], $lang, 
$fallbacks );
+               $name = self::pickLocalizedString( $config['name'], $lang );
                if ( $name === false ) {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
                $nameMsg = new RawMessage( $name );
-               $linkText = self::pickLocalizedString( $config['banner'], 
$lang, $fallbacks );
-               if ( $linkText === false ) {
+
+               if ( array_key_exists( $lang->getCode(), $config['banner'] ) ) {
+                       $linkText = $config['banner'][$lang->getCode()];
+               } else {
                        $linkText = wfMessage( 
'zero-rated-mobile-access-banner-text' )->inLanguage( $lang )->plain();
                }
                if ( $sitename !== null ) {
@@ -836,19 +837,16 @@
         * or use language fallbacks if message is not defined.
         * @param array $map Dictionary of languageCode => string
         * @param Language $lang language object
-        * @param array $fallbacks array of fallback messages (could be null, 
will be initialized)
         * @return string|bool message from the dictionary or false if nothing 
found
         */
-       private static function pickLocalizedString( $map, $lang, &$fallbacks ) 
{
+       private static function pickLocalizedString( $map, $lang ) {
                $langCode = $lang->getCode();
                if ( array_key_exists( $langCode, $map ) ) {
                        return $map[$langCode];
                }
-               if ( $fallbacks === null ) {
-                       $fallbacks = $lang->getFallbackLanguages();
-                       if ( count( $fallbacks ) === 0 ) {
-                               $fallbacks = array( 'en' );
-                       }
+               $fallbacks = $lang->getFallbackLanguages();
+               if ( count( $fallbacks ) === 0 ) {
+                       $fallbacks = array( 'en' );
                }
                foreach ( $fallbacks as $l ) {
                        if ( array_key_exists( $l, $map ) ) {
diff --git a/includes/ZeroConfigContent.php b/includes/ZeroConfigContent.php
index e959767..c87684b 100644
--- a/includes/ZeroConfigContent.php
+++ b/includes/ZeroConfigContent.php
@@ -121,7 +121,7 @@
                                        }
                                        break;
                                case 1:
-                                       if ( $parentKey === 'name' || 
$parentKey === 'banner' ) {
+                                       if ( $parentKey === 'name' ) {
                                                $lang = Language::factory( $key 
);
                                                $fallbacks = 
$lang->getFallbackLanguages();
                                                if ( count( $fallbacks ) === 0 
&& $key !== 'en' ) {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15074346ab1a0e029119f8737a26d3bf4ada5902
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>

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

Reply via email to