jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/309827 )

Change subject: Show languages from the Babel box on the user page
......................................................................


Show languages from the Babel box on the user page

Bug: T135371
Change-Id: Ieeaf446326be93a779df3e6bd7a8dca899950a6c
---
M UniversalLanguageSelector.hooks.php
M resources/js/ext.uls.compactlinks.js
2 files changed, 32 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Nikerabbit: Looks good to me, approved



diff --git a/UniversalLanguageSelector.hooks.php 
b/UniversalLanguageSelector.hooks.php
index 460d929..989d647 100644
--- a/UniversalLanguageSelector.hooks.php
+++ b/UniversalLanguageSelector.hooks.php
@@ -350,11 +350,25 @@
 
                // 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
-               if ( $wgULSAnonCanChangeLanguage || 
$out->getUser()->isLoggedIn() ) {
+               if ( $wgULSAnonCanChangeLanguage || $loggedIn ) {
                        $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
                $langCode = $out->getLanguage()->getCode();
                $vars['wgULSCurrentAutonym'] = Language::fetchLanguageName( 
$langCode );
diff --git a/resources/js/ext.uls.compactlinks.js 
b/resources/js/ext.uls.compactlinks.js
index 69e23c0..f292194 100644
--- a/resources/js/ext.uls.compactlinks.js
+++ b/resources/js/ext.uls.compactlinks.js
@@ -247,6 +247,8 @@
                        // Previous languages are always the better suggestion
                        // because the user has explicitly chosen them.
                        filterByPreviousLanguages,
+                       // User's languages in the Babel box on the user page
+                       filterByBabelLanguages,
                        // Site specific highlights, mostly used on Wikimedia 
sites
                        filterBySitePicks,
                        // Add all common languages to the beginning of array.
@@ -306,13 +308,27 @@
        }
 
        /**
+        * 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.
         *
         * @param {string[]} languages Language codes
         * @return {string[]} List of language codes supported by the article
         */
        function filterBySitePicks( languages ) {
-               var picks = mw.config.get( 'wgULSCompactLinksPrepend' ) || [];
+               var picks = mw.config.get( 'wgULSCompactLinksPrepend', [] );
 
                return $.grep( picks, function ( language ) {
                        return $.inArray( language, languages ) >= 0;

-- 
To view, visit https://gerrit.wikimedia.org/r/309827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieeaf446326be93a779df3e6bd7a8dca899950a6c
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Fomafix <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to