resourceloader: Use content-neutral context when computing module versions
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 16 Jun 2015 03:57:12 +0000 (04:57 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 18 Jun 2015 20:10:41 +0000 (21:10 +0100)
The startup module produces a manifest with versions representing the
entire module.

Typically, the request for the startup module itself has only=scripts.
However, that "only" must only apply to what resources of the startup module are
output in the request.

The context passed to getModifiedTime() and getVersionHash() must not suggest
any restriction of measuring only the scripts, or otherwise ignoring some
aspects of the module (such as stylesheets, or messages).

Most existing getModifiedTime() implementations compute timestamps of all
files, regardless of the context. So this bug didn't surface before.
However that will change for modules that compute the version hash based on
getModuleContent(), which does honour the getOnly() and shouldIncludeScripts()
methods of the request context.

Change-Id: Ib8f09c39d10724d146b53b6d53d82da18944a12b

includes/resourceloader/ResourceLoaderModule.php

index 63da592..d58c01d 100644 (file)
@@ -585,6 +585,16 @@ abstract class ResourceLoaderModule {
         * @return string Hash (should use ResourceLoader::makeHash)
         */
        public function getVersionHash( ResourceLoaderContext $context ) {
+               // The startup module produces a manifest with versions representing the entire module.
+               // Typically, the request for the startup module itself has only=scripts. That must apply
+               // only to the startup module content, and not to the module version computed here.
+               $context = new DerivativeResourceLoaderContext( $context );
+               $context->setModules( array() );
+               // Version hash must cover all resources, regardless of startup request itself.
+               $context->setOnly( null );
+               // Compute version hash based on content, not debug urls.
+               $context->setDebug( false );
+
                // Cache this somewhat expensive operation. Especially because some classes
                // (e.g. startup module) iterate more than once over all modules to get versions.
                $contextHash = $context->getHash();