Merge "Use HttpStatus::header instead of manually crafting header()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 4 Jun 2015 20:25:37 +0000 (20:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Jun 2015 20:25:37 +0000 (20:25 +0000)
1  2 
includes/resourceloader/ResourceLoader.php

   * @author Trevor Parscal
   */
  
 +use Psr\Log\LoggerAwareInterface;
 +use Psr\Log\LoggerInterface;
 +use Psr\Log\NullLogger;
 +
  /**
   * Dynamic JavaScript and CSS resource loading system.
   *
   * Most of the documentation is on the MediaWiki documentation wiki starting at:
   *    https://www.mediawiki.org/wiki/ResourceLoader
   */
 -class ResourceLoader {
 +class ResourceLoader implements LoggerAwareInterface {
        /** @var int */
        protected static $filterCacheVersion = 7;
  
         */
        protected $blobStore;
  
 +      /**
 +       * @var LoggerInterface
 +       */
 +      private $logger;
 +
        /**
         * Load information stored in the database about modules.
         *
                }
  
                if ( !in_array( $filter, array( 'minify-js', 'minify-css' ) ) ) {
 -                      wfDebugLog( 'resourceloader', __METHOD__ . ": Invalid filter: $filter" );
 +                      $this->logger->info( __METHOD__ . ": Invalid filter: $filter" );
                        return $data;
                }
  
                                $cache->set( $key, $result );
                        } catch ( Exception $e ) {
                                MWExceptionHandler::logException( $e );
 -                              wfDebugLog( 'resourceloader', __METHOD__ . ": minification failed: $e" );
 +                              $this->logger->info( __METHOD__ . ": minification failed: $e" );
                                $this->errors[] = self::formatExceptionNoComment( $e );
                        }
                }
         * Register core modules and runs registration hooks.
         * @param Config|null $config
         */
 -      public function __construct( Config $config = null ) {
 +      public function __construct( Config $config = null, LoggerInterface $logger = null ) {
                global $IP;
  
 -              if ( $config === null ) {
 -                      wfDebug( __METHOD__ . ' was called without providing a Config instance' );
 -                      $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
 +              if ( !$logger ) {
 +                      $logger = new NullLogger();
                }
 +              $this->setLogger( $logger );
  
 +              if ( !$config ) {
 +                      $this->logger->info( __METHOD__ . ' was called without providing a Config instance' );
 +                      $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
 +              }
                $this->config = $config;
  
                // Add 'local' source first
                return $this->config;
        }
  
 +      public function setLogger( LoggerInterface $logger ) {
 +              $this->logger = $logger;
 +      }
 +
        /**
         * @param MessageBlobStore $blobStore
         * @since 1.25
                                // Do not allow private modules to be loaded from the web.
                                // This is a security issue, see bug 34907.
                                if ( $module->getGroup() === 'private' ) {
 -                                      wfDebugLog( 'resourceloader', __METHOD__ . ": request for private module '$name' denied" );
 +                                      $this->logger->info( __METHOD__ . ": request for private module '$name' denied" );
                                        $this->errors[] = "Cannot show private module \"$name\"";
                                        continue;
                                }
                        $this->preloadModuleInfo( array_keys( $modules ), $context );
                } catch ( Exception $e ) {
                        MWExceptionHandler::logException( $e );
 -                      wfDebugLog( 'resourceloader', __METHOD__ . ": preloading module info failed: $e" );
 +                      $this->logger->info( __METHOD__ . ": preloading module info failed: $e" );
                        $this->errors[] = self::formatExceptionNoComment( $e );
                }
  
                        $versionHash = $this->getCombinedVersion( $context, array_keys( $modules ) );
                } catch ( Exception $e ) {
                        MWExceptionHandler::logException( $e );
 -                      wfDebugLog( 'resourceloader', __METHOD__ . ": calculating version hash failed: $e" );
 +                      $this->logger->info( __METHOD__ . ": calculating version hash failed: $e" );
                        $this->errors[] = self::formatExceptionNoComment( $e );
                }
  
                        // sending the 304.
                        wfResetOutputBuffers( /* $resetGzipEncoding = */ true );
  
-                       header( 'HTTP/1.0 304 Not Modified' );
-                       header( 'Status: 304 Not Modified' );
+                       HttpStatus::header( 304 );
  
                        $this->sendResponseHeaders( $context, $etag, false );
                        return true;
@@@ -958,7 -940,8 +957,7 @@@ MESSAGE
                                $blobs = $this->blobStore->get( $this, $modules, $context->getLanguage() );
                        } catch ( Exception $e ) {
                                MWExceptionHandler::logException( $e );
 -                              wfDebugLog(
 -                                      'resourceloader',
 +                              $this->logger->info(
                                        __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e"
                                );
                                $this->errors[] = self::formatExceptionNoComment( $e );
                                }
                        } catch ( Exception $e ) {
                                MWExceptionHandler::logException( $e );
 -                              wfDebugLog( 'resourceloader', __METHOD__ . ": generating module package failed: $e" );
 +                              $this->logger->info( __METHOD__ . ": generating module package failed: $e" );
                                $this->errors[] = self::formatExceptionNoComment( $e );
  
                                // Respond to client with error-state instead of module implementation