diff --git a/Resources.php b/Resources.php index dc58f010..f133fac7 100644 --- a/Resources.php +++ b/Resources.php @@ -68,7 +68,6 @@ $wgResourceModules['ext.uls.interface'] = array( 'jquery.tipsy', 'ext.uls.displaysettings', 'ext.uls.inputsettings', - 'ext.uls.geoclient', ), 'position' => 'top', ) + $resourcePaths; diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index ccde16a5..a4eae6e3 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -41,9 +41,15 @@ class UniversalLanguageSelectorHooks { * @return bool */ public static function addModules( $out, $skin ) { + global $wgULSGeoService; + // If extension is enabled, basic features(API, language data) available. $out->addModules( 'ext.uls.init' ); - $out->addModules( 'ext.uls.geoclient' ); + + if ( is_string( $wgULSGeoService ) ) { + $out->addModules( 'ext.uls.geoclient' ); + } + if ( self::isToolbarEnabled( $out->getUser() ) ) { // Enable UI language selection for the user. $out->addModules( 'ext.uls.interface' ); @@ -224,7 +230,9 @@ class UniversalLanguageSelectorHooks { $wgULSAnonCanChangeLanguage; // Place constant stuff here (not depending on request context) - $vars['wgULSGeoService'] = $wgULSGeoService; + if ( is_string( $wgULSGeoService ) ) { + $vars['wgULSGeoService'] = $wgULSGeoService; + } $vars['wgULSIMEEnabled'] = $wgULSIMEEnabled; $vars['wgULSPosition'] = $wgULSPosition; $vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage; diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index 1cb2c2e6..50cc714d 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -50,11 +50,11 @@ $wgExtensionCredits['other'][] = array( * 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'. - * This is what Wikipedia does. + * If set to true, it will query Wikimedia's geoip service. * * The service should return jsonp that uses the supplied callback parameter. */ -$wgULSGeoService = 'http://freegeoip.net/json/'; +$wgULSGeoService = true; /** * Enable language selection, input methods and webfonts for everyone, unless @@ -138,4 +138,17 @@ $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UniversalLanguageSelectorHooks $wgDefaultUserOptions['uls-preferences'] = ''; $wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences'; +$wgExtensionFunctions[] = function() { + global $wgHooks, $wgULSGeoService; + + if ( $wgULSGeoService === true ) { + $wgHooks['BeforePageDisplay'][] = function( &$out ) { + $out->addScript( '' ); + return true; + }; + } + + return true; +}; + require( "$dir/Resources.php" ); diff --git a/resources/js/ext.uls.geoclient.js b/resources/js/ext.uls.geoclient.js index a59667a2..3a66b0cb 100644 --- a/resources/js/ext.uls.geoclient.js +++ b/resources/js/ext.uls.geoclient.js @@ -25,10 +25,6 @@ window.Geo = data; }; - mw.uls.getCountryCode = function () { - return window.Geo && ( window.Geo.country || window.Geo.country_code ); - }; - var currentProto, httpOnly, settings, service = mw.config.get( 'wgULSGeoService' ); diff --git a/resources/js/ext.uls.init.js b/resources/js/ext.uls.init.js index b449c7a5..0bc16829 100644 --- a/resources/js/ext.uls.init.js +++ b/resources/js/ext.uls.init.js @@ -66,6 +66,10 @@ return ( window.navigator.language || window.navigator.userLanguage ).split( '-' )[0]; }; + mw.uls.getCountryCode = function () { + return window.Geo && ( window.Geo.country || window.Geo.country_code ); + }; + mw.uls.getAcceptLanguageList = function () { return mw.config.get( 'wgULSAcceptLanguageList' ); };