From 0578faf0fbc4a05c2eefeb7965986bb66710cb7d Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Wed, 15 Sep 2010 18:15:36 +0000 Subject: [PATCH] Fixed really bad stuff going on with running hooks at the file level. Now, ResourceLoader::initialize must be called before you can use it durring page rendering. ResourceLoader::respond calls it automatically. ResourceLoader::initialize only has side-effects when run the first time. --- includes/OutputPage.php | 2 ++ includes/ResourceLoader.php | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index cec102a598..e0ba8533ab 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2294,6 +2294,8 @@ class OutputPage { foreach ( (array) $modules as $name ) { $moduleGroups[strpos( $name, 'user' ) === 0 ? 'user' : null][] = $name; } + // Make sure ResourceLoader is ready for use + ResourceLoader::initialize(); $links = ''; foreach ( $moduleGroups as $group => $modules ) { if ( count( $modules ) ) { diff --git a/includes/ResourceLoader.php b/includes/ResourceLoader.php index 6fb9105d1e..cb759ca499 100644 --- a/includes/ResourceLoader.php +++ b/includes/ResourceLoader.php @@ -29,6 +29,7 @@ class ResourceLoader { // @var array list of module name/ResourceLoaderModule object pairs protected static $modules = array(); + protected static $initialized = false; /* Protected Static Methods */ @@ -84,6 +85,17 @@ class ResourceLoader { /* Static Methods */ + public static function initialize() { + global $IP; + + if ( !self::$initialized ) { + // Do this first just in case someone accidentally adds a call to ResourceLoader::initialize in their hook + self::$initialized = true; + self::register( include( "$IP/resources/Resources.php" ) ); + wfRunHooks( 'ResourceLoaderRegisterModules' ); + } + } + /** * Registers a module with the ResourceLoader system. * @@ -194,6 +206,9 @@ class ResourceLoader { global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage; global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage; + // Register modules + self::initialize(); + // Split requested modules into two groups, modules and missing $modules = array(); $missing = array(); @@ -323,7 +338,4 @@ class ResourceLoader { } } } -} - -ResourceLoader::register( include( "$IP/resources/Resources.php" ) ); -wfRunHooks( 'ResourceLoaderRegisterModules' ); \ No newline at end of file +} \ No newline at end of file -- 2.20.1