jenkins-bot has submitted this change and it was merged.

Change subject: Use new LocalisationCacheRecacheFallback hook
......................................................................


Use new LocalisationCacheRecacheFallback hook

This allows us to not use the wrong message when a language itself
doesn't have a change but one of its fallbacks does.

Bug: 68781
Change-Id: I5433aeba95823c5e939efc5e304d955faf1e9551
---
M LocalisationUpdate.class.php
M LocalisationUpdate.php
2 files changed, 30 insertions(+), 3 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/LocalisationUpdate.class.php b/LocalisationUpdate.class.php
index 79253c9..349c35f 100644
--- a/LocalisationUpdate.class.php
+++ b/LocalisationUpdate.class.php
@@ -4,6 +4,29 @@
  * Class for localization update hooks and static methods.
  */
 class LocalisationUpdate {
+       /** @todo Remove this once pre-1.24 versions of MW are no longer 
supported. */
+       private static $onRecacheFallbackCalled = false;
+
+       /**
+        * Hook: LocalisationCacheRecacheFallback
+        */
+       public static function onRecacheFallback( LocalisationCache $lc, $code, 
array &$cache ) {
+               self::$onRecacheFallbackCalled = true;
+
+               $dir = LocalisationUpdate::getDirectory();
+               if ( !$dir ) {
+                       return true;
+               }
+
+               $fileName = "$dir/" . self::getFilename( $code );
+               if ( is_readable( $fileName ) ) {
+                       $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
+                       $cache['messages'] = array_merge( $cache['messages'], 
$data );
+               }
+
+               return true;
+       }
+
        /**
         * Hook: LocalisationCacheRecache
         */
@@ -16,11 +39,14 @@
                $codeSequence = array_merge( array( $code ), 
$cache['fallbackSequence'] );
                foreach ( $codeSequence as $csCode ) {
                        $fileName = "$dir/" . self::getFilename( $csCode );
-                       if ( is_readable( $fileName ) ) {
+                       if ( !self::$onRecacheFallbackCalled && is_readable( 
$fileName ) ) {
+                               // We're on an old version of MW that doesn't 
have the hook
+                               // needed to do things correctly. L10n will be 
broken here in
+                               // certain reasonably-common situations (see 
bug 68781), but
+                               // there's nothing we can do about it.
                                $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
                                $cache['messages'] = array_merge( 
$cache['messages'], $data );
                        }
-
                        $cache['deps'][] = new FileDependency( $fileName );
                }
 
diff --git a/LocalisationUpdate.php b/LocalisationUpdate.php
index 25b6e86..c90bf1b 100644
--- a/LocalisationUpdate.php
+++ b/LocalisationUpdate.php
@@ -40,12 +40,13 @@
        'path' => __FILE__,
        'name' => 'LocalisationUpdate',
        'author' => array( 'Tom Maaswinkel', 'Niklas Laxström', 'Roan Kattouw' 
),
-       'version' => '1.2.0',
+       'version' => '1.3.0',
        'url' => 'https://www.mediawiki.org/wiki/Extension:LocalisationUpdate',
        'descriptionmsg' => 'localisationupdate-desc',
 );
 
 $wgHooks['LocalisationCacheRecache'][] = 'LocalisationUpdate::onRecache';
+$wgHooks['LocalisationCacheRecacheFallback'][] = 
'LocalisationUpdate::onRecacheFallback';
 
 $dir = __DIR__;
 $wgMessagesDirs['LocalisationUpdate'] = __DIR__ . '/i18n';

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5433aeba95823c5e939efc5e304d955faf1e9551
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/LocalisationUpdate
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
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