From: Roan Kattouw Date: Sun, 20 Mar 2011 17:15:51 +0000 (+0000) Subject: (bug 26805) Introduce ResourceLoaderGetStartupModules hook to allow extensions to... X-Git-Tag: 1.31.0-rc.0~31292 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=743026d69cda440ef0a14554d14fa5665da51a3c;p=lhc%2Fweb%2Fwiklou.git (bug 26805) Introduce ResourceLoaderGetStartupModules hook to allow extensions to add modules to the startup set (normally this is jQuery and mediawiki). Applied patch by Michael Dale, with minor style tweaks --- diff --git a/docs/hooks.txt b/docs/hooks.txt index d5866c01a9..07648a4300 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1400,6 +1400,11 @@ $out: OutputPage object loader request or generating HTML output. &$resourceLoader: ResourceLoader object +'ResourceLoaderGetStartupModules': Run once the startup module is being generated. This allows you +to add modules to the startup module. This hook should be used sparingly since any module added here +will be loaded on all pages. This hook is useful if you want to make code available to module loader +scripts. + 'RawPageViewBeforeOutput': Right before the text is blown out in action=raw &$obj: RawPage object &$text: The text that's going to be the output diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 7048f03c90..f047fe4af6 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -159,17 +159,26 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { $out = file_get_contents( "$IP/resources/startup.js" ); if ( $context->getOnly() === 'scripts' ) { - // Build load query for jquery and mediawiki modules + + // The core modules: + $modules = array( 'jquery', 'mediawiki' ); + wfRunHooks( 'ResourceLoaderGetStartupModules', array( &$modules ) ); + + // Get the latest version + $version = 0; + foreach ( $modules as $moduleName ) { + $version = max( $version, + $context->getResourceLoader()->getModule( $moduleName )->getModifiedTime( $context ) + ); + } + // Build load query for StartupModules $query = array( - 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ), + 'modules' => implode( '|', $modules ), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', - 'version' => wfTimestamp( TS_ISO_8601_BASIC, max( - $context->getResourceLoader()->getModule( 'jquery' )->getModifiedTime( $context ), - $context->getResourceLoader()->getModule( 'mediawiki' )->getModifiedTime( $context ) - ) ) + 'version' => wfTimestamp( TS_ISO_8601_BASIC, round( $version, -2 ) ) ); // Ensure uniform query order ksort( $query );