Jump to content

Manual:Hooks/ResourceLoaderModifyStartupSourceUrls

From mediawiki.org
ResourceLoaderModifyStartupSourceUrls
Available from version 1.43.0
Allows modifying source URLs (i.e. URLs to load.php) before they get embedded in the JS generated for the startup module.
Define function:
public static function onResourceLoaderModifyStartupSourceUrls( array &$urls, MediaWiki\ResourceLoader\Context $context ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"ResourceLoaderModifyStartupSourceUrls": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderModifyStartupSourceUrls"
	}
}
Called from: File(s): includes/ResourceLoader/StartUpModule.php
Interface: ResourceLoaderModifyStartupSourceUrlsHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:ResourceLoaderModifyStartupSourceUrls extensions.


Details

[edit]
  • array &$urls - An array of source name => URL; the URL might be relative.
  • MediaWiki\ResourceLoader\Context $context

Usage

[edit]

The hook lets you modify ResourceLoader source URLs (i.e. URLs to load.php, see ResourceLoader::getSources) before they get embedded in the JS generated for the startup module.

The hook must not add or remove sources, and calling the new URL should have a roughly similar outcome to calling the old URL. It is mainly intended to preserve URL modifications that might affect the code generated for the modules (e.g. when load.php?modules=startup is called on the mobile site, it should generate source URLs which also use the mobile site).

See also