r73077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73076‎ | r73077 | r73078 >
Date:18:27, 15 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Moved responsiblity of initializtion to ResourceLoader public interfaces.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2294,8 +2294,6 @@
22952295 foreach ( (array) $modules as $name ) {
22962296 $moduleGroups[strpos( $name, 'user' ) === 0 ? 'user' : null][] = $name;
22972297 }
2298 - // Make sure ResourceLoader is ready for use
2299 - ResourceLoader::initialize();
23002298 $links = '';
23012299 foreach ( $moduleGroups as $group => $modules ) {
23022300 if ( count( $modules ) ) {
Index: trunk/phase3/includes/ResourceLoader.php
@@ -33,6 +33,23 @@
3434
3535 /* Protected Static Methods */
3636
 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+
3754 /**
3855 * Runs text through a filter, caching the filtered result for future calls
3956 *
@@ -85,17 +102,6 @@
86103
87104 /* Static Methods */
88105
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 -
100106 /**
101107 * Registers a module with the ResourceLoader system.
102108 *
@@ -110,6 +116,11 @@
111117 * the client in a way that they can easily see them if they want to, such as by using FireBug
112118 */
113119 public static function register( $name, ResourceLoaderModule $object = null ) {
 120+
 121+ if ( !self::$initialized ) {
 122+ self::initialize();
 123+ }
 124+
114125 // Allow multiple modules to be registered in one call
115126 if ( is_array( $name ) && !isset( $object ) ) {
116127 foreach ( $name as $key => $value ) {
@@ -135,6 +146,11 @@
136147 * @return Array: array( modulename => ResourceLoaderModule )
137148 */
138149 public static function getModules() {
 150+
 151+ if ( !self::$initialized ) {
 152+ self::initialize();
 153+ }
 154+
139155 return self::$modules;
140156 }
141157
@@ -145,6 +161,11 @@
146162 * @return mixed ResourceLoaderModule or null if not registered
147163 */
148164 public static function getModule( $name ) {
 165+
 166+ if ( !self::$initialized ) {
 167+ self::initialize();
 168+ }
 169+
149170 return isset( self::$modules[$name] ) ? self::$modules[$name] : null;
150171 }
151172
@@ -155,6 +176,11 @@
156177 * @return String: JavaScript code for registering all modules with the client loader
157178 */
158179 public static function getModuleRegistrations( ResourceLoaderContext $context ) {
 180+
 181+ if ( !self::$initialized ) {
 182+ self::initialize();
 183+ }
 184+
159185 $scripts = '';
160186 $registrations = array();
161187
@@ -188,6 +214,11 @@
189215 * @return Integer: UNIX timestamp
190216 */
191217 public static function getHighestModifiedTime( ResourceLoaderContext $context ) {
 218+
 219+ if ( !self::$initialized ) {
 220+ self::initialize();
 221+ }
 222+
192223 $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice
193224
194225 foreach ( self::$modules as $module ) {
@@ -206,8 +237,9 @@
207238 global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage;
208239 global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage;
209240
210 - // Register modules
211 - self::initialize();
 241+ if ( !self::$initialized ) {
 242+ self::initialize();
 243+ }
212244
213245 // Split requested modules into two groups, modules and missing
214246 $modules = array();

Status & tagging log