From 743026d69cda440ef0a14554d14fa5665da51a3c Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sun, 20 Mar 2011 17:15:51 +0000 Subject: [PATCH] (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 --- docs/hooks.txt | 5 +++++ .../ResourceLoaderStartUpModule.php | 21 +++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) 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 ); -- 2.20.1