From 4bd38a0fcf98a15e529adf373a57f5485fbb494a Mon Sep 17 00:00:00 2001 From: Amire80 Date: Sat, 10 Sep 2016 17:03:11 +0300 Subject: [PATCH] Query only for elements that are interlanguage links targets Depends on the core change in 1.28, which adds the interlanguage-link-target class to the elements: I06c80945af785477be52096022c8493e7f82c298 Includes backwards compatibility code so that ULS compact links would be usable on core versions that don't have this change. Bug: T135378 Change-Id: I2909ce31e19087358d194e0e108e1ba038e7273e Depends-On: I06c80945af785477be52096022c8493e7f82c298 --- resources/js/ext.uls.compactlinks.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/resources/js/ext.uls.compactlinks.js b/resources/js/ext.uls.compactlinks.js index 4faaf03a..4ec13d35 100644 --- a/resources/js/ext.uls.compactlinks.js +++ b/resources/js/ext.uls.compactlinks.js @@ -395,8 +395,16 @@ * @return {Array} List of language codes in which there are articles with badges */ CompactInterlanguageList.prototype.filterByBadges = function () { + // Can be removed when backwards compatibility before + // MediaWiki 1.28 is no longer needed + var targetSelector = parseFloat( mw.config.get( 'wgVersion' ) ) >= 1.28 ? + '.interlanguage-link-target' : + 'a'; + return $( '#p-lang' ).find( '[class*="badge"]' ).map( function ( i, el ) { - return convertMediaWikiLanguageCodeToULS( $( el ).find( 'a' ).attr( 'lang' ) ); + return convertMediaWikiLanguageCodeToULS( + $( el ).find( targetSelector ).attr( 'lang' ) + ); } ).toArray(); }; @@ -407,9 +415,16 @@ * @return {Object} List of existing language codes and their hrefs */ CompactInterlanguageList.prototype.getInterlanguageList = function () { - var interlanguageList = {}; + var targetSelector, + interlanguageList = {}; - this.$interlanguageList.find( 'li.interlanguage-link > a' ).each( function () { + // Can be removed when backwards compatibility before + // MediaWiki 1.28 is no longer needed + targetSelector = parseFloat( mw.config.get( 'wgVersion' ) ) >= 1.28 ? + '.interlanguage-link-target' : + 'li.interlanguage-link > a'; + + this.$interlanguageList.find( targetSelector ).each( function () { var langCode = convertMediaWikiLanguageCodeToULS( this.getAttribute( 'lang' ) ); interlanguageList[ langCode ] = {