Currently, ResourceLoader modules use global config variables; they should rather get them from the local Config object.
High level
- ResourceLoader.php:
- $wgShowExceptionDetails in static formatException().
- $wgResourceLoaderDebug and $wgRequest in static inDebugMode(). — can't be improved without breaking changes and alternatives exist already. migrate and remove instead of improving (see below).
- ResourceLoaderContext.php
- $wgLanguageCode in getLanguage() as fallback.
- ResourceLoaderFileModule.php: $IP, $wgResourceBasePath, $wgExtensionAssetsPath.
- ResourceLoaderImage.php: $wgSVGConverter, $wgSVGConverterPath.
- ResourceLoaderModule.php: $wgContLang in getFlip().
- ResourceLoaderStartUpModule.php:
- $wgContLang in getConfigSettings().
- $wgIncludeLegacyJavaScript in getLegacyModules(). - T130879
ResourceLoader::inDebugMode
Context:
Whether ResourceLoader acts in debug mode is determined by the ?debug parameter to load.php. This is handled in the RL\Context class and accepts values 0, 1, 2, true, false. There is also a frontend to this via wiki page views by the same`?debug` parameter e.g. on /wiki/Apple?debug=2 or /w/index.php?debug=2. This is handled by OutputPage and then passed on to RL\ClientHtml which then passes it to load.php.
Developers can make their debug session sticky for a short period of time by setting the resourceLoaderDebug cookie and/or by setting $wgResourceLoaderDebug = in LocalSettings.php locally. This is similarly handled by OutputPage, and then passed to load.php. That is - load.php should be stateless and directly be aware of any MW settings or cookies.
The main reason this method exists is because debug mode decides whether to minify code or not. As such, we historically used ResourceLoader::inDebugMode() to decide between minified and raw chunks. We now handle this differently, via RL\Context::encodeJson() which automatically decides between pretty for debug or minified for prod. If the debug settings is still needed, it can be accesed from RL\Context::getDebug(). This means information is parsed centrally and passed down to where it is needed via the RL Context object.
Older code that still uses the global static ResourceLoader::inDebugMode method:
- ResourceLoader::encodeJsonForScript() Deprecate and remove once unused. We've removed most use of these but we have a utility functions calling them from older code:
- ResourceLoader::makeConfigSetScript Deprecate and remove once unused. 4 extension remaining:
- Used in mediawiki/extensions/UniversalLanguageSelector. Migrate to $context->encodeJson().
- Used in mediawiki/extensions/Kartographer. Migrate to $context->encodeJson().
- Used in mediawiki/extensions/CodeMirror. Migrate to Package files as virtual JSON file.
- Used in mediawiki/extensions/Wikibase. Migrate to $context->encodeJson().
- ResourceLoader::makeInlineCodeWithModule - This formats a single array of strings. It doesn't need to vary by debug mode, and can call json_encode directly instead.
- ResourceLoader::makeConfigSetScript Deprecate and remove once unused. 4 extension remaining:
- OutputPage. It uses inDebugMode to configure RL\ClientHtml and to parse the cookie/MW config/requets param for debug mode. This is the original purpose and remains needed. Everything else flows down from here. There is no need for any other code to consider cookies or MW configuration, because it would get it from here. I suggest we copy ResourceLoader::inDebugMode to private OutputPage method, refactor to use local context, and then use call for RL\ClientHtml instead.
- SpecialJavaScriptTest. It uses inDebugMode() enable debug mode automatically based on cookie or MW config. No longer needed after source maps (T47514). It can be reduced to WebRequest->getRawVal('debug') ?? '0' so that you can still manually enable ?debug=2 here.