From c6289d013eac6194fb6631e8b0d9723f580982b0 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 29 Aug 2014 10:13:21 -0700 Subject: [PATCH] ResourceLoaderFileModule: Support fallback in 'languageScripts' Bug: 58139 Change-Id: Idd7657aa48a9eb2b075a85f77e066b425f330890 --- RELEASE-NOTES-1.25 | 2 ++ .../ResourceLoaderFileModule.php | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 9dbf896cfc..03009bc680 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -11,6 +11,8 @@ production. === Configuration changes in 1.25 === === New features in 1.25 === +* (bug 58139) ResourceLoaderFileModule now supports language fallback + for 'languageScripts'. === Bug fixes in 1.25 === diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index a77e8f7193..7bbc9bbe6a 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -536,7 +536,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { $files, $this->scripts, $context->getDebug() ? $this->debugScripts : array(), - self::tryForKey( $this->languageScripts, $context->getLanguage() ), + $this->getLanguageScripts( $context->getLanguage() ), self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ), $this->loaderScripts ); @@ -700,7 +700,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { protected function getScriptFiles( ResourceLoaderContext $context ) { $files = array_merge( $this->scripts, - self::tryForKey( $this->languageScripts, $context->getLanguage() ), + $this->getLanguageScripts( $context->getLanguage() ), self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ) ); if ( $context->getDebug() ) { @@ -710,6 +710,29 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { return array_unique( $files, SORT_REGULAR ); } + /** + * Get the set of language scripts for the given language, + * possibly using a fallback language. + * + * @param string $lang + * @return array + */ + private function getLanguageScripts( $lang ) { + $scripts = self::tryForKey( $this->languageScripts, $lang ); + if ( $scripts ) { + return $scripts; + } + $fallbacks = Language::getFallbacksFor( $lang ); + foreach ( $fallbacks as $lang ) { + $scripts = self::tryForKey( $this->languageScripts, $lang ); + if ( $scripts ) { + return $scripts; + } + } + + return array(); + } + /** * Get a list of file paths for all styles in this module, in order of proper inclusion. * -- 2.20.1