r79139 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79138‎ | r79139 | r79140 >
Date:22:28, 28 December 2010
Author:platonides
Status:ok
Tags:
Comment:
MFT r78924
Modified paths:
  • /branches/REL1_17/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)

Diff [purge]

Index: branches/REL1_17/phase3/includes/resourceloader/ResourceLoader.php
@@ -66,7 +66,7 @@
6767 ), __METHOD__
6868 );
6969
70 - // Set modules' dependecies
 70+ // Set modules' dependencies
7171 $modulesWithDeps = array();
7272 foreach ( $res as $row ) {
7373 $this->getModule( $row->md_module )->setFileDependencies( $skin,
@@ -116,7 +116,7 @@
117117 *
118118 * @param $filter String: Name of filter to run
119119 * @param $data String: Text to filter, such as JavaScript or CSS text
120 - * @return String: Filtered data
 120+ * @return String: Filtered data, or a comment containing an error message
121121 */
122122 protected function filter( $filter, $data ) {
123123 wfProfileIn( __METHOD__ );
@@ -150,14 +150,14 @@
151151 $result = CSSMin::minify( $data );
152152 break;
153153 }
 154+
 155+ // Save filtered text to Memcached
 156+ $cache->set( $key, $result );
154157 } catch ( Exception $exception ) {
155 - throw new MWException( 'ResourceLoader filter error. ' .
156 - 'Exception was thrown: ' . $exception->getMessage() );
 158+ // Return exception as a comment
 159+ $result = "/*\n{$exception->__toString()}\n*/";
157160 }
158161
159 - // Save filtered text to Memcached
160 - $cache->set( $key, $result );
161 -
162162 wfProfileOut( __METHOD__ );
163163
164164 return $result;
@@ -293,6 +293,7 @@
294294 ob_start();
295295
296296 wfProfileIn( __METHOD__ );
 297+ $response = '';
297298
298299 // Split requested modules into two groups, modules and missing
299300 $modules = array();
@@ -319,7 +320,12 @@
320321 }
321322
322323 // Preload information needed to the mtime calculation below
323 - $this->preloadModuleInfo( array_keys( $modules ), $context );
 324+ try {
 325+ $this->preloadModuleInfo( array_keys( $modules ), $context );
 326+ } catch( Exception $e ) {
 327+ // Add exception to the output as a comment
 328+ $response .= "/*\n{$e->__toString()}\n*/";
 329+ }
324330
325331 wfProfileIn( __METHOD__.'-getModifiedTime' );
326332
@@ -327,12 +333,17 @@
328334 // the last modified time
329335 $mtime = wfTimestamp( TS_UNIX, $wgCacheEpoch );
330336 foreach ( $modules as $module ) {
331 - // Bypass squid cache if the request includes any private modules
332 - if ( $module->getGroup() === 'private' ) {
333 - $smaxage = 0;
 337+ try {
 338+ // Bypass squid cache if the request includes any private modules
 339+ if ( $module->getGroup() === 'private' ) {
 340+ $smaxage = 0;
 341+ }
 342+ // Calculate maximum modified time
 343+ $mtime = max( $mtime, $module->getModifiedTime( $context ) );
 344+ } catch ( Exception $e ) {
 345+ // Add exception to the output as a comment
 346+ $response .= "/*\n{$e->__toString()}\n*/";
334347 }
335 - // Calculate maximum modified time
336 - $mtime = max( $mtime, $module->getModifiedTime( $context ) );
337348 }
338349
339350 wfProfileOut( __METHOD__.'-getModifiedTime' );
@@ -378,7 +389,7 @@
379390 }
380391
381392 // Generate a response
382 - $response = $this->makeModuleResponse( $context, $modules, $missing );
 393+ $response .= $this->makeModuleResponse( $context, $modules, $missing );
383394
384395 // Capture any PHP warnings from the output buffer and append them to the
385396 // response in a comment if we're in debug mode.
@@ -404,62 +415,73 @@
405416 public function makeModuleResponse( ResourceLoaderContext $context,
406417 array $modules, $missing = array() )
407418 {
 419+ $out = '';
408420 if ( $modules === array() && $missing === array() ) {
409421 return '/* No modules requested. Max made me put this here */';
410422 }
411423
412424 // Pre-fetch blobs
413425 if ( $context->shouldIncludeMessages() ) {
414 - $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
 426+ //try {
 427+ $blobs = MessageBlobStore::get( $this, $modules, $context->getLanguage() );
 428+ //} catch ( Exception $e ) {
 429+ // Add exception to the output as a comment
 430+ // $out .= "/*\n{$e->__toString()}\n*/";
 431+ //}
415432 } else {
416433 $blobs = array();
417434 }
418435
419436 // Generate output
420 - $out = '';
421437 foreach ( $modules as $name => $module ) {
422 -
423438 wfProfileIn( __METHOD__ . '-' . $name );
 439+ try {
 440+ // Scripts
 441+ $scripts = '';
 442+ if ( $context->shouldIncludeScripts() ) {
 443+ $scripts .= $module->getScript( $context ) . "\n";
 444+ }
424445
425 - // Scripts
426 - $scripts = '';
427 - if ( $context->shouldIncludeScripts() ) {
428 - $scripts .= $module->getScript( $context ) . "\n";
429 - }
 446+ // Styles
 447+ $styles = array();
 448+ if ( $context->shouldIncludeStyles() ) {
 449+ $styles = $module->getStyles( $context );
 450+ }
430451
431 - // Styles
432 - $styles = array();
433 - if ( $context->shouldIncludeStyles() ) {
434 - $styles = $module->getStyles( $context );
435 - }
 452+ // Messages
 453+ $messagesBlob = isset( $blobs[$name] ) ? $blobs[$name] : '{}';
436454
437 - // Messages
438 - $messagesBlob = isset( $blobs[$name] ) ? $blobs[$name] : '{}';
 455+ // Append output
 456+ switch ( $context->getOnly() ) {
 457+ case 'scripts':
 458+ $out .= $scripts;
 459+ break;
 460+ case 'styles':
 461+ $out .= self::makeCombinedStyles( $styles );
 462+ break;
 463+ case 'messages':
 464+ $out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
 465+ break;
 466+ default:
 467+ // Minify CSS before embedding in mediaWiki.loader.implement call
 468+ // (unless in debug mode)
 469+ if ( !$context->getDebug() ) {
 470+ foreach ( $styles as $media => $style ) {
 471+ $styles[$media] = $this->filter( 'minify-css', $style );
 472+ }
 473+ }
 474+ $out .= self::makeLoaderImplementScript( $name, $scripts, $styles,
 475+ new XmlJsCode( $messagesBlob ) );
 476+ break;
 477+ }
 478+ } catch ( Exception $e ) {
 479+ // Add exception to the output as a comment
 480+ $out .= "/*\n{$e->__toString()}\n*/";
439481
440 - // Append output
441 - switch ( $context->getOnly() ) {
442 - case 'scripts':
443 - $out .= $scripts;
444 - break;
445 - case 'styles':
446 - $out .= self::makeCombinedStyles( $styles );
447 - break;
448 - case 'messages':
449 - $out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
450 - break;
451 - default:
452 - // Minify CSS before embedding in mediaWiki.loader.implement call
453 - // (unless in debug mode)
454 - if ( !$context->getDebug() ) {
455 - foreach ( $styles as $media => $style ) {
456 - $styles[$media] = $this->filter( 'minify-css', $style );
457 - }
458 - }
459 - $out .= self::makeLoaderImplementScript( $name, $scripts, $styles,
460 - new XmlJsCode( $messagesBlob ) );
461 - break;
 482+ // Register module as missing
 483+ $missing[] = $name;
 484+ unset( $modules[$name] );
462485 }
463 -
464486 wfProfileOut( __METHOD__ . '-' . $name );
465487 }
466488
Property changes on: branches/REL1_17/phase3/includes/resourceloader/ResourceLoader.php
___________________________________________________________________
Modified: svn:mergeinfo
467489 Merged /trunk/phase3/includes/resourceloader/ResourceLoader.php:r78924

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78924Proper exception handling in ResourceLoader. Catch exceptions and output them...catrope20:14, 23 December 2010

Status & tagging log