Use HookHandlers and inject services

This change also replaces the calls of deprecated functions from class
Language and replaces the global variables by the MainConfig.

Change-Id: Ice7273481a736cb138e263a9300bfd90fdcbb401
This commit is contained in:
Fomafix
2021-10-27 06:21:50 +00:00
committed by jenkins-bot
parent c482541ef7
commit f0c6bec1ac
2 changed files with 149 additions and 115 deletions

View File

@@ -20,15 +20,26 @@
"MediaWiki": ">= 1.35.0" "MediaWiki": ">= 1.35.0"
}, },
"Hooks": { "Hooks": {
"BeforePageDisplay": "UniversalLanguageSelectorHooks::addModules", "BeforePageDisplay": "main",
"EnterMobileMode": "UniversalLanguageSelectorHooks::onEnterMobileMode", "EnterMobileMode": "main",
"GetBetaFeaturePreferences": "UniversalLanguageSelectorHooks::onGetBetaFeaturePreferences", "GetBetaFeaturePreferences": "main",
"GetPreferences": "UniversalLanguageSelectorHooks::onGetPreferences", "GetPreferences": "main",
"MakeGlobalVariablesScript": "UniversalLanguageSelectorHooks::addVariables", "MakeGlobalVariablesScript": "main",
"ResourceLoaderGetConfigVars": "UniversalLanguageSelectorHooks::addConfig", "ResourceLoaderGetConfigVars": "main",
"SkinAfterPortlet": "UniversalLanguageSelectorHooks::onSkinAfterPortlet", "SkinAfterPortlet": "main",
"SkinTemplateNavigation::Universal": "UniversalLanguageSelectorHooks::onSkinTemplateNavigationUniversal", "SkinTemplateNavigation::Universal": "main",
"UserGetLanguageObject": "UniversalLanguageSelectorHooks::getLanguage" "UserGetLanguageObject": "main"
},
"HookHandlers": {
"main": {
"class": "UniversalLanguageSelectorHooks",
"services": [
"MainConfig",
"UserOptionsLookup",
"StatsdDataFactory",
"LanguageNameUtils"
]
}
}, },
"APIModules": { "APIModules": {
"languagesearch": "ApiLanguageSearch", "languagesearch": "ApiLanguageSearch",

View File

@@ -19,9 +19,58 @@
*/ */
use MediaWiki\Extension\BetaFeatures\BetaFeatures; use MediaWiki\Extension\BetaFeatures\BetaFeatures;
use MediaWiki\MediaWikiServices; use MediaWiki\Hook\BeforePageDisplayHook;
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
use MediaWiki\Hook\PersonalUrlsHook;
use MediaWiki\Hook\UserGetLanguageObjectHook;
use MediaWiki\Languages\LanguageNameUtils;
use MediaWiki\Preferences\Hook\GetPreferencesHook;
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
use MediaWiki\Skins\Hook\SkinAfterPortletHook;
use MediaWiki\User\UserOptionsLookup;
class UniversalLanguageSelectorHooks { /**
* @phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
*/
class UniversalLanguageSelectorHooks implements
BeforePageDisplayHook,
PersonalUrlsHook,
UserGetLanguageObjectHook,
ResourceLoaderGetConfigVarsHook,
MakeGlobalVariablesScriptHook,
GetPreferencesHook,
SkinAfterPortletHook
{
/** @var Config */
private $config;
/** @var UserOptionsLookup */
private $userOptionsLookup;
/** @var IBufferingStatsdDataFactory */
private $statsdDataFactory;
/** @var LanguageNameUtils */
private $languageNameUtils;
/**
* @param Config $config
* @param UserOptionsLookup $userOptionsLookup
* @param IBufferingStatsdDataFactory $statsdDataFactory
* @param LanguageNameUtils $languageNameUtils
*/
public function __construct(
Config $config,
UserOptionsLookup $userOptionsLookup,
IBufferingStatsdDataFactory $statsdDataFactory,
LanguageNameUtils $languageNameUtils
) {
$this->config = $config;
$this->userOptionsLookup = $userOptionsLookup;
$this->statsdDataFactory = $statsdDataFactory;
$this->languageNameUtils = $languageNameUtils;
}
public static function setVersionConstant() { public static function setVersionConstant() {
global $wgHooks; global $wgHooks;
@@ -44,10 +93,8 @@ class UniversalLanguageSelectorHooks {
* fonts, language change undo tooltip). * fonts, language change undo tooltip).
* @return bool * @return bool
*/ */
private static function isEnabled(): bool { private function isEnabled(): bool {
global $wgULSEnable; return (bool)$this->config->get( 'ULSEnable' );
return (bool)$wgULSEnable;
} }
/** /**
@@ -56,18 +103,15 @@ class UniversalLanguageSelectorHooks {
* @param User $user * @param User $user
* @return bool * @return bool
*/ */
private static function isCompactLinksEnabled( User $user ) { private function isCompactLinksEnabled( User $user ) {
global $wgULSEnable, $wgInterwikiMagic,
$wgHideInterlanguageLinks, $wgULSCompactLanguageLinksBetaFeature;
// Whether any user visible features are enabled // Whether any user visible features are enabled
if ( !$wgULSEnable ) { if ( !$this->config->get( 'ULSEnable' ) ) {
return false; return false;
} }
if ( $wgULSCompactLanguageLinksBetaFeature === true && if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === true &&
$wgInterwikiMagic === true && $this->config->get( 'InterwikiMagic' ) === true &&
$wgHideInterlanguageLinks === false && $this->config->get( 'HideInterlanguageLinks' ) === false &&
ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) &&
BetaFeatures::isFeatureEnabled( $user, 'uls-compact-links' ) BetaFeatures::isFeatureEnabled( $user, 'uls-compact-links' )
) { ) {
@@ -76,10 +120,10 @@ class UniversalLanguageSelectorHooks {
return true; return true;
} }
if ( $wgULSCompactLanguageLinksBetaFeature === false ) { if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === false ) {
// Compact language links is a default feature in this wiki. // Compact language links is a default feature in this wiki.
// Check user preference // Check user preference
return MediaWikiServices::getInstance()->getUserOptionsLookup() return $this->userOptionsLookup
->getBoolOption( $user, 'compact-language-links' ); ->getBoolOption( $user, 'compact-language-links' );
} }
@@ -91,8 +135,7 @@ class UniversalLanguageSelectorHooks {
* @param Skin $skin * @param Skin $skin
* Hook: BeforePageDisplay * Hook: BeforePageDisplay
*/ */
public static function addModules( OutputPage $out, Skin $skin ) { public function onBeforePageDisplay( $out, $skin ): void {
global $wgULSPosition, $wgULSGeoService;
$unsupportedSkins = [ 'minerva' ]; $unsupportedSkins = [ 'minerva' ];
if ( in_array( $skin->getSkinName(), $unsupportedSkins ) ) { if ( in_array( $skin->getSkinName(), $unsupportedSkins ) ) {
return; return;
@@ -101,8 +144,8 @@ class UniversalLanguageSelectorHooks {
$excludedLinks = $out->getProperty( 'noexternallanglinks' ); $excludedLinks = $out->getProperty( 'noexternallanglinks' );
$override = is_array( $excludedLinks ) && in_array( '*', $excludedLinks ); $override = is_array( $excludedLinks ) && in_array( '*', $excludedLinks );
$config = [ $config = [
'wgULSPosition' => $wgULSPosition, 'wgULSPosition' => $this->config->get( 'ULSPosition' ),
'wgULSisCompactLinksEnabled' => self::isCompactLinksEnabled( $out->getUser() ), 'wgULSisCompactLinksEnabled' => $this->isCompactLinksEnabled( $out->getUser() ),
]; ];
// Load compact links if no mw-interlanguage-selector element is present in the page HTML. // Load compact links if no mw-interlanguage-selector element is present in the page HTML.
@@ -110,17 +153,17 @@ class UniversalLanguageSelectorHooks {
// using the class as the heuristic. // using the class as the heuristic.
// Note if the element is rendered by the skin, its assumed that no collapsing is needed. // Note if the element is rendered by the skin, its assumed that no collapsing is needed.
// See T264824 for more information. // See T264824 for more information.
if ( !$override && self::isCompactLinksEnabled( $out->getUser() ) && if ( !$override && $this->isCompactLinksEnabled( $out->getUser() ) &&
strpos( $out->getHTML(), 'mw-interlanguage-selector' ) === false strpos( $out->getHTML(), 'mw-interlanguage-selector' ) === false
) { ) {
$out->addModules( 'ext.uls.compactlinks' ); $out->addModules( 'ext.uls.compactlinks' );
} }
if ( is_string( $wgULSGeoService ) ) { if ( is_string( $this->config->get( 'ULSGeoService' ) ) ) {
$out->addModules( 'ext.uls.geoclient' ); $out->addModules( 'ext.uls.geoclient' );
} }
if ( self::isEnabled() ) { if ( $this->isEnabled() ) {
// Enable UI language selection for the user. // Enable UI language selection for the user.
$out->addModules( 'ext.uls.interface' ); $out->addModules( 'ext.uls.interface' );
} }
@@ -129,7 +172,7 @@ class UniversalLanguageSelectorHooks {
// For example, ContentTranslation special pages depend on being able to change it. // For example, ContentTranslation special pages depend on being able to change it.
$out->addJsConfigVars( $config ); $out->addJsConfigVars( $config );
if ( $wgULSPosition === 'personal' ) { if ( $this->config->get( 'ULSPosition' ) === 'personal' ) {
$out->addModuleStyles( 'ext.uls.pt' ); $out->addModuleStyles( 'ext.uls.pt' );
} else { } else {
$out->addModuleStyles( 'ext.uls.interlanguage' ); $out->addModuleStyles( 'ext.uls.interlanguage' );
@@ -139,7 +182,7 @@ class UniversalLanguageSelectorHooks {
$out->addModuleStyles( 'ext.uls.preferencespage' ); $out->addModuleStyles( 'ext.uls.preferencespage' );
} }
self::handleSetLang( $out ); $this->handleSetLang( $out );
} }
/** /**
@@ -148,15 +191,14 @@ class UniversalLanguageSelectorHooks {
* @param OutputPage $out * @param OutputPage $out
* @return void * @return void
*/ */
protected static function handleSetLang( OutputPage $out ): void { protected function handleSetLang( OutputPage $out ): void {
$languageToSet = self::getSetLang( $out ); $languageToSet = $this->getSetLang( $out );
if ( !$languageToSet ) { if ( !$languageToSet ) {
return; return;
} }
MediaWikiServices::getInstance()->getStatsdDataFactory() $this->statsdDataFactory->increment( 'uls.setlang_used' );
->increment( 'uls.setlang_used' );
$user = $out->getUser(); $user = $out->getUser();
if ( $user->isAnon() && !$out->getConfig()->get( 'ULSAnonCanChangeLanguage' ) ) { if ( $user->isAnon() && !$out->getConfig()->get( 'ULSAnonCanChangeLanguage' ) ) {
@@ -171,11 +213,11 @@ class UniversalLanguageSelectorHooks {
* Add some tabs for navigation for users who do not use Ajax interface. * Add some tabs for navigation for users who do not use Ajax interface.
* Hook: PersonalUrls * Hook: PersonalUrls
* @param array &$personal_urls * @param array &$personal_urls
* @param Title $title * @param Title &$title
* @param SkinTemplate $skin * @param SkinTemplate $skin
*/ */
public static function onPersonalUrls( &$personal_urls, $title, SkinTemplate $skin ) { public function onPersonalUrls( &$personal_urls, &$title, $skin ): void {
$personal_urls = self::addPersonalBarTrigger( $personal_urls = $this->addPersonalBarTrigger(
$personal_urls, $personal_urls,
$skin $skin
); );
@@ -185,13 +227,13 @@ class UniversalLanguageSelectorHooks {
* @param SkinTemplate $skin * @param SkinTemplate $skin
* @param array &$links * @param array &$links
*/ */
public static function onSkinTemplateNavigationUniversal( SkinTemplate $skin, array &$links ) { public function onSkinTemplateNavigation__Universal( SkinTemplate $skin, array &$links ) {
// In modern skins which separate out the user menu, // In modern skins which separate out the user menu,
// e.g. Vector. (T282196) // e.g. Vector. (T282196)
// this should appear in the `user-interface-preferences` menu. // this should appear in the `user-interface-preferences` menu.
// For older skins not separating out the user menu this will be prepended. // For older skins not separating out the user menu this will be prepended.
if ( isset( $links['user-interface-preferences'] ) ) { if ( isset( $links['user-interface-preferences'] ) ) {
$links['user-interface-preferences'] = self::addPersonalBarTrigger( $links['user-interface-preferences'] = $this->addPersonalBarTrigger(
$links['user-interface-preferences'], $links['user-interface-preferences'],
$skin $skin
); );
@@ -204,17 +246,15 @@ class UniversalLanguageSelectorHooks {
* @param SkinTemplate $context SkinTemplate object providing context * @param SkinTemplate $context SkinTemplate object providing context
* @return array of modified personal urls * @return array of modified personal urls
*/ */
private static function addPersonalBarTrigger( private function addPersonalBarTrigger(
array &$personal_urls, array &$personal_urls,
SkinTemplate $context SkinTemplate $context
) { ) {
global $wgULSPosition; if ( $this->config->get( 'ULSPosition' ) !== 'personal' ) {
if ( $wgULSPosition !== 'personal' ) {
return $personal_urls; return $personal_urls;
} }
if ( !self::isEnabled() ) { if ( !$this->isEnabled() ) {
return $personal_urls; return $personal_urls;
} }
@@ -224,7 +264,7 @@ class UniversalLanguageSelectorHooks {
if ( version_compare( MW_VERSION, '1.36', '<' ) ) { if ( version_compare( MW_VERSION, '1.36', '<' ) ) {
return [ return [
'uls' => [ 'uls' => [
'text' => Language::fetchLanguageName( $langCode ), 'text' => $this->languageNameUtils->getLanguageName( $langCode ),
'href' => '#', 'href' => '#',
'class' => 'uls-trigger', 'class' => 'uls-trigger',
'active' => true 'active' => true
@@ -233,7 +273,7 @@ class UniversalLanguageSelectorHooks {
} else { } else {
return [ return [
'uls' => [ 'uls' => [
'text' => Language::fetchLanguageName( $langCode ), 'text' => $this->languageNameUtils->getLanguageName( $langCode ),
'href' => '#', 'href' => '#',
// Skin meta data to allow skin (e.g. Vector) to add icons // Skin meta data to allow skin (e.g. Vector) to add icons
'icon' => 'wikimedia-language', 'icon' => 'wikimedia-language',
@@ -250,8 +290,8 @@ class UniversalLanguageSelectorHooks {
* @param array $preferred * @param array $preferred
* @return string * @return string
*/ */
protected static function getDefaultLanguage( array $preferred ) { protected function getDefaultLanguage( array $preferred ) {
$supported = Language::fetchLanguageNames( null, 'mwfile' ); $supported = $this->languageNameUtils->getLanguageNames( LanguageNameUtils::AUTONYMS, 'mwfile' );
// look for a language that is acceptable to the client // look for a language that is acceptable to the client
// and known to the wiki. // and known to the wiki.
@@ -280,10 +320,8 @@ class UniversalLanguageSelectorHooks {
* @param string &$code * @param string &$code
* @param IContextSource $context * @param IContextSource $context
*/ */
public static function getLanguage( User $user, &$code, IContextSource $context ) { public function onUserGetLanguageObject( $user, &$code, $context ) {
global $wgULSAnonCanChangeLanguage, $wgULSLanguageDetection; if ( $this->config->get( 'ULSLanguageDetection' ) ) {
if ( $wgULSLanguageDetection ) {
// Vary any caching based on the header value. Note that // Vary any caching based on the header value. Note that
// we need to vary regardless of whether we end up using // we need to vary regardless of whether we end up using
// the header or not, so that requests without the header // the header or not, so that requests without the header
@@ -291,7 +329,7 @@ class UniversalLanguageSelectorHooks {
$context->getOutput()->addVaryHeader( 'Accept-Language' ); $context->getOutput()->addVaryHeader( 'Accept-Language' );
} }
if ( !self::isEnabled() ) { if ( !$this->isEnabled() ) {
return; return;
} }
@@ -307,10 +345,10 @@ class UniversalLanguageSelectorHooks {
} }
// If using cookie storage for anons is OK, read from that // If using cookie storage for anons is OK, read from that
if ( $wgULSAnonCanChangeLanguage ) { if ( $this->config->get( 'ULSAnonCanChangeLanguage' ) ) {
// Try to set the language based on the cookie // Try to set the language based on the cookie
$languageToUse = $request->getCookie( 'language', null, '' ); $languageToUse = $request->getCookie( 'language', null, '' );
if ( Language::isSupportedLanguage( $languageToUse ) ) { if ( $this->languageNameUtils->isSupportedLanguage( $languageToUse ) ) {
$code = $languageToUse; $code = $languageToUse;
return; return;
@@ -318,11 +356,11 @@ class UniversalLanguageSelectorHooks {
} }
// As last resort, try Accept-Language headers if allowed // As last resort, try Accept-Language headers if allowed
if ( $wgULSLanguageDetection ) { if ( $this->config->get( 'ULSLanguageDetection' ) ) {
// We added a Vary header at the top of this function, // We added a Vary header at the top of this function,
// since we're depending upon the Accept-Language header // since we're depending upon the Accept-Language header
$preferred = $request->getAcceptLang(); $preferred = $request->getAcceptLang();
$default = self::getDefaultLanguage( $preferred ); $default = $this->getDefaultLanguage( $preferred );
if ( $default !== '' ) { if ( $default !== '' ) {
$code = $default; $code = $default;
} }
@@ -333,42 +371,36 @@ class UniversalLanguageSelectorHooks {
* Hook: ResourceLoaderGetConfigVars * Hook: ResourceLoaderGetConfigVars
* @param array &$vars * @param array &$vars
* @param string $skin * @param string $skin
* @param Config $config
*/ */
public static function addConfig( array &$vars, $skin ) { public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
global $wgULSGeoService,
$wgULSIMEEnabled, $wgULSWebfontsEnabled,
$wgULSNoWebfontsSelectors,
$wgULSAnonCanChangeLanguage,
$wgULSImeSelectors, $wgULSNoImeSelectors,
$wgULSFontRepositoryBasePath,
$wgExtensionAssetsPath,
$wgInterwikiSortingSortPrepend;
$extRegistry = ExtensionRegistry::getInstance(); $extRegistry = ExtensionRegistry::getInstance();
$skinConfig = $extRegistry->getAttribute( 'UniversalLanguageSelectorSkinConfig' )[ $skin ] ?? []; $skinConfig = $extRegistry->getAttribute( 'UniversalLanguageSelectorSkinConfig' )[ $skin ] ?? [];
// Place constant stuff here (not depending on request context) // Place constant stuff here (not depending on request context)
if ( is_string( $wgULSGeoService ) ) { if ( is_string( $config->get( 'ULSGeoService' ) ) ) {
$vars['wgULSGeoService'] = $wgULSGeoService; $vars['wgULSGeoService'] = $config->get( 'ULSGeoService' );
} }
$vars['wgULSIMEEnabled'] = $wgULSIMEEnabled; $vars['wgULSIMEEnabled'] = $config->get( 'ULSIMEEnabled' );
$vars['wgULSWebfontsEnabled'] = $wgULSWebfontsEnabled; $vars['wgULSWebfontsEnabled'] = $config->get( 'ULSWebfontsEnabled' );
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage; $vars['wgULSAnonCanChangeLanguage'] = $config->get( 'ULSAnonCanChangeLanguage' );
$vars['wgULSImeSelectors'] = $wgULSImeSelectors; $vars['wgULSImeSelectors'] = $config->get( 'ULSImeSelectors' );
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors; $vars['wgULSNoImeSelectors'] = $config->get( 'ULSNoImeSelectors' );
$vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors; $vars['wgULSNoWebfontsSelectors'] = $config->get( 'ULSNoWebfontsSelectors' );
$vars['wgULSDisplaySettingsInInterlanguage'] = $skinConfig['ULSDisplaySettingsInInterlanguage'] ?? false; $vars['wgULSDisplaySettingsInInterlanguage'] = $skinConfig['ULSDisplaySettingsInInterlanguage'] ?? false;
if ( is_string( $wgULSFontRepositoryBasePath ) ) { if ( is_string( $config->get( 'ULSFontRepositoryBasePath' ) ) ) {
$vars['wgULSFontRepositoryBasePath'] = $wgULSFontRepositoryBasePath; $vars['wgULSFontRepositoryBasePath'] = $config->get( 'ULSFontRepositoryBasePath' );
} else { } else {
$vars['wgULSFontRepositoryBasePath'] = $wgExtensionAssetsPath . $vars['wgULSFontRepositoryBasePath'] = $config->get( 'ExtensionAssetsPath' ) .
'/UniversalLanguageSelector/data/fontrepo/fonts/'; '/UniversalLanguageSelector/data/fontrepo/fonts/';
} }
if ( isset( $wgInterwikiSortingSortPrepend ) && $wgInterwikiSortingSortPrepend !== [] ) { if ( $config->has( 'InterwikiSortingSortPrepend' ) &&
$vars['wgULSCompactLinksPrepend'] = $wgInterwikiSortingSortPrepend; $config->get( 'InterwikiSortingSortPrepend' ) !== []
) {
$vars['wgULSCompactLinksPrepend'] = $config->get( 'InterwikiSortingSortPrepend' );
} }
} }
@@ -377,7 +409,7 @@ class UniversalLanguageSelectorHooks {
* @param array &$vars * @param array &$vars
* @param OutputPage $out * @param OutputPage $out
*/ */
public static function addVariables( array &$vars, OutputPage $out ) { public function onMakeGlobalVariablesScript( &$vars, $out ): void {
// Place request context dependent stuff here // Place request context dependent stuff here
$user = $out->getUser(); $user = $out->getUser();
$loggedIn = $user->isRegistered(); $loggedIn = $user->isRegistered();
@@ -400,19 +432,17 @@ class UniversalLanguageSelectorHooks {
// An optimization to avoid loading all of uls.data just to get the autonym // An optimization to avoid loading all of uls.data just to get the autonym
$langCode = $out->getLanguage()->getCode(); $langCode = $out->getLanguage()->getCode();
$vars['wgULSCurrentAutonym'] = Language::fetchLanguageName( $langCode ); $vars['wgULSCurrentAutonym'] = $this->languageNameUtils->getLanguageName( $langCode );
$setLangCode = self::getSetLang( $out ); $setLangCode = $this->getSetLang( $out );
if ( $setLangCode ) { if ( $setLangCode ) {
$vars['wgULSCurrentLangCode'] = $langCode; $vars['wgULSCurrentLangCode'] = $langCode;
$vars['wgULSSetLangCode'] = $setLangCode; $vars['wgULSSetLangCode'] = $setLangCode;
$vars['wgULSSetLangName'] = Language::fetchLanguageName( $setLangCode ); $vars['wgULSSetLangName'] = $this->languageNameUtils->getLanguageName( $setLangCode );
} }
} }
public static function onGetPreferences( $user, array &$preferences ) { public function onGetPreferences( $user, &$preferences ) {
global $wgULSCompactLanguageLinksBetaFeature;
// T259037: Does not work well on Minerva // T259037: Does not work well on Minerva
$skin = RequestContext::getMain()->getSkin(); $skin = RequestContext::getMain()->getSkin();
if ( $skin->getSkinName() === 'minerva' ) { if ( $skin->getSkinName() === 'minerva' ) {
@@ -434,7 +464,7 @@ class UniversalLanguageSelectorHooks {
wfMessage( 'ext-uls-language-settings-preferences-link' )->escaped() . "</a>", wfMessage( 'ext-uls-language-settings-preferences-link' )->escaped() . "</a>",
]; ];
if ( $wgULSCompactLanguageLinksBetaFeature === false ) { if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === false ) {
$preferences['compact-language-links'] = [ $preferences['compact-language-links'] = [
'type' => 'check', 'type' => 'check',
'section' => 'rendering/languages', 'section' => 'rendering/languages',
@@ -446,15 +476,13 @@ class UniversalLanguageSelectorHooks {
} }
} }
public static function onGetBetaFeaturePreferences( $user, array &$prefs ) { public function onGetBetaFeaturePreferences( $user, array &$prefs ) {
global $wgExtensionAssetsPath, $wgULSCompactLanguageLinksBetaFeature, if ( $this->config->get( 'ULSCompactLanguageLinksBetaFeature' ) === true &&
$wgHideInterlanguageLinks, $wgInterwikiMagic; $this->config->get( 'InterwikiMagic' ) === true &&
$this->config->get( 'HideInterlanguageLinks' ) === false
if ( $wgULSCompactLanguageLinksBetaFeature === true &&
$wgInterwikiMagic === true &&
$wgHideInterlanguageLinks === false
) { ) {
$imagesDir = "$wgExtensionAssetsPath/UniversalLanguageSelector/resources/images"; $extensionAssetsPath = $this->config->get( 'ExtensionAssetsPath' );
$imagesDir = "$extensionAssetsPath/UniversalLanguageSelector/resources/images";
$prefs['uls-compact-links'] = [ $prefs['uls-compact-links'] = [
'label-message' => 'uls-betafeature-label', 'label-message' => 'uls-betafeature-label',
'desc-message' => 'uls-betafeature-desc', 'desc-message' => 'uls-betafeature-desc',
@@ -476,22 +504,16 @@ class UniversalLanguageSelectorHooks {
* @param string $name * @param string $name
* @param string &$content * @param string &$content
*/ */
public static function onSkinAfterPortlet( public function onSkinAfterPortlet( $skin, $name, &$content ) {
Skin $skin,
string $name,
string &$content
) {
global $wgULSPosition;
if ( $name !== 'lang' ) { if ( $name !== 'lang' ) {
return; return;
} }
if ( $wgULSPosition !== 'interlanguage' ) { if ( $this->config->get( 'ULSPosition' ) !== 'interlanguage' ) {
return; return;
} }
if ( !self::isEnabled() ) { if ( !$this->isEnabled() ) {
return; return;
} }
@@ -514,18 +536,19 @@ class UniversalLanguageSelectorHooks {
* Hook: EnterMobileMode * Hook: EnterMobileMode
* @param MobileContext $context * @param MobileContext $context
*/ */
public static function onEnterMobileMode( MobileContext $context ) { public function onEnterMobileMode( MobileContext $context ) {
global $wgULSEnable, $wgULSMobileWebfontsEnabled;
// Currently only supported in mobile Beta mode // Currently only supported in mobile Beta mode
if ( $wgULSEnable && $wgULSMobileWebfontsEnabled && $context->isBetaGroupMember() ) { if ( $this->config->get( 'ULSEnable' ) &&
$this->config->get( 'ULSMobileWebfontsEnabled' ) &&
$context->isBetaGroupMember()
) {
$context->getOutput()->addModules( 'ext.uls.webfonts.mobile' ); $context->getOutput()->addModules( 'ext.uls.webfonts.mobile' );
} }
} }
private static function getSetLang( OutputPage $out ): ?string { private function getSetLang( OutputPage $out ): ?string {
$setLangCode = $out->getRequest()->getText( 'setlang' ); $setLangCode = $out->getRequest()->getText( 'setlang' );
if ( $setLangCode && Language::isSupportedLanguage( $setLangCode ) ) { if ( $setLangCode && $this->languageNameUtils->isSupportedLanguage( $setLangCode ) ) {
return $setLangCode; return $setLangCode;
} }