From f12177ce20286f5a6bc075ff47d0e66076e2c0f1 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 19 Nov 2011 16:02:26 +0000 Subject: [PATCH] Make ResourceLoader::register() non-recursive, was calling itself recursively on every page load. --- includes/resourceloader/ResourceLoader.php | 59 ++++++++++------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 9973cbc807..17acbd6650 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -219,43 +219,38 @@ class ResourceLoader { wfProfileIn( __METHOD__ ); // Allow multiple modules to be registered in one call - if ( is_array( $name ) ) { - foreach ( $name as $key => $value ) { - $this->register( $key, $value ); + $registrations = is_array( $name ) ? $name : array( $name => $info ); + foreach ( $registrations as $name => $info ) { + // Disallow duplicate registrations + if ( isset( $this->moduleInfos[$name] ) ) { + // A module has already been registered by this name + throw new MWException( + 'ResourceLoader duplicate registration error. ' . + 'Another module has already been registered as ' . $name + ); } - wfProfileOut( __METHOD__ ); - return; - } - // Disallow duplicate registrations - if ( isset( $this->moduleInfos[$name] ) ) { - // A module has already been registered by this name - throw new MWException( - 'ResourceLoader duplicate registration error. ' . - 'Another module has already been registered as ' . $name - ); - } + // Check $name for illegal characters + if ( preg_match( '/[|,!]/', $name ) ) { + throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" ); + } - // Check $name for illegal characters - if ( preg_match( '/[|,!]/', $name ) ) { - throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" ); - } + // Attach module + if ( is_object( $info ) ) { + // Old calling convention + // Validate the input + if ( !( $info instanceof ResourceLoaderModule ) ) { + throw new MWException( 'ResourceLoader invalid module error. ' . + 'Instances of ResourceLoaderModule expected.' ); + } - // Attach module - if ( is_object( $info ) ) { - // Old calling convention - // Validate the input - if ( !( $info instanceof ResourceLoaderModule ) ) { - throw new MWException( 'ResourceLoader invalid module error. ' . - 'Instances of ResourceLoaderModule expected.' ); + $this->moduleInfos[$name] = array( 'object' => $info ); + $info->setName( $name ); + $this->modules[$name] = $info; + } else { + // New calling convention + $this->moduleInfos[$name] = $info; } - - $this->moduleInfos[$name] = array( 'object' => $info ); - $info->setName( $name ); - $this->modules[$name] = $info; - } else { - // New calling convention - $this->moduleInfos[$name] = $info; } wfProfileOut( __METHOD__ ); -- 2.20.1