From: Trevor Parscal Date: Wed, 15 Sep 2010 18:27:47 +0000 (+0000) Subject: Moved responsiblity of initializtion to ResourceLoader public interfaces. X-Git-Tag: 1.31.0-rc.0~34910 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=b2a0b0656920b33727f21e97baa6c95ee689c8f0;p=lhc%2Fweb%2Fwiklou.git Moved responsiblity of initializtion to ResourceLoader public interfaces. --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index e0ba8533ab..cec102a598 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2294,8 +2294,6 @@ 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 cb759ca499..e4176e7b78 100644 --- a/includes/ResourceLoader.php +++ b/includes/ResourceLoader.php @@ -33,6 +33,23 @@ class ResourceLoader { /* Protected Static Methods */ + /* + * Registers core modules and runs registration hooks + */ + protected static function initialize() { + global $IP; + + // Safety check - this should never be called more than once anyways + if ( self::$initialized ) { + wfDebug( 'ResourceLoader::intitialize was called more than once' ); + return; + } + + self::$initialized = true; + self::register( include( "$IP/resources/Resources.php" ) ); + wfRunHooks( 'ResourceLoaderRegisterModules' ); + } + /** * Runs text through a filter, caching the filtered result for future calls * @@ -85,17 +102,6 @@ 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. * @@ -110,6 +116,11 @@ class ResourceLoader { * the client in a way that they can easily see them if they want to, such as by using FireBug */ public static function register( $name, ResourceLoaderModule $object = null ) { + + if ( !self::$initialized ) { + self::initialize(); + } + // Allow multiple modules to be registered in one call if ( is_array( $name ) && !isset( $object ) ) { foreach ( $name as $key => $value ) { @@ -135,6 +146,11 @@ class ResourceLoader { * @return Array: array( modulename => ResourceLoaderModule ) */ public static function getModules() { + + if ( !self::$initialized ) { + self::initialize(); + } + return self::$modules; } @@ -145,6 +161,11 @@ class ResourceLoader { * @return mixed ResourceLoaderModule or null if not registered */ public static function getModule( $name ) { + + if ( !self::$initialized ) { + self::initialize(); + } + return isset( self::$modules[$name] ) ? self::$modules[$name] : null; } @@ -155,6 +176,11 @@ class ResourceLoader { * @return String: JavaScript code for registering all modules with the client loader */ public static function getModuleRegistrations( ResourceLoaderContext $context ) { + + if ( !self::$initialized ) { + self::initialize(); + } + $scripts = ''; $registrations = array(); @@ -188,6 +214,11 @@ class ResourceLoader { * @return Integer: UNIX timestamp */ public static function getHighestModifiedTime( ResourceLoaderContext $context ) { + + if ( !self::$initialized ) { + self::initialize(); + } + $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice foreach ( self::$modules as $module ) { @@ -206,8 +237,9 @@ class ResourceLoader { global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage; global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage; - // Register modules - self::initialize(); + if ( !self::$initialized ) { + self::initialize(); + } // Split requested modules into two groups, modules and missing $modules = array();