[MediaWiki-commits] [Gerrit] Introduce a config variable to enable Compact language links... - change (mediawiki...UniversalLanguageSelector)
jenkins-bot has submitted this change and it was merged. Change subject: Introduce a config variable to enable Compact language links by default .. Introduce a config variable to enable Compact language links by default Configuration: ULSCompactLanguageLinksBetaFeature Default value: True Bug: T134145 Change-Id: I8d4e97653daf7fcee9175c6d7cefb5c5abb22305 --- M UniversalLanguageSelector.hooks.php M extension.json 2 files changed, 47 insertions(+), 13 deletions(-) Approvals: Nikerabbit: Checked; Looks good to me, approved jenkins-bot: Verified diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 6152011..1544878 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -44,14 +44,51 @@ } /** +* 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 * @return bool * 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 @@ // 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 @@ } 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"; diff --git a/extension.json b/extension.json index 731ad10..54988e2 100644 --- a/extension.json +++ b/extension.json @@ -53,7 +53,7 @@ "config": { "@ULSGeoService": "ULS can use geolocation services to suggest languages based on the country the user is vising from. Setting this to false will prevent builtin geolocation from being used. You can provide your own geolocation by setting window.Geo to object which has key \"country_code\" or \"country\". If set to true, it will query Wikimedia's geoip service. The service should return jsonp that uses the supplied callback parameter.", "ULSGeoService": true, -
[MediaWiki-commits] [Gerrit] Introduce a config variable to enable Compact language links... - change (mediawiki...UniversalLanguageSelector)
Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/285902 Change subject: Introduce a config variable to enable Compact language links by default .. Introduce a config variable to enable Compact language links by default Configuration: ULSCompactLanguageLinksBetaFeature Default value: True Change-Id: I8d4e97653daf7fcee9175c6d7cefb5c5abb22305 --- M UniversalLanguageSelector.hooks.php M extension.json 2 files changed, 45 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/02/285902/1 diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 6152011..7ce5885 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -44,14 +44,50 @@ } /** +* Whether ULS Compact interlanguage links enabled +* +* @param User $user +* @return bool +*/ + public static function isCompactLinksEnabled( $user ) { + global $wgULSEnable, $wgULSEnableAnon, $wgInterwikiMagic, + $wgHideInterlanguageLinks, $wgULSCompactLanguageLinksBetaFeature; + + 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 * @return bool * 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 +104,7 @@ // 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 +357,11 @@ } 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"; diff --git a/extension.json b/extension.json index 7596576..3655e26 100644 --- a/extension.json +++ b/extension.json @@ -88,7 +88,9 @@ "#p-lang li.interlanguage-link > a" ], "@ULSFontRepositoryBasePath": "Base path of ULS font repository. If not set, will be set to 'UniversalLanguageSelector/data/fontrepo/fonts/', relative to $wgExtensionAssetsPath. @since 2013.10", - "ULSFontRepositoryBasePath": false + "ULSFontRepositoryBasePath": false, + "ULSCompactLanguageLinksBetaFeature": true, + "@ULSCompactLanguageLinksBetaFeature": "Set compact interlanguage li