Introduce a config variable to enable Compact language links by default

Configuration: ULSCompactLanguageLinksBetaFeature
Default value: True

Bug: T134145
Change-Id: I8d4e97653daf7fcee9175c6d7cefb5c5abb22305
This commit is contained in:
Santhosh Thottingal
2016-04-28 11:56:55 +05:30
committed by Nikerabbit
parent b871779a41
commit aa4e4b417d
2 changed files with 47 additions and 13 deletions

View File

@@ -43,6 +43,44 @@ class UniversalLanguageSelectorHooks {
return true;
}
/**
* Whether ULS Compact interlanguage links enabled
*
* @param User $user
* @return bool
*/
public static function isCompactLinksEnabled( $user ) {
global $wgULSEnable, $wgULSEnableAnon, $wgInterwikiMagic,
$wgHideInterlanguageLinks, $wgULSCompactLanguageLinksBetaFeature;
// Whether any user visible features are enabled
if ( !$wgULSEnable ) {
return false;
}
if ( !$wgULSEnableAnon && $user->isAnon() ) {
return false;
}
if ( $wgULSCompactLanguageLinksBetaFeature === true &&
$wgInterwikiMagic === true &&
$wgHideInterlanguageLinks === false &&
class_exists( 'BetaFeatures' ) &&
BetaFeatures::isFeatureEnabled( $user, 'uls-compact-links' )
) {
// Compact language links is a beta feature in this wiki. Check the user's
// preference.
return true;
}
if ( $wgULSCompactLanguageLinksBetaFeature === false ) {
// Compact language links is a default feature in this wiki.
return true;
}
return false;
}
/**
* @param OutputPage $out
* @param Skin $skin
@@ -50,8 +88,7 @@ class UniversalLanguageSelectorHooks {
* Hook: BeforePageDisplay
*/
public static function addModules( $out, $skin ) {
global $wgULSPosition, $wgULSGeoService, $wgULSEventLogging,
$wgInterwikiMagic, $wgHideInterlanguageLinks;
global $wgULSPosition, $wgULSGeoService, $wgULSEventLogging;
// Load the style for users without JS, to hide the useless links
$out->addModuleStyles( 'ext.uls.nojs' );
@@ -68,13 +105,7 @@ class UniversalLanguageSelectorHooks {
// If the extension is enabled, basic features (API, language data) available.
$out->addModules( 'ext.uls.init' );
// If compact ULS beta feature is enabled and is actually functional
// (see onGetBetaFeaturePreferences)
if ( $wgInterwikiMagic === true &&
$wgHideInterlanguageLinks === false &&
class_exists( 'BetaFeatures' ) &&
BetaFeatures::isFeatureEnabled( $out->getUser(), 'uls-compact-links' )
) {
if ( self::isCompactLinksEnabled( $out->getUser() ) ) {
$out->addModules( 'ext.uls.compactlinks' );
}
@@ -327,10 +358,11 @@ class UniversalLanguageSelectorHooks {
}
public static function onGetBetaFeaturePreferences( $user, &$prefs ) {
global $wgExtensionAssetsPath,
global $wgExtensionAssetsPath, $wgULSCompactLanguageLinksBetaFeature,
$wgHideInterlanguageLinks, $wgInterwikiMagic;
if ( $wgInterwikiMagic === true &&
if ( $wgULSCompactLanguageLinksBetaFeature === true &&
$wgInterwikiMagic === true &&
$wgHideInterlanguageLinks === false
) {
$imagesDir = "$wgExtensionAssetsPath/UniversalLanguageSelector/resources/images";