Initial version of geolocation support
Change-Id: Ia1a18ac336131520bbc67f52194f4aa9c547ea67
This commit is contained in:
committed by
Amir E. Aharoni
parent
fde6b18e40
commit
64c26ad137
@@ -27,7 +27,11 @@ 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' );
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +116,9 @@ class UniversalLanguageSelectorHooks {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function addConfig( &$vars ) {
|
public static function addConfig( &$vars ) {
|
||||||
global $wgContLang;
|
global $wgContLang, $wgULSGeoService;
|
||||||
$vars['wgULSLanguages'] = Language::fetchLanguageNames( $wgContLang->getCode(), 'mwfile' );
|
$vars['wgULSLanguages'] = Language::fetchLanguageNames( $wgContLang->getCode(), 'mwfile' );
|
||||||
|
$vars['wgULSGeoService'] = $wgULSGeoService;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
|
|||||||
/**
|
/**
|
||||||
* Version number used in extension credits and in other placed where needed.
|
* Version number used in extension credits and in other placed where needed.
|
||||||
*/
|
*/
|
||||||
define( 'ULS_VERSION', '2012-07-20' );
|
define( 'ULS_VERSION', '2012-08-30' );
|
||||||
|
|
||||||
$wgExtensionCredits['other'][] = array(
|
$wgExtensionCredits['other'][] = array(
|
||||||
'path' => __FILE__,
|
'path' => __FILE__,
|
||||||
@@ -45,6 +45,17 @@ $wgExtensionCredits['other'][] = array(
|
|||||||
'descriptionmsg' => 'uls-desc',
|
'descriptionmsg' => 'uls-desc',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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. This is what
|
||||||
|
* Wikipedia does.
|
||||||
|
*
|
||||||
|
* The service should return jsonp that uses the supplied callback parameter.
|
||||||
|
*/
|
||||||
|
$wgULSGeoService = 'http://freegeoip.net/json/';
|
||||||
|
|
||||||
$dir = __DIR__ ;
|
$dir = __DIR__ ;
|
||||||
|
|
||||||
// Internationalization
|
// Internationalization
|
||||||
@@ -77,6 +88,12 @@ $wgResourceModules['ext.uls.init'] = array(
|
|||||||
'position' => 'top',
|
'position' => 'top',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$wgResourceModules['ext.uls.geoclient'] = array(
|
||||||
|
'scripts' => 'resources/js/ext.uls.geoclient.js',
|
||||||
|
'localBasePath' => $dir,
|
||||||
|
'remoteExtPath' => 'UniversalLanguageSelector',
|
||||||
|
);
|
||||||
|
|
||||||
$wgResourceModules['ext.uls.preferences'] = array(
|
$wgResourceModules['ext.uls.preferences'] = array(
|
||||||
'scripts' => 'resources/js/ext.uls.preferences.js',
|
'scripts' => 'resources/js/ext.uls.preferences.js',
|
||||||
'localBasePath' => $dir,
|
'localBasePath' => $dir,
|
||||||
|
|||||||
@@ -335,7 +335,7 @@
|
|||||||
onSelect: null, // Callback function to be called when a language is selected
|
onSelect: null, // Callback function to be called when a language is selected
|
||||||
searchAPI: null, // Language search API
|
searchAPI: null, // Language search API
|
||||||
languages: $.uls.data.autonyms(), // Languages to be used for ULS, default is all languages
|
languages: $.uls.data.autonyms(), // Languages to be used for ULS, default is all languages
|
||||||
quickList : null
|
quickList: null // Array of language codes of function that returns such
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn.uls.Constructor = ULS;
|
$.fn.uls.Constructor = ULS;
|
||||||
|
|||||||
@@ -130,9 +130,14 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
quicklist: function() {
|
quicklist: function() {
|
||||||
|
if ( $.isFunction( this.options.quickList ) ) {
|
||||||
|
this.options.quickList = this.options.quickList();
|
||||||
|
}
|
||||||
|
|
||||||
if ( !this.options.quickList ) {
|
if ( !this.options.quickList ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $column;
|
var $column;
|
||||||
var quickList = this.options.quickList;
|
var quickList = this.options.quickList;
|
||||||
var quickListLength = ( quickList.length <= 16 ) ? quickList.length : 16;
|
var quickListLength = ( quickList.length <= 16 ) ? quickList.length : 16;
|
||||||
|
|||||||
14
resources/js/ext.uls.geoclient.js
Normal file
14
resources/js/ext.uls.geoclient.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
( function( mw, $ ) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
window.setGeo = function ( data ) {
|
||||||
|
window.GEO = data;
|
||||||
|
}
|
||||||
|
var settings = {
|
||||||
|
cache: true,
|
||||||
|
dataType: "jsonp",
|
||||||
|
jsonpCallback: "setGeo"
|
||||||
|
};
|
||||||
|
$.ajax( mw.config.get( 'wgULSGeoService' ), settings );
|
||||||
|
|
||||||
|
}( mediaWiki, jQuery ) );
|
||||||
@@ -101,12 +101,25 @@
|
|||||||
},
|
},
|
||||||
languages: mw.config.get( 'wgULSLanguages' ),
|
languages: mw.config.get( 'wgULSLanguages' ),
|
||||||
searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch",
|
searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch",
|
||||||
quickList : $.unique( [
|
quickList: function() {
|
||||||
|
var unique = [],
|
||||||
|
list = [
|
||||||
mw.config.get( 'wgUserLanguage' ),
|
mw.config.get( 'wgUserLanguage' ),
|
||||||
mw.config.get( 'wgContentLanguage' ),
|
mw.config.get( 'wgContentLanguage' ),
|
||||||
mw.uls.getBrowserLanguage()
|
mw.uls.getBrowserLanguage()
|
||||||
].concat( mw.uls.getPreviousLanguages() ) )
|
];
|
||||||
|
list = list.concat( mw.uls.getPreviousLanguages() );
|
||||||
|
if ( window.GEO ) {
|
||||||
|
console.log( $.uls.data.languagesInTerritory( window.GEO.country_code ) );
|
||||||
|
list = list.concat( $.uls.data.languagesInTerritory( window.GEO.country_code ) );
|
||||||
|
}
|
||||||
|
$.each( list, function ( i, v ) {
|
||||||
|
if ( $.inArray( v, unique ) === -1 ) {
|
||||||
|
unique.push( v );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
return unique;
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user