r103686 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103685‎ | r103686 | r103687 >
Date:16:31, 19 November 2011
Author:catrope
Status:ok
Tags:
Comment:
1.18wmf1: MFT r103682
Modified paths:
  • /branches/wmf/1.18wmf1/includes/resourceloader/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/includes/resourceloader/ResourceLoader.php
@@ -208,43 +208,38 @@
209209 wfProfileIn( __METHOD__ );
210210
211211 // Allow multiple modules to be registered in one call
212 - if ( is_array( $name ) ) {
213 - foreach ( $name as $key => $value ) {
214 - $this->register( $key, $value );
 212+ $registrations = is_array( $name ) ? $name : array( $name => $info );
 213+ foreach ( $registrations as $name => $info ) {
 214+ // Disallow duplicate registrations
 215+ if ( isset( $this->moduleInfos[$name] ) ) {
 216+ // A module has already been registered by this name
 217+ throw new MWException(
 218+ 'ResourceLoader duplicate registration error. ' .
 219+ 'Another module has already been registered as ' . $name
 220+ );
215221 }
216 - wfProfileOut( __METHOD__ );
217 - return;
218 - }
219222
220 - // Disallow duplicate registrations
221 - if ( isset( $this->moduleInfos[$name] ) ) {
222 - // A module has already been registered by this name
223 - throw new MWException(
224 - 'ResourceLoader duplicate registration error. ' .
225 - 'Another module has already been registered as ' . $name
226 - );
227 - }
 223+ // Check $name for illegal characters
 224+ if ( preg_match( '/[|,!]/', $name ) ) {
 225+ throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" );
 226+ }
228227
229 - // Check $name for illegal characters
230 - if ( preg_match( '/[|,!]/', $name ) ) {
231 - throw new MWException( "ResourceLoader module name '$name' is invalid. Names may not contain pipes (|), commas (,) or exclamation marks (!)" );
232 - }
 228+ // Attach module
 229+ if ( is_object( $info ) ) {
 230+ // Old calling convention
 231+ // Validate the input
 232+ if ( !( $info instanceof ResourceLoaderModule ) ) {
 233+ throw new MWException( 'ResourceLoader invalid module error. ' .
 234+ 'Instances of ResourceLoaderModule expected.' );
 235+ }
233236
234 - // Attach module
235 - if ( is_object( $info ) ) {
236 - // Old calling convention
237 - // Validate the input
238 - if ( !( $info instanceof ResourceLoaderModule ) ) {
239 - throw new MWException( 'ResourceLoader invalid module error. ' .
240 - 'Instances of ResourceLoaderModule expected.' );
 237+ $this->moduleInfos[$name] = array( 'object' => $info );
 238+ $info->setName( $name );
 239+ $this->modules[$name] = $info;
 240+ } else {
 241+ // New calling convention
 242+ $this->moduleInfos[$name] = $info;
241243 }
242 -
243 - $this->moduleInfos[$name] = array( 'object' => $info );
244 - $info->setName( $name );
245 - $this->modules[$name] = $info;
246 - } else {
247 - // New calling convention
248 - $this->moduleInfos[$name] = $info;
249244 }
250245
251246 wfProfileOut( __METHOD__ );
Property changes on: branches/wmf/1.18wmf1/includes/resourceloader/ResourceLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
252247 Merged /trunk/phase3/includes/resourceloader/ResourceLoader.php:r103682

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r103682Make ResourceLoader::register() non-recursive, was calling itself recursively...catrope16:02, 19 November 2011

Status & tagging log