diff --git a/ResourceLoaderULSModule.php b/ResourceLoaderULSModule.php new file mode 100644 index 00000000..dda84928 --- /dev/null +++ b/ResourceLoaderULSModule.php @@ -0,0 +1,78 @@ +language->getCode(), 'mwfile' + ); + return $vars; + } + + /** + * @param $context ResourceLoaderContext + * @return string: JavaScript code + */ + public function getScript( ResourceLoaderContext $context ) { + $this->language = Language::factory( $context->getLanguage() ); + $out = ''; + foreach ( $this->getData() as $key => $value ) { + $out .= Xml::encodeJsCall( 'mw.config.set', array( $key, $value ) ); + } + return $out; + } + + /** + * @param $context ResourceLoaderContext + * @return array|int|Mixed + */ + public function getModifiedTime( ResourceLoaderContext $context ) { + $this->language = Language::factory( $context->getLanguage() ); + $cache = wfGetCache( CACHE_ANYTHING ); + $key = wfMemcKey( 'resourceloader', 'ulsmodule', 'changeinfo' ); + + $data = $this->getData(); + $hash = md5( serialize( $data ) ); + + $result = $cache->get( $key ); + if ( is_array( $result ) && $result['hash'] === $hash ) { + return $result['timestamp']; + } + $timestamp = wfTimestamp(); + $cache->set( $key, array( + 'hash' => $hash, + 'timestamp' => $timestamp, + ) ); + return $timestamp; + } +} diff --git a/Resources.php b/Resources.php index f133fac7..e8fab4c0 100644 --- a/Resources.php +++ b/Resources.php @@ -11,6 +11,10 @@ $resourcePaths = array( 'remoteExtPath' => 'UniversalLanguageSelector' ); +$wgResourceModules['ext.uls.languagenames'] = array( + 'class' => 'ResourceLoaderULSModule' +); + $wgResourceModules['ext.uls.displaysettings'] = array( 'scripts' => 'resources/js/ext.uls.displaysettings.js', 'styles' => 'resources/css/ext.uls.displaysettings.css', @@ -41,6 +45,7 @@ $wgResourceModules['ext.uls.init'] = array( 'monobook' => 'resources/css/ext.uls-monobook.css', ), 'dependencies' => array( + 'ext.uls.languagenames', 'mediawiki.Uri', 'mediawiki.util', 'jquery.json', diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index a4eae6e3..4d26264e 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -281,9 +281,6 @@ class UniversalLanguageSelectorHooks { */ public static function addVariables( &$vars, OutputPage $out ) { // Place request context dependent stuff here - $vars['wgULSLanguages'] = Language::fetchLanguageNames( - $out->getLanguage()->getCode(), 'mwfile' - ); $vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() ); return true; diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index 50cc714d..c68047b5 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -123,6 +123,7 @@ $wgExtensionMessagesFiles['UniversalLanguageSelector'] = "$dir/UniversalLanguage // Register auto load for the page class $wgAutoloadClasses['UniversalLanguageSelectorHooks'] = "$dir/UniversalLanguageSelector.hooks.php"; +$wgAutoloadClasses['ResourceLoaderULSModule'] = "$dir/ResourceLoaderULSModule.php"; $wgAutoloadClasses['ApiLanguageSearch'] = "$dir/api/ApiLanguageSearch.php"; $wgAutoloadClasses['LanguageNameSearch'] = "$dir/data/LanguageNameSearch.php";