Index: trunk/phase3/includes/resourceloader/ResourceLoader.php |
— | — | @@ -219,43 +219,38 @@ |
220 | 220 | wfProfileIn( __METHOD__ ); |
221 | 221 | |
222 | 222 | // Allow multiple modules to be registered in one call |
223 | | - if ( is_array( $name ) ) { |
224 | | - foreach ( $name as $key => $value ) { |
225 | | - $this->register( $key, $value ); |
| 223 | + $registrations = is_array( $name ) ? $name : array( $name => $info ); |
| 224 | + foreach ( $registrations as $name => $info ) { |
| 225 | + // Disallow duplicate registrations |
| 226 | + if ( isset( $this->moduleInfos[$name] ) ) { |
| 227 | + // A module has already been registered by this name |
| 228 | + throw new MWException( |
| 229 | + 'ResourceLoader duplicate registration error. ' . |
| 230 | + 'Another module has already been registered as ' . $name |
| 231 | + ); |
226 | 232 | } |
227 | | - wfProfileOut( __METHOD__ ); |
228 | | - return; |
229 | | - } |
230 | 233 | |
231 | | - // Disallow duplicate registrations |
232 | | - if ( isset( $this->moduleInfos[$name] ) ) { |
233 | | - // A module has already been registered by this name |
234 | | - throw new MWException( |
235 | | - 'ResourceLoader duplicate registration error. ' . |
236 | | - 'Another module has already been registered as ' . $name |
237 | | - ); |
238 | | - } |
| 234 | + // Check $name for illegal characters |
| 235 | + if ( preg_match( '/[|,!]/', $name ) ) { |
| 236 | + throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" ); |
| 237 | + } |
239 | 238 | |
240 | | - // Check $name for illegal characters |
241 | | - if ( preg_match( '/[|,!]/', $name ) ) { |
242 | | - throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" ); |
243 | | - } |
| 239 | + // Attach module |
| 240 | + if ( is_object( $info ) ) { |
| 241 | + // Old calling convention |
| 242 | + // Validate the input |
| 243 | + if ( !( $info instanceof ResourceLoaderModule ) ) { |
| 244 | + throw new MWException( 'ResourceLoader invalid module error. ' . |
| 245 | + 'Instances of ResourceLoaderModule expected.' ); |
| 246 | + } |
244 | 247 | |
245 | | - // Attach module |
246 | | - if ( is_object( $info ) ) { |
247 | | - // Old calling convention |
248 | | - // Validate the input |
249 | | - if ( !( $info instanceof ResourceLoaderModule ) ) { |
250 | | - throw new MWException( 'ResourceLoader invalid module error. ' . |
251 | | - 'Instances of ResourceLoaderModule expected.' ); |
| 248 | + $this->moduleInfos[$name] = array( 'object' => $info ); |
| 249 | + $info->setName( $name ); |
| 250 | + $this->modules[$name] = $info; |
| 251 | + } else { |
| 252 | + // New calling convention |
| 253 | + $this->moduleInfos[$name] = $info; |
252 | 254 | } |
253 | | - |
254 | | - $this->moduleInfos[$name] = array( 'object' => $info ); |
255 | | - $info->setName( $name ); |
256 | | - $this->modules[$name] = $info; |
257 | | - } else { |
258 | | - // New calling convention |
259 | | - $this->moduleInfos[$name] = $info; |
260 | 255 | } |
261 | 256 | |
262 | 257 | wfProfileOut( __METHOD__ ); |