r84401 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84400‎ | r84401 | r84402 >
Date:17:15, 20 March 2011
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
(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
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1400,6 +1400,11 @@
14011401 loader request or generating HTML output.
14021402 &$resourceLoader: ResourceLoader object
14031403
 1404+'ResourceLoaderGetStartupModules': Run once the startup module is being generated. This allows you
 1405+to add modules to the startup module. This hook should be used sparingly since any module added here
 1406+will be loaded on all pages. This hook is useful if you want to make code available to module loader
 1407+scripts.
 1408+
14041409 'RawPageViewBeforeOutput': Right before the text is blown out in action=raw
14051410 &$obj: RawPage object
14061411 &$text: The text that's going to be the output
Index: trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -159,17 +159,26 @@
160160
161161 $out = file_get_contents( "$IP/resources/startup.js" );
162162 if ( $context->getOnly() === 'scripts' ) {
163 - // Build load query for jquery and mediawiki modules
 163+
 164+ // The core modules:
 165+ $modules = array( 'jquery', 'mediawiki' );
 166+ wfRunHooks( 'ResourceLoaderGetStartupModules', array( &$modules ) );
 167+
 168+ // Get the latest version
 169+ $version = 0;
 170+ foreach ( $modules as $moduleName ) {
 171+ $version = max( $version,
 172+ $context->getResourceLoader()->getModule( $moduleName )->getModifiedTime( $context )
 173+ );
 174+ }
 175+ // Build load query for StartupModules
164176 $query = array(
165 - 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ),
 177+ 'modules' => implode( '|', $modules ),
166178 'only' => 'scripts',
167179 'lang' => $context->getLanguage(),
168180 'skin' => $context->getSkin(),
169181 'debug' => $context->getDebug() ? 'true' : 'false',
170 - 'version' => wfTimestamp( TS_ISO_8601_BASIC, max(
171 - $context->getResourceLoader()->getModule( 'jquery' )->getModifiedTime( $context ),
172 - $context->getResourceLoader()->getModule( 'mediawiki' )->getModifiedTime( $context )
173 - ) )
 182+ 'version' => wfTimestamp( TS_ISO_8601_BASIC, round( $version, -2 ) )
174183 );
175184 // Ensure uniform query order
176185 ksort( $query );

Sign-offs

UserFlagDate
Krinkleinspected17:19, 20 March 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r84413Per CR, remove round() call I accidentally reintroduced in r84401catrope19:53, 20 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   18:39, 20 March 2011

More timestamp rounding?

#Comment by Catrope (talk | contribs)   19:53, 20 March 2011

D'oh!

Status & tagging log