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
This commit is contained in:
Niklas Laxström
2013-04-26 12:40:40 +00:00
committed by Amir E. Aharoni
parent 7416740f95
commit 60242e2c53
5 changed files with 29 additions and 9 deletions

View File

@@ -68,7 +68,6 @@ $wgResourceModules['ext.uls.interface'] = array(
'jquery.tipsy',
'ext.uls.displaysettings',
'ext.uls.inputsettings',
'ext.uls.geoclient',
),
'position' => 'top',
) + $resourcePaths;

View File

@@ -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;

View File

@@ -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( '<script src="//bits.wikimedia.org/geoiplookup"></script>' );
return true;
};
}
return true;
};
require( "$dir/Resources.php" );

View File

@@ -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' );

View File

@@ -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' );
};