Switch default ULS geoip provider
Current provider is going away. Switching to another free provider. Implemented caching with a cookie for speed and to avoid generating unnecessary load on the service. Bug: T143542 Change-Id: I191d69a6fb8abe9556f475dfef1368dc9f96b846
This commit is contained in:
@@ -121,10 +121,8 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$out->addModules( 'ext.uls.compactlinks' );
|
$out->addModules( 'ext.uls.compactlinks' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_string( $wgULSGeoService ) ) {
|
if ( $wgULSGeoService ) {
|
||||||
$out->addModules( 'ext.uls.geoclient' );
|
$out->addModules( 'ext.uls.geoclient' );
|
||||||
} elseif ( $wgULSGeoService === true ) {
|
|
||||||
$out->addScript( '<script src="//meta.wikimedia.org/geoiplookup"></script>' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self::isToolbarEnabled( $out->getUser() ) ) {
|
if ( self::isToolbarEnabled( $out->getUser() ) ) {
|
||||||
@@ -312,7 +310,11 @@ class UniversalLanguageSelectorHooks {
|
|||||||
$wgWBClientSettings;
|
$wgWBClientSettings;
|
||||||
|
|
||||||
// Place constant stuff here (not depending on request context)
|
// Place constant stuff here (not depending on request context)
|
||||||
if ( is_string( $wgULSGeoService ) ) {
|
|
||||||
|
if ( $wgULSGeoService === true ) {
|
||||||
|
$wgULSGeoService = 'https://freegeoip.net/json/?callback=?';
|
||||||
|
}
|
||||||
|
if ( $wgULSGeoService ) {
|
||||||
$vars['wgULSGeoService'] = $wgULSGeoService;
|
$vars['wgULSGeoService'] = $wgULSGeoService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
"compact-language-links": true
|
"compact-language-links": true
|
||||||
},
|
},
|
||||||
"config": {
|
"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": "ULS can use a geolocation service to suggest languages based on the country the user is vising from. If set to true, it will query a free geoip service. Setting this to false will prevent built-in geolocation from being used. You can provide your own geolocation by setting window.Geo to an object which has key \"country_code\" or \"country\".",
|
||||||
"ULSGeoService": true,
|
"ULSGeoService": true,
|
||||||
"@ULSEnable": "Enable language selection, compact language links, input methods and webfonts for everyone, unless the behavior is overridden by the configuration variables below. Even if false the classes and resource loader modules are registered for the use of other extensions. Language changing via cookie or setlang query parameter is not possible.",
|
"@ULSEnable": "Enable language selection, compact language links, input methods and webfonts for everyone, unless the behavior is overridden by the configuration variables below. Even if false the classes and resource loader modules are registered for the use of other extensions. Language changing via cookie or setlang query parameter is not possible.",
|
||||||
"ULSEnable": true,
|
"ULSEnable": true,
|
||||||
@@ -129,6 +129,10 @@
|
|||||||
},
|
},
|
||||||
"ext.uls.geoclient": {
|
"ext.uls.geoclient": {
|
||||||
"scripts": "js/ext.uls.geoclient.js",
|
"scripts": "js/ext.uls.geoclient.js",
|
||||||
|
"dependencies": [
|
||||||
|
"json",
|
||||||
|
"mediawiki.cookie"
|
||||||
|
],
|
||||||
"localBasePath": "resources",
|
"localBasePath": "resources",
|
||||||
"remoteExtPath": "UniversalLanguageSelector/resources"
|
"remoteExtPath": "UniversalLanguageSelector/resources"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,29 +20,29 @@
|
|||||||
( function ( $, mw ) {
|
( function ( $, mw ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var currentProto, httpOnly, settings,
|
var geo,
|
||||||
|
cacheAge = 60 * 60 * 8, // 8 hours
|
||||||
service = mw.config.get( 'wgULSGeoService' );
|
service = mw.config.get( 'wgULSGeoService' );
|
||||||
|
|
||||||
mw.uls = mw.uls || {};
|
// This is not supposed to happen. For sanity prefer existing value.
|
||||||
mw.uls.setGeo = function ( data ) {
|
if ( window.Geo ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using cache for speed and to be nice for the service. Using cookies over
|
||||||
|
// localstorage because cookies support automatic expiring and are supported
|
||||||
|
// everywhere where as localstorage might not. This cookie is not currently
|
||||||
|
// read server side.
|
||||||
|
geo = mw.cookie.get( 'ULSGeo' );
|
||||||
|
if ( geo ) {
|
||||||
|
try {
|
||||||
|
window.Geo = JSON.parse( geo );
|
||||||
|
return;
|
||||||
|
} catch ( e ) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
$.getJSON( service ).done( function ( data ) {
|
||||||
window.Geo = data;
|
window.Geo = data;
|
||||||
};
|
mw.cookie.set( 'ULSGeo', JSON.stringify( data ), cacheAge );
|
||||||
|
} );
|
||||||
// Call the service only if defined, and if the current
|
|
||||||
// protocol is https, only if the service is not configured
|
|
||||||
// with http:// as the protocol
|
|
||||||
if ( service ) {
|
|
||||||
httpOnly = service.substring( 0, 7 ) === 'http://';
|
|
||||||
currentProto = document.location.protocol;
|
|
||||||
if ( !httpOnly || currentProto === 'http:' ) {
|
|
||||||
settings = {
|
|
||||||
cache: true,
|
|
||||||
dataType: 'jsonp',
|
|
||||||
jsonpCallback: 'mw.uls.setGeo'
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax( service, settings );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}( jQuery, mediaWiki ) );
|
}( jQuery, mediaWiki ) );
|
||||||
|
|||||||
Reference in New Issue
Block a user