From 60242e2c530a85bb2e7425699a7b5a0c7a798997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Laxstr=C3=B6m?= Date: Fri, 26 Apr 2013 12:40:40 +0000 Subject: [PATCH] Use wmf geoip by default Unlike freegeoip it also works with https Also moved the getCountryCode function to init, as it should be available regardless of whether we load the optional geoclient module. Bug: 40965 Change-Id: Ia18130890d09f86a93b5b61f7da7c48fcfa480c7 --- Resources.php | 1 - UniversalLanguageSelector.hooks.php | 12 ++++++++++-- UniversalLanguageSelector.php | 17 +++++++++++++++-- resources/js/ext.uls.geoclient.js | 4 ---- resources/js/ext.uls.init.js | 4 ++++ 5 files changed, 29 insertions(+), 9 deletions(-) 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' ); };