Page MenuHomePhabricator

Remove support for automatic 'dir' parameter inference for load.php urls
Open, NormalPublic

Description

The dir query parameter for load.php can set explicitly, but MediaWiki doesn't do this for its own urls. Instead, it passes lang only, and depends on ResourceLoaderContext to infer the correct directionality based on MediaWiki's localisation system.

This appears to be one of few non-trivial uses (if not, the only use) of MediaWiki Language classes in ResourceLoader and is a dependency I'd like to remove if possible.

Two changes required:

  • For urls created server-side in PHP, move the responsibility for setting this information to MediaWiki OutputPage, where it creates the ResourceLoaderContext object for ResourceLoaderClientHtml.
  • For urls created client-side in JS, the mw.loader code will need to be expanded to know the current directionality somehow and use it for subsequent load.php requests.

Event Timeline

Krinkle created this task.Jun 14 2019, 6:36 PM
Krinkle added a project: patch-welcome.
Krinkle added a subscriber: Fomafix.

@Fomafix Would you be interested in working on this?

Fomafix added a comment.EditedJun 15 2019, 8:04 AM

The server-side part is easy.
The client-side part requires the information of the direction on JavaScript side. I see four possibilities to get this information:

  • Add an addition JavaScript config variable wgUserDirection or wgUserLanguageDirection.
  • Get the information from the existing JavaScript config variable wgUserLanguage via a mapping table. ULS already contains such a table. A complete table is big. Maybe the table can just filled with the used language codes wgUserLanguage and maybe other languages that are used.
  • Get the information from the browser.
  • Add a new JavaScript config variable specific for resource load containing all URL parameters that just reflected to the server. Default values like dir=ltr or debug=false can be omitted in this variable.

T181684: Add ability to get language directionality from mw.language also requires the language directionality of a language in JavaScript.

A similar dependency is the call of Language::getFallbacksFor. This can avoided in ResourceLoader by transmitting always the whole fallback language chain instead of only the user interface language. By the way this allows an user individual fallback chain.

The server-side part is easy.
The client-side part requires the information of the direction on JavaScript side. I see four possibilities [..]

  1. Add a new JavaScript config variable specific for resource load containing all URL parameters that just reflected to the server. Default values like dir=ltr or debug=false can be omitted in this variable.

I like this one most. It would be very efficient and reduces the amount of information and code required on the client. You can use the existing $VARS that StartupModule and mediawiki.js make use of to very efficiently export these for the current context. I think you can replace reqBase with a $VARS.something assignment to make this work. E.g. skin/lang always, and debug/dir only as needed.

Krinkle triaged this task as Normal priority.Jun 16 2019, 7:35 PM

I like this one most. It would be very efficient and reduces the amount of information and code required on the client. You can use the existing $VARS that StartupModule and mediawiki.js make use of to very efficiently export these for the current context. I think you can replace reqBase with a $VARS.something assignment to make this work. E.g. skin/lang always, and debug/dir only as needed.

Yes, this is the best solution. I created T225899 to set the default URL parameters for JavaScript on server-side.

Why $VARS.something and not mw.config.get( 'something' )?

Gilles moved this task from Inbox to Radar on the Performance-Team board.Jun 17 2019, 8:06 PM
Gilles edited projects, added Performance-Team (Radar); removed Performance-Team.
Fomafix claimed this task.Jun 24 2019, 12:05 PM

Change 518688 had a related patch set uploaded (by Fomafix; owner: Fomafix):
[mediawiki/core@master] resourceloader: Add parameter 'dir' to loader URLs

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