From d04a92a5517d656447d73001e51a8cfb9b130d07 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 17 Sep 2015 23:14:46 +0100 Subject: [PATCH] resourceloader: Keep module_deps handling inside module base class Most of it was already there (SELECT in preloadInfo, and in-class holder via setFileDependencies) but the logic to write to the database was within the file module class. Moving it the other way around may make more sense in the future, but for the moment ResourceLoader.php makes assumptions about all modules being able to store setFileDependencies as read from the database. Whether or not a class currently implements a way to write to that table. Change-Id: I06b5da4144798197478c66e8b9ccd4cc62cf6fb6 --- .../ResourceLoaderFileModule.php | 17 +------- .../resourceloader/ResourceLoaderModule.php | 43 ++++++++++++++++--- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php index 51118b1f9f..ca10ab7cc7 100644 --- a/includes/resourceloader/ResourceLoaderFileModule.php +++ b/includes/resourceloader/ResourceLoaderFileModule.php @@ -417,21 +417,8 @@ class ResourceLoaderFileModule extends ResourceLoaderModule { ); // Collect referenced files $this->localFileRefs = array_unique( $this->localFileRefs ); - // If the list has been modified since last time we cached it, update the cache - try { - if ( $this->localFileRefs !== $this->getFileDependencies( $context->getSkin() ) ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->replace( 'module_deps', - array( array( 'md_module', 'md_skin' ) ), array( - 'md_module' => $this->getName(), - 'md_skin' => $context->getSkin(), - 'md_deps' => FormatJson::encode( $this->localFileRefs ), - ) - ); - } - } catch ( Exception $e ) { - wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" ); - } + $this->saveFileDependencies( $context->getSkin(), $this->localFileRefs ); + return $styles; } diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index 376b62cdf1..80c8220550 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -374,12 +374,13 @@ abstract class ResourceLoaderModule { /** * Get the files this module depends on indirectly for a given skin. - * Currently these are only image files referenced by the module's CSS. + * + * These are only image files referenced by the module's stylesheet. * * @param string $skin Skin name * @return array List of files */ - public function getFileDependencies( $skin ) { + protected function getFileDependencies( $skin ) { // Try in-object cache first if ( isset( $this->fileDeps[$skin] ) ) { return $this->fileDeps[$skin]; @@ -405,8 +406,11 @@ abstract class ResourceLoaderModule { } /** - * Set preloaded file dependency information. Used so we can load this - * information for all modules at once. + * Set in-object cache for file dependencies. + * + * This is used to retrieve data in batches. See ResourceLoader::preloadModuleInfo(). + * To save the data, use saveFileDependencies(). + * * @param string $skin Skin name * @param array $deps Array of file names */ @@ -414,6 +418,31 @@ abstract class ResourceLoaderModule { $this->fileDeps[$skin] = $deps; } + /** + * Set the files this module depends on indirectly for a given skin. + * + * @since 1.26 + * @param string $skin Skin name + * @param array $localFileRefs List of files + */ + protected function saveFileDependencies( $skin, $localFileRefs ) { + try { + // If the list has been modified since last time we cached it, update the cache + if ( $localFileRefs !== $this->getFileDependencies( $skin ) ) { + $dbw = wfGetDB( DB_MASTER ); + $dbw->replace( 'module_deps', + array( array( 'md_module', 'md_skin' ) ), array( + 'md_module' => $this->getName(), + 'md_skin' => $skin, + 'md_deps' => FormatJson::encode( $localFileRefs ), + ) + ); + } + } catch ( Exception $e ) { + wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" ); + } + } + /** * Get the last modification timestamp of the messages in this module for a given language. * @param string $lang Language code @@ -445,8 +474,10 @@ abstract class ResourceLoaderModule { } /** - * Set a preloaded message blob last modification timestamp. Used so we - * can load this information for all modules at once. + * Set in-object cache for message blob time. + * + * This is used to retrieve data in batches. See ResourceLoader::preloadModuleInfo(). + * * @param string $lang Language code * @param int $mtime UNIX timestamp */ -- 2.20.1