Show languages from the Babel box on the user page
Bug: T135371 Change-Id: Ieeaf446326be93a779df3e6bd7a8dca899950a6c
This commit is contained in:
@@ -350,11 +350,25 @@ class UniversalLanguageSelectorHooks {
|
|||||||
|
|
||||||
// Place request context dependent stuff here
|
// Place request context dependent stuff here
|
||||||
|
|
||||||
|
$user = $out->getUser();
|
||||||
|
$loggedIn = $user->isLoggedIn();
|
||||||
|
|
||||||
// Do not output accept languages if there is risk it will get cached accross requests
|
// Do not output accept languages if there is risk it will get cached accross requests
|
||||||
if ( $wgULSAnonCanChangeLanguage || $out->getUser()->isLoggedIn() ) {
|
if ( $wgULSAnonCanChangeLanguage || $loggedIn ) {
|
||||||
$vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() );
|
$vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $loggedIn && class_exists( Babel::class ) ) {
|
||||||
|
$userLanguageInfo = Babel::getCachedUserLanguageInfo( $user );
|
||||||
|
|
||||||
|
// This relies on the fact that Babel levels are 'N' and
|
||||||
|
// the digits 0 to 5 as strings, and that in reverse
|
||||||
|
// ASCII order they will be 'N', '5', '4', '3', '2', '1', '0'.
|
||||||
|
arsort( $userLanguageInfo );
|
||||||
|
|
||||||
|
$vars['wgULSBabelLanguages'] = array_keys( $userLanguageInfo );
|
||||||
|
}
|
||||||
|
|
||||||
// An optimization to avoid loading all of uls.data just to get the autonym
|
// An optimization to avoid loading all of uls.data just to get the autonym
|
||||||
$langCode = $out->getLanguage()->getCode();
|
$langCode = $out->getLanguage()->getCode();
|
||||||
$vars['wgULSCurrentAutonym'] = Language::fetchLanguageName( $langCode );
|
$vars['wgULSCurrentAutonym'] = Language::fetchLanguageName( $langCode );
|
||||||
|
|||||||
@@ -247,6 +247,8 @@
|
|||||||
// Previous languages are always the better suggestion
|
// Previous languages are always the better suggestion
|
||||||
// because the user has explicitly chosen them.
|
// because the user has explicitly chosen them.
|
||||||
filterByPreviousLanguages,
|
filterByPreviousLanguages,
|
||||||
|
// User's languages in the Babel box on the user page
|
||||||
|
filterByBabelLanguages,
|
||||||
// Site specific highlights, mostly used on Wikimedia sites
|
// Site specific highlights, mostly used on Wikimedia sites
|
||||||
filterBySitePicks,
|
filterBySitePicks,
|
||||||
// Add all common languages to the beginning of array.
|
// Add all common languages to the beginning of array.
|
||||||
@@ -305,6 +307,20 @@
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter by languages that appear in the Babel box on the user page.
|
||||||
|
*
|
||||||
|
* @param {string[]} languages Language codes
|
||||||
|
* @return {string[]} List of language codes supported by the article
|
||||||
|
*/
|
||||||
|
function filterByBabelLanguages( languages ) {
|
||||||
|
var babelLanguages = mw.config.get( 'wgULSBabelLanguages', [] );
|
||||||
|
|
||||||
|
return $.grep( babelLanguages, function ( language ) {
|
||||||
|
return $.inArray( language, languages ) >= 0;
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the language list by site picks.
|
* Filter the language list by site picks.
|
||||||
*
|
*
|
||||||
@@ -312,7 +328,7 @@
|
|||||||
* @return {string[]} List of language codes supported by the article
|
* @return {string[]} List of language codes supported by the article
|
||||||
*/
|
*/
|
||||||
function filterBySitePicks( languages ) {
|
function filterBySitePicks( languages ) {
|
||||||
var picks = mw.config.get( 'wgULSCompactLinksPrepend' ) || [];
|
var picks = mw.config.get( 'wgULSCompactLinksPrepend', [] );
|
||||||
|
|
||||||
return $.grep( picks, function ( language ) {
|
return $.grep( picks, function ( language ) {
|
||||||
return $.inArray( language, languages ) >= 0;
|
return $.inArray( language, languages ) >= 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user