Page MenuHomePhabricator

Commons' default LanguageSelect gadget doesn't work on Ajax page reloads
Open, Needs TriagePublicBUG REPORT

Description

This is in fact a bug of https://commons.wikimedia.org/wiki/MediaWiki:Gadget-LanguageSelect.js, but will post here too as Phabricator is more visible.

When using scripts that reload the page via Ajax (such as Convenient-Discussions and DiscussionTools) the language selection isn't preformed on reload as it does on initiual load, and all the language versions get displayed instead of only the selected one.

You can see the demonstration here. A real world example (with as many as 19 languages) is here.

In the first case, for example, when loading the page using Convenient Discussions and then reloading (using the refresh button of the navigation panel on the left of the page), this is shown

image.png (251×852 px, 37 KB)
instead of this
image.png (162×850 px, 21 KB)

The first idea is to replace $(document).ready with mw.hook('wikipage.content').add. But that would probably be not enough: 'wikipage.content' hook can be fired for pieces of DOM other than #mw-content-text (so, the init method should probably take $content as its first parameter and then use). It can also fire more than once (which is, well, why we need it), so the container element created by the gadget could be created many times.

Event Timeline

Jack_who_built_the_house renamed this task from Commons' LanguageSelect gadget should use hook instead of document ready event to Commons' default LanguageSelect gadget should use hook instead of document ready event.May 16 2021, 9:56 PM
Jack_who_built_the_house renamed this task from Commons' default LanguageSelect gadget should use hook instead of document ready event to Commons' default LanguageSelect gadget doesn't work on Ajax page reloads.May 16 2021, 9:59 PM