Allow loading redirects in Common languages

Bug: 49847
Change-Id: Ia2380a77ebad789a2f70a7a88a1bb9970199b1c5
This commit is contained in:
Amir E. Aharoni
2013-06-19 17:00:59 -07:00
committed by Niklas Laxström
parent 20033e4fbf
commit b6698228d4
2 changed files with 55 additions and 5 deletions

View File

@@ -75,9 +75,20 @@
return mw.config.get( 'wgULSAcceptLanguageList' ); return mw.config.get( 'wgULSAcceptLanguageList' );
}; };
mw.uls.getFrequentLanguageList = function () { /**
var countryCode, * Get a list of codes for languages to show in
unique = [], * the "Common languages" section of the ULS.
* The list consists of the user's current selected language,
* the wiki's content language, the browser' UI language
* and Accept-Language, user's previous selected languages
* and finally, the languages of countryCode taken from the CLDR,
* taken by default from the user's geolocation.
*
* @param {String} [countryCode] Uppercase country code.
* @return {Array} List of language codes without duplicates.
*/
mw.uls.getFrequentLanguageList = function ( countryCode ) {
var unique = [],
list = [ list = [
mw.config.get( 'wgUserLanguage' ), mw.config.get( 'wgUserLanguage' ),
mw.config.get( 'wgContentLanguage' ), mw.config.get( 'wgContentLanguage' ),
@@ -86,7 +97,7 @@
.concat( mw.uls.getPreviousLanguages() ) .concat( mw.uls.getPreviousLanguages() )
.concat( mw.uls.getAcceptLanguageList() ); .concat( mw.uls.getAcceptLanguageList() );
countryCode = mw.uls.getCountryCode(); countryCode = countryCode || mw.uls.getCountryCode();
if ( countryCode ) { if ( countryCode ) {
list = list.concat( $.uls.data.getLanguagesInTerritory( countryCode ) ); list = list.concat( $.uls.data.getLanguagesInTerritory( countryCode ) );
@@ -100,7 +111,24 @@
// Filter out unknown and unsupported languages // Filter out unknown and unsupported languages
unique = $.grep( unique, function ( langCode ) { unique = $.grep( unique, function ( langCode ) {
return $.fn.uls.defaults.languages[langCode]; var target;
// If the language is already known and defined, just use it
if ( $.fn.uls.defaults.languages[langCode] !== undefined ) {
return true;
}
// If the language is not immediately known,
// try to check is as a redirect
target = $.uls.data.isRedirect( langCode );
if ( target ) {
// Check that the redirect's target is known
// to this instance of ULS
return $.fn.uls.defaults.languages[target] !== undefined;
}
return false;
} ); } );
return unique; return unique;

View File

@@ -63,4 +63,26 @@
prefs.set( prefName, undefined ); prefs.set( prefName, undefined );
prefs.save(); prefs.save();
} ); } );
QUnit.test( '-- Common languages', 1, function ( assert ) {
var i, foundTagalog, languagesInPH;
// Bug 49847
foundTagalog = false;
languagesInPH = mw.uls.getFrequentLanguageList( 'PH' );
for ( i = 0; i < languagesInPH.length; i++ ) {
if ( $.uls.data.isRedirect( languagesInPH[i] ) === 'tl' ||
languagesInPH[i] === 'tl'
) {
foundTagalog = true;
break;
}
}
assert.ok(
foundTagalog,
'Tagalog is one of the languages presented to users in the Philippines.'
);
} );
}( jQuery, mediaWiki ) ); }( jQuery, mediaWiki ) );