Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2294,8 +2294,6 @@ |
2295 | 2295 | foreach ( (array) $modules as $name ) { |
2296 | 2296 | $moduleGroups[strpos( $name, 'user' ) === 0 ? 'user' : null][] = $name; |
2297 | 2297 | } |
2298 | | - // Make sure ResourceLoader is ready for use |
2299 | | - ResourceLoader::initialize(); |
2300 | 2298 | $links = ''; |
2301 | 2299 | foreach ( $moduleGroups as $group => $modules ) { |
2302 | 2300 | if ( count( $modules ) ) { |
Index: trunk/phase3/includes/ResourceLoader.php |
— | — | @@ -33,6 +33,23 @@ |
34 | 34 | |
35 | 35 | /* Protected Static Methods */ |
36 | 36 | |
| 37 | + /* |
| 38 | + * Registers core modules and runs registration hooks |
| 39 | + */ |
| 40 | + protected static function initialize() { |
| 41 | + global $IP; |
| 42 | + |
| 43 | + // Safety check - this should never be called more than once anyways |
| 44 | + if ( self::$initialized ) { |
| 45 | + wfDebug( 'ResourceLoader::intitialize was called more than once' ); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + self::$initialized = true; |
| 50 | + self::register( include( "$IP/resources/Resources.php" ) ); |
| 51 | + wfRunHooks( 'ResourceLoaderRegisterModules' ); |
| 52 | + } |
| 53 | + |
37 | 54 | /** |
38 | 55 | * Runs text through a filter, caching the filtered result for future calls |
39 | 56 | * |
— | — | @@ -85,17 +102,6 @@ |
86 | 103 | |
87 | 104 | /* Static Methods */ |
88 | 105 | |
89 | | - public static function initialize() { |
90 | | - global $IP; |
91 | | - |
92 | | - if ( !self::$initialized ) { |
93 | | - // Do this first just in case someone accidentally adds a call to ResourceLoader::initialize in their hook |
94 | | - self::$initialized = true; |
95 | | - self::register( include( "$IP/resources/Resources.php" ) ); |
96 | | - wfRunHooks( 'ResourceLoaderRegisterModules' ); |
97 | | - } |
98 | | - } |
99 | | - |
100 | 106 | /** |
101 | 107 | * Registers a module with the ResourceLoader system. |
102 | 108 | * |
— | — | @@ -110,6 +116,11 @@ |
111 | 117 | * the client in a way that they can easily see them if they want to, such as by using FireBug |
112 | 118 | */ |
113 | 119 | public static function register( $name, ResourceLoaderModule $object = null ) { |
| 120 | + |
| 121 | + if ( !self::$initialized ) { |
| 122 | + self::initialize(); |
| 123 | + } |
| 124 | + |
114 | 125 | // Allow multiple modules to be registered in one call |
115 | 126 | if ( is_array( $name ) && !isset( $object ) ) { |
116 | 127 | foreach ( $name as $key => $value ) { |
— | — | @@ -135,6 +146,11 @@ |
136 | 147 | * @return Array: array( modulename => ResourceLoaderModule ) |
137 | 148 | */ |
138 | 149 | public static function getModules() { |
| 150 | + |
| 151 | + if ( !self::$initialized ) { |
| 152 | + self::initialize(); |
| 153 | + } |
| 154 | + |
139 | 155 | return self::$modules; |
140 | 156 | } |
141 | 157 | |
— | — | @@ -145,6 +161,11 @@ |
146 | 162 | * @return mixed ResourceLoaderModule or null if not registered |
147 | 163 | */ |
148 | 164 | public static function getModule( $name ) { |
| 165 | + |
| 166 | + if ( !self::$initialized ) { |
| 167 | + self::initialize(); |
| 168 | + } |
| 169 | + |
149 | 170 | return isset( self::$modules[$name] ) ? self::$modules[$name] : null; |
150 | 171 | } |
151 | 172 | |
— | — | @@ -155,6 +176,11 @@ |
156 | 177 | * @return String: JavaScript code for registering all modules with the client loader |
157 | 178 | */ |
158 | 179 | public static function getModuleRegistrations( ResourceLoaderContext $context ) { |
| 180 | + |
| 181 | + if ( !self::$initialized ) { |
| 182 | + self::initialize(); |
| 183 | + } |
| 184 | + |
159 | 185 | $scripts = ''; |
160 | 186 | $registrations = array(); |
161 | 187 | |
— | — | @@ -188,6 +214,11 @@ |
189 | 215 | * @return Integer: UNIX timestamp |
190 | 216 | */ |
191 | 217 | public static function getHighestModifiedTime( ResourceLoaderContext $context ) { |
| 218 | + |
| 219 | + if ( !self::$initialized ) { |
| 220 | + self::initialize(); |
| 221 | + } |
| 222 | + |
192 | 223 | $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice |
193 | 224 | |
194 | 225 | foreach ( self::$modules as $module ) { |
— | — | @@ -206,8 +237,9 @@ |
207 | 238 | global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage; |
208 | 239 | global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage; |
209 | 240 | |
210 | | - // Register modules |
211 | | - self::initialize(); |
| 241 | + if ( !self::$initialized ) { |
| 242 | + self::initialize(); |
| 243 | + } |
212 | 244 | |
213 | 245 | // Split requested modules into two groups, modules and missing |
214 | 246 | $modules = array(); |