diff --git a/includes/UniversalLanguageSelectorHooks.php b/includes/UniversalLanguageSelectorHooks.php index 62bf4746..73d6b4a3 100644 --- a/includes/UniversalLanguageSelectorHooks.php +++ b/includes/UniversalLanguageSelectorHooks.php @@ -102,15 +102,24 @@ class UniversalLanguageSelectorHooks { if ( in_array( $skin->getSkinName(), $unsupportedSkins ) ) { return; } - // Soft dependency to Wikibase client. Don't enable CLL if links are managed manually. $excludedLinks = $out->getProperty( 'noexternallanglinks' ); $override = is_array( $excludedLinks ) && in_array( '*', $excludedLinks ); $config = [ 'wgULSPosition' => $wgULSPosition, - 'wgULSCompactLinksEnabled' => !$override && self::isCompactLinksEnabled( $out->getUser() ), ]; + // Load compact links if no mw-interlanguage-selector element is present in the page HTML. + // We use the same mechanism as Skin::getDefaultModules and check the HTML for the presence in the HTML, + // using the class as the heuristic. + // Note if the element is rendered by the skin, its assumed that no collapsing is needed. + // See T264824 for more information. + if ( !$override && self::isCompactLinksEnabled( $out->getUser() ) && + strpos( $out->getHTML(), 'mw-interlanguage-selector' ) === false + ) { + $out->addModules( 'ext.uls.compactlinks' ); + } + if ( is_string( $wgULSGeoService ) ) { $out->addModules( 'ext.uls.geoclient' ); } diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 3cd82d75..04009a22 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -443,23 +443,6 @@ } ); } - /** - * Compact the language list if necessary - */ - function compactLanguageLinksList() { - if ( - // Allow skins to register their own button, in which case no need to compact - !document.querySelector( '.mw-interlanguage-selector' ) && ( - // This line is for cached HTML where the JS config variable is not available - // it can be removed a week after this code has been in production. - mw.loader.getState( 'ext.uls.compactlinks' ) !== 'registered' || - mw.config.get( 'wgULSCompactLinksEnabled' ) - ) - ) { - mw.loader.using( 'ext.uls.compactlinks' ); - } - } - /** * Event handler for the language button * @param {jQuery.Event} ev @@ -494,7 +477,6 @@ initInterface(); initTooltip(); initIme(); - compactLanguageLinksList(); initInterlanguageSelector(); }