(Translated by https://www.hiragana.jp/)
⚓ T311617 MUL - Wikibase classic termbox (entity terms view) sometimes reorders user babel languages
Page MenuHomePhabricator

MUL - Wikibase classic termbox (entity terms view) sometimes reorders user babel languages
Closed, ResolvedPublic8 Estimated Story PointsBUG REPORT

Description

Steps to reproduce:
Open any Entity (e.g. https://test.wikidata.org/wiki/Q172818)

What happens?

  • The termbox initially shows the languages sorted in one order (e.g. mul, en, de, pt), but then JS runs and they get reordered into another order (e.g. mul, de, en, pt).
  • The behavior changes based on your logged-in state / Babels (de-N, en-4, pt-1 in the example given), and uselang (mul in the example given).
  • There is also an accompanying console warning:

Existing entitytermsforlanguagelistview DOM does not match configured languages

Mobile-only:

  • On mobile an additional result is that the formatting is off ("No label defined" is bold, "blah" is not).

image.png (912×1 px, 53 KB)

It looks like this can only be reproduced when not logged in.

What should have happened instead?

  • The termbox should show the languages correctly ordered from the start (just like we are used to from Wikidata proper). That is, the languages do not jump around.
  • The formatting on mobile is normal again.

Notes:

Acceptance criteria:

  • We understand the problem that leads to this issue.
  • The problem is solved (or if solving the problem is out of scope then please create a follow-up task so we can discuss it)

Original:
When I load https://test.wikidata.org/wiki/Q172818?uselang=mul, the termbox initially shows the languages mul, en, de, pt, but then JS runs and they get reordered into mul, de, en, pt – English and German switch places. (My Babel is currently de-N, en-4, pt-1.) There is also an accompanying console warning:

Existing entitytermsforlanguagelistview DOM does not match configured languages

This needs to be looked into. (I thought I’d fixed this with T307808, but clearly there’s still some remaining issue.)

Event Timeline

karapayneWMDE set the point value for this task to 8.
Manuel changed the subtype of this task from "Task" to "Bug Report".Jul 12 2022, 11:08 AM
karapayneWMDE renamed this task from Wikibase classic termbox (entity terms view) sometimes reorders user babel languages to MULLANG - Wikibase classic termbox (entity terms view) sometimes reorders user babel languages.Sep 13 2022, 9:56 AM
karapayneWMDE renamed this task from MULLANG - Wikibase classic termbox (entity terms view) sometimes reorders user babel languages to MUL - Wikibase classic termbox (entity terms view) sometimes reorders user babel languages.

Task breakdown note: we decided to split the mobile termbox part into a separate task (T318137), since it seems technically unrelated. (But both are part of the sprint now.)

Okay, I think I’ve found the two code paths that do subtly different things here.

  • “Server-side order” (initial rendering):
    • OutputPageBeforeHTMLHookHandler::getLocallyRenderedEntityViewPlaceholderExpander() calls $this->userPreferredTermsLanguages->getLanguages( $language->getCode(), $user ) (where $language is the UI language)
    • UserPreferredContentLanguagesLookup::getLanguages() calls $this->userLanguageLookup->getAllUserLanguages( $user ) and then prepends the request UI language to it
    • BabelUserLanguageLookup::getAllUserLanguages() calls $this->getUserSpecifiedLanguages( $user ) (the user’s Babel languages) and prepends the user’s UI language option to it
    • final order: request UI language (uselang URL parameter), user UI language (option), user Babel languages
  • “Client-side order” (after reordering) – actually, this is also largely controlled by the server:
    • wikibase.getUserLanguages() gets mw.config.get( 'wgUserLanguage' ) and prepends the request UI language to it
    • the wgUserLanguage config had been added in OutputPageBeforeHTMLHookHandler::addJsUserLanguages() (same hook handler class as above)
    • OutputPageBeforeHTMLHookHandler::addJsUserLanguages() calls $this->userLanguageLookup->getUserSpecifiedLanguages( $out->getUser() ) (same user language lookup service as above)
    • BabelUserLanguageLookup::getUserSpecifiedLanguages() returns the user’s Babel languages
    • final order: request UI language (uselang URL parameter), user Babel languages
  • (Both also limit the returned language codes to only ones that are actually valid term language codes, and ensure that language codes aren’t listed twice, but that’s not important here.)

So in both cases we ultimately start with the request UI language and end with the user Babel languages, but the initial server-rendered termbox also includes the user’s language preference (aka option, setting, whatever) before all other Babel languages, whereas the JS code uses an order where the user’s language preference isn’t used (it appears wherever the user has included it in their Babel, if at all).

I think that including the user language preference in addition to the request UI language probably makes sense (someone will have written that code for a reason). I don’t think there’s a good reason why we shouldn’t send that same language list to the JS side, so we probably just want to make OutputPageBeforeHTMLHookHandler::addJsUserLanguages() call $this->userPreferredTermsLanguages->getLanguages( $language->getCode(), $user ) as well.

Note that WikibaseMediaInfo already uses UserLanguageLookup::getAllUserLanguages() instead of ::getUserSpecifiedLanguages() (i.e. includes the language preference).

Change 833798 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Make sure language lookups return plain arrays

https://gerrit.wikimedia.org/r/833798

Change 833799 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Use UserPreferredContentLanguagesLookup for wbUserSpecifiedLanguages

https://gerrit.wikimedia.org/r/833799

Change 833800 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/WikibaseMediaInfo@master] Revert "Make sure wbUserSpecifiedLanguages is a plain array"

https://gerrit.wikimedia.org/r/833800

(The third Gerrit change is just an optional cleanup, and it should probably at least be +1ed by the WBMI developers. The first two Wikibase changes are necessary to fix the bug.)

Change 834341 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Move JS variables into MakeGlobalVariablesScript hook

https://gerrit.wikimedia.org/r/834341

Change 834341 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Move JS variables into MakeGlobalVariablesScript hook

https://gerrit.wikimedia.org/r/834341

Change 833798 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Make sure language lookups return plain arrays

https://gerrit.wikimedia.org/r/833798

Change 833799 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Send user preferred content languages to client-side

https://gerrit.wikimedia.org/r/833799

Change 833800 merged by jenkins-bot:

[mediawiki/extensions/WikibaseMediaInfo@master] Revert "Make sure wbUserSpecifiedLanguages is a plain array"

https://gerrit.wikimedia.org/r/833800