Compact language links module is loaded via server side

This provides an alternative mechanism to
I0518ecdf402ebf5eb6bad2c430f6462322c0d8e1 for loading the compact
language link module. Instead of relying on the client, the HTML
is inspected.

Bug: T264824
Change-Id: I977a998388b3e70f7fe4d97fa05be3c1ac1bf676
This commit is contained in:
jdlrobson
2020-11-16 11:02:50 -08:00
committed by jenkins-bot
parent ab6decae11
commit d69d5773e5
2 changed files with 11 additions and 20 deletions

View File

@@ -102,15 +102,24 @@ class UniversalLanguageSelectorHooks {
if ( in_array( $skin->getSkinName(), $unsupportedSkins ) ) { if ( in_array( $skin->getSkinName(), $unsupportedSkins ) ) {
return; return;
} }
// Soft dependency to Wikibase client. Don't enable CLL if links are managed manually. // Soft dependency to Wikibase client. Don't enable CLL if links are managed manually.
$excludedLinks = $out->getProperty( 'noexternallanglinks' ); $excludedLinks = $out->getProperty( 'noexternallanglinks' );
$override = is_array( $excludedLinks ) && in_array( '*', $excludedLinks ); $override = is_array( $excludedLinks ) && in_array( '*', $excludedLinks );
$config = [ $config = [
'wgULSPosition' => $wgULSPosition, '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 ) ) { if ( is_string( $wgULSGeoService ) ) {
$out->addModules( 'ext.uls.geoclient' ); $out->addModules( 'ext.uls.geoclient' );
} }

View File

@@ -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 * Event handler for the language button
* @param {jQuery.Event} ev * @param {jQuery.Event} ev
@@ -494,7 +477,6 @@
initInterface(); initInterface();
initTooltip(); initTooltip();
initIme(); initIme();
compactLanguageLinksList();
initInterlanguageSelector(); initInterlanguageSelector();
} }