Return target of redirect languages in mw.uls.getFrequentLanguageList

When mw.uls.getFrequentLanguageList() is requested sometimes
the language that is a redirect returned causing other codebases (like Wikibase)
to show an invalid language to the user.

Bug: T217770
Change-Id: I49c802d584081aa5992dd0ba76144059bcac56c8
This commit is contained in:
Amir Sarabadani
2019-07-15 16:11:33 +02:00
committed by jenkins-bot
parent cc4c09ed67
commit 76551ed4a7
2 changed files with 36 additions and 1 deletions

View File

@@ -180,7 +180,7 @@
* @return {Array} List of language codes without duplicates.
*/
mw.uls.getFrequentLanguageList = function ( countryCode ) {
var i, j, lang,
var i, j, lang, target,
ret = [],
lists = [
[
@@ -200,6 +200,11 @@
for ( i = 0; i < lists.length; i++ ) {
for ( j = 0; j < lists[ i ].length; j++ ) {
lang = lists[ i ][ j ];
target = $.uls.data.isRedirect( lang );
if ( target ) {
lang = target;
}
// Make flat, make unique, and ignore unknown/unsupported languages
if ( ret.indexOf( lang ) === -1 && $.uls.data.getAutonym( lang ) !== lang ) {
ret.push( lang );