Add a hook to StartUpModule that can modify the source URLs that get embedded into the startup module JS in the form of mw.loader.addSource() parameters. The intended use case is preserving relevant URL information, especially in the case of the 'local' source which is a relative URL, when the URL pattern of the load.php URL that generates the startup module code is different from the URL pattern of the page that loads that load.php URL. (E.g. $wgLoadScript is set to a different domain than the current page, to canonicalize load.php URLs for a site that's reachable via multiple domains, but then by default the local source is a relative URL which would be interpreted relative to the URL of the page that executes the startup module code, so it would result in calls to non-canonical load.php URLs). Bug: T365162 Bug: T371530 Change-Id: I199ab779abd0596b836ae43dcc5f2f2a489c9274
95 lines
2.6 KiB
PHP
95 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\ResourceLoader;
|
|
|
|
use MediaWiki\Config\Config;
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
|
|
/**
|
|
* @internal
|
|
* @codeCoverageIgnore
|
|
* @ingroup ResourceLoader
|
|
*/
|
|
class HookRunner implements
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderExcludeUserOptionsHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderForeignApiModulesHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderModifyStartupSourceUrlsHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderRegisterModulesHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteModulePagesHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderSiteStylesModulePagesHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook,
|
|
\MediaWiki\ResourceLoader\Hook\ResourceLoaderJqueryMsgModuleMagicWordsHook
|
|
{
|
|
/** @var HookContainer */
|
|
private $container;
|
|
|
|
public function __construct( HookContainer $container ) {
|
|
$this->container = $container;
|
|
}
|
|
|
|
public function onResourceLoaderExcludeUserOptions( array &$keysToExclude, Context $context ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderExcludeUserOptions',
|
|
[ &$keysToExclude, $context ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderForeignApiModules( &$dependencies, $context ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderForeignApiModules',
|
|
[ &$dependencies, $context ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderModifyStartupSourceUrls( array &$urls, Context $context ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderModifyStartupSourceUrls',
|
|
[ &$urls, $context ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderRegisterModules( ResourceLoader $rl ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderRegisterModules',
|
|
[ $rl ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderSiteModulePages( $skin, array &$pages ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderSiteModulePages',
|
|
[ $skin, &$pages ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderSiteStylesModulePages( $skin, array &$pages ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderSiteStylesModulePages',
|
|
[ $skin, &$pages ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
|
$this->container->run(
|
|
'ResourceLoaderGetConfigVars',
|
|
[ &$vars, $skin, $config ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
|
|
public function onResourceLoaderJqueryMsgModuleMagicWords( Context $context,
|
|
array &$magicWords
|
|
): void {
|
|
$this->container->run(
|
|
'ResourceLoaderJqueryMsgModuleMagicWords',
|
|
[ $context, &$magicWords ],
|
|
[ 'abortable' => false ]
|
|
);
|
|
}
|
|
}
|