Transmit current autonym via ResourceLoader instead of config var
This avoids loading of wgULSCurrentAutonym in every HTML page. Change-Id: I8f3a28e3b46f41926bcbe54ace493a33f9ba4566
This commit is contained in:
@@ -228,7 +228,12 @@
|
||||
"js/ext.uls.launch.js",
|
||||
"js/ext.uls.actions.menu.js",
|
||||
"js/ext.uls.actions.menu.item.js",
|
||||
"js/ext.uls.actions.menu.items.registry.js"
|
||||
"js/ext.uls.actions.menu.items.registry.js",
|
||||
{
|
||||
"name": "data.json",
|
||||
"callback": "UniversalLanguageSelector\\Hooks::getModuleData",
|
||||
"versionCallback": "UniversalLanguageSelector\\Hooks::getModuleDataSummary"
|
||||
}
|
||||
],
|
||||
"styles": [
|
||||
"css/ext.uls.interface.less",
|
||||
|
||||
@@ -32,8 +32,10 @@ use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
||||
use MediaWiki\Hook\UserGetLanguageObjectHook;
|
||||
use MediaWiki\Html\Html;
|
||||
use MediaWiki\Languages\LanguageNameUtils;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Output\OutputPage;
|
||||
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
||||
use MediaWiki\ResourceLoader\Context;
|
||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
||||
use MediaWiki\Skins\Hook\SkinAfterPortletHook;
|
||||
use MediaWiki\User\User;
|
||||
@@ -448,13 +450,9 @@ class Hooks implements
|
||||
$vars['wgULSBabelLanguages'] = array_keys( $userLanguageInfo );
|
||||
}
|
||||
|
||||
// An optimization to avoid loading all of uls.data just to get the autonym
|
||||
$langCode = $out->getLanguage()->getCode();
|
||||
$vars['wgULSCurrentAutonym'] = $this->languageNameUtils->getLanguageName( $langCode );
|
||||
|
||||
$setLangCode = $this->getSetLang( $out );
|
||||
if ( $setLangCode ) {
|
||||
$vars['wgULSCurrentLangCode'] = $langCode;
|
||||
$vars['wgULSCurrentLangCode'] = $out->getLanguage()->getCode();
|
||||
$vars['wgULSSetLangCode'] = $setLangCode;
|
||||
$vars['wgULSSetLangName'] = $this->languageNameUtils->getLanguageName( $setLangCode );
|
||||
}
|
||||
@@ -582,4 +580,28 @@ class Hooks implements
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
public static function getModuleData( Context $context, Config $config ): array {
|
||||
$languageNameUtils = MediaWikiServices::getInstance()->getLanguageNameUtils();
|
||||
return [
|
||||
'currentAutonym' => $languageNameUtils->getLanguageName( $context->getLanguage() ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Config $config
|
||||
* @return array
|
||||
*/
|
||||
public static function getModuleDataSummary( Context $context, Config $config ): array {
|
||||
return [
|
||||
'currentAutonym' => $context->getLanguage(),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@
|
||||
previousLanguage = mw.storage.get( 'uls-previous-language-code' );
|
||||
currentLanguage = mw.config.get( 'wgUserLanguage' );
|
||||
previousAutonym = mw.storage.get( 'uls-previous-language-autonym' );
|
||||
currentAutonym = mw.config.get( 'wgULSCurrentAutonym' );
|
||||
currentAutonym = require( '../data.json' ).currentAutonym;
|
||||
|
||||
// If storage is empty, i.e. first visit, then store the current language
|
||||
// immediately so that we know when it changes.
|
||||
|
||||
Reference in New Issue
Block a user