Geoclient fixes for https and WMF
* Don't call freegeoip on https, it wont work * Use Geo instead of GEO like WMF Change-Id: I9ebdd9f3518e15e70122a9c8c8d64240d5e44c5b
This commit is contained in:
committed by
Gerrit Code Review
parent
8d5307852a
commit
3c9e7249a8
@@ -26,11 +26,8 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function addModules( $out, $skin ) {
|
public static function addModules( $out, $skin ) {
|
||||||
global $wgULSGeoService;
|
|
||||||
$out->addModules( 'ext.uls.init' );
|
$out->addModules( 'ext.uls.init' );
|
||||||
if ( $wgULSGeoService ) {
|
$out->addModules( 'ext.uls.geoclient' );
|
||||||
$out->addModules( 'ext.uls.geoclient' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ $wgExtensionCredits['other'][] = array(
|
|||||||
* ULS can use geolocation services to suggest languages based on the
|
* ULS can use geolocation services to suggest languages based on the
|
||||||
* country the user is vising from. Setting this to false will prevent
|
* country the user is vising from. Setting this to false will prevent
|
||||||
* builtin geolocation from being used. You can provide your own geolocation
|
* builtin geolocation from being used. You can provide your own geolocation
|
||||||
* by setting window.GEO to object which has key 'country_code' or 'country'.
|
* by setting window.Geo to object which has key 'country_code' or 'country'.
|
||||||
* This is what Wikipedia does.
|
* This is what Wikipedia does.
|
||||||
*
|
*
|
||||||
* The service should return jsonp that uses the supplied callback parameter.
|
* The service should return jsonp that uses the supplied callback parameter.
|
||||||
|
|||||||
@@ -22,19 +22,31 @@
|
|||||||
|
|
||||||
mw.uls = mw.uls || {};
|
mw.uls = mw.uls || {};
|
||||||
mw.uls.setGeo = function ( data ) {
|
mw.uls.setGeo = function ( data ) {
|
||||||
window.GEO = data;
|
window.Geo = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
mw.uls.getCountryCode = function () {
|
mw.uls.getCountryCode = function () {
|
||||||
/*jshint camelcase: false*/
|
return window.Geo && ( window.Geo.country || window.Geo.country_code );
|
||||||
return window.GEO && ( window.GEO.country || window.GEO.country_code );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var settings = {
|
var currentProto, httpOnly,
|
||||||
cache: true,
|
service = mw.config.get( 'wgULSGeoService' );
|
||||||
dataType: 'jsonp',
|
|
||||||
jsonpCallback: 'mw.uls.setGeo'
|
// Call the service only if defined, and if the current
|
||||||
};
|
// protocol is https, only if the service is not configured
|
||||||
$.ajax( mw.config.get( 'wgULSGeoService' ), settings );
|
// with http:// as the protocol
|
||||||
|
if ( service ) {
|
||||||
|
httpOnly = service.substring(0, 7) === 'http://';
|
||||||
|
currentProto = document.location.protocol;
|
||||||
|
if ( !httpOnly || currentProto === 'http:' ) {
|
||||||
|
var settings = {
|
||||||
|
cache: true,
|
||||||
|
dataType: 'jsonp',
|
||||||
|
jsonpCallback: 'mw.uls.setGeo'
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax( service, settings );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}( mediaWiki, jQuery ) );
|
}( mediaWiki, jQuery ) );
|
||||||
|
|||||||
@@ -63,7 +63,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
mw.uls.getFrequentLanguageList = function () {
|
mw.uls.getFrequentLanguageList = function () {
|
||||||
var unique = [],
|
var countryCode,
|
||||||
|
unique = [],
|
||||||
list = [
|
list = [
|
||||||
mw.config.get( 'wgUserLanguage' ),
|
mw.config.get( 'wgUserLanguage' ),
|
||||||
mw.config.get( 'wgContentLanguage' ),
|
mw.config.get( 'wgContentLanguage' ),
|
||||||
@@ -72,8 +73,9 @@
|
|||||||
.concat( mw.uls.getPreviousLanguages() )
|
.concat( mw.uls.getPreviousLanguages() )
|
||||||
.concat( mw.uls.getAcceptLanguageList() );
|
.concat( mw.uls.getAcceptLanguageList() );
|
||||||
|
|
||||||
if ( window.GEO ) {
|
countryCode = mw.uls.getCountryCode()
|
||||||
list = list.concat( $.uls.data.getLanguagesInTerritory( mw.uls.getCountryCode() ) );
|
if ( countryCode ) {
|
||||||
|
list = list.concat( $.uls.data.getLanguagesInTerritory( countryCode ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each( list, function ( i, v ) {
|
$.each( list, function ( i, v ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user