r103682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103681‎ | r103682 | r103683 >
Date:16:02, 19 November 2011
Author:catrope
Status:ok
Tags:
Comment:
Make ResourceLoader::register() non-recursive, was calling itself recursively on every page load.
Modified paths:
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -219,43 +219,38 @@
220220 wfProfileIn( __METHOD__ );
221221
222222 // 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+ );
226232 }
227 - wfProfileOut( __METHOD__ );
228 - return;
229 - }
230233
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+ }
239238
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+ }
244247
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;
252254 }
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;
260255 }
261256
262257 wfProfileOut( __METHOD__ );

Follow-up revisions

RevisionCommit summaryAuthorDate
r1036861.18wmf1: MFT r103682catrope16:31, 19 November 2011

Status & tagging log