From: Timo Tijhof Date: Tue, 10 May 2016 19:00:44 +0000 (+0100) Subject: resourceloader: Track state of page-style modules X-Git-Tag: 1.31.0-rc.0~6374^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=a464d1d41d69f12fe93146629254f6c785f43d81;hp=a29c7cdede96cb64fa929ff29488357c26f4e773;p=lhc%2Fweb%2Fwiklou.git resourceloader: Track state of page-style modules This allows dynamically loaded modules to depend on page-style modules without it causing the page-style module to be loaded a second time. * New method Module::getType() indicates whether a module is a page-style module or supposed to be dynamically loaded. * Emit warning from addModuleStyles() when given a module that is not a page-style module (to be enforced later) Bug: T92459 Bug: T87871 Change-Id: I8b6c6a10d965e73965f877c42e995d04202524f3 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c667fb9363..545ab73b56 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2785,6 +2785,17 @@ class OutputPage extends ContextSource { continue; } + if ( $only === ResourceLoaderModule::TYPE_STYLES ) { + if ( $module->getType() !== ResourceLoaderModule::LOAD_STYLES ) { + $logger = $resourceLoader->getLogger(); + $logger->debug( 'Unexpected general module "{module}" in styles queue.', [ + 'module' => $name, + ] ); + } else { + $links['states'][$name] = 'ready'; + } + } + $sortedModules[$module->getSource()][$module->getGroup()][$name] = $module; } diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index b06553ab90..6b755d7290 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -922,6 +922,28 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { return $this->targets; } + /** + * Get the module's load type. + * + * @since 1.28 + * @return string + */ + public function getType() { + $canBeStylesOnly = !( + // All options except 'styles', 'skinStyles' and 'debugRaw' + $this->scripts + || $this->debugScripts + || $this->templates + || $this->languageScripts + || $this->skinScripts + || $this->dependencies + || $this->messages + || $this->skipFunction + || $this->raw + ); + return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL; + } + /** * Compile a LESS file into CSS. * diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 121a6c9928..3adadff514 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -35,6 +35,12 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { const TYPE_STYLES = 'styles'; const TYPE_COMBINED = 'combined'; + # Desired load type + // Module only has styles (loaded via