[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Class for localization update hooks and static methods. 5 */ 6 class LocalisationUpdate { 7 /** @todo Remove this once pre-1.24 versions of MW are no longer supported. */ 8 private static $onRecacheFallbackCalled = false; 9 10 /** 11 * Hook: LocalisationCacheRecacheFallback 12 */ 13 public static function onRecacheFallback( LocalisationCache $lc, $code, array &$cache ) { 14 self::$onRecacheFallbackCalled = true; 15 16 $dir = LocalisationUpdate::getDirectory(); 17 if ( !$dir ) { 18 return true; 19 } 20 21 $fileName = "$dir/" . self::getFilename( $code ); 22 if ( is_readable( $fileName ) ) { 23 $data = FormatJson::decode( file_get_contents( $fileName ), true ); 24 $cache['messages'] = array_merge( $cache['messages'], $data ); 25 } 26 27 return true; 28 } 29 30 /** 31 * Hook: LocalisationCacheRecache 32 */ 33 public static function onRecache( LocalisationCache $lc, $code, array &$cache ) { 34 $dir = LocalisationUpdate::getDirectory(); 35 if ( !$dir ) { 36 return true; 37 } 38 39 $codeSequence = array_merge( array( $code ), $cache['fallbackSequence'] ); 40 foreach ( $codeSequence as $csCode ) { 41 $fileName = "$dir/" . self::getFilename( $csCode ); 42 if ( !self::$onRecacheFallbackCalled && is_readable( $fileName ) ) { 43 // We're on an old version of MW that doesn't have the hook 44 // needed to do things correctly. L10n will be broken here in 45 // certain reasonably-common situations (see bug 68781), but 46 // there's nothing we can do about it. 47 $data = FormatJson::decode( file_get_contents( $fileName ), true ); 48 $cache['messages'] = array_merge( $cache['messages'], $data ); 49 } 50 $cache['deps'][] = new FileDependency( $fileName ); 51 } 52 53 return true; 54 } 55 56 /** 57 * Returns a directory where updated translations are stored. 58 * 59 * @return string|false False if not configured. 60 * @since 1.1 61 */ 62 public static function getDirectory() { 63 global $wgLocalisationUpdateDirectory, $wgCacheDirectory; 64 65 // ?: can be used once we drop support for MW 1.19 66 return $wgLocalisationUpdateDirectory ? 67 $wgLocalisationUpdateDirectory : 68 $wgCacheDirectory; 69 } 70 71 /** 72 * Returns a filename where updated translations are stored. 73 * 74 * @param string $language Language tag 75 * @return string 76 * @since 1.1 77 */ 78 public static function getFilename( $language ) { 79 return "l10nupdate-$language.json"; 80 } 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |