* @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 );
}
$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
* @author Trevor Parscal
*/
+use MediaWiki\Logger\LoggerFactory;
+
// Bail on old versions of PHP, or if composer has not been run yet to install
// dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+.
require_once dirname( __FILE__ ) . '/includes/PHPVersionCheck.php';
// Respond to resource loading request.
// foo()->bar() syntax is not supported in PHP4, and this file needs to *parse* in PHP4.
$configFactory = ConfigFactory::getDefaultInstance();
-$resourceLoader = new ResourceLoader( $configFactory->makeConfig( 'main' ) );
+$resourceLoader = new ResourceLoader(
+ $configFactory->makeConfig( 'main' ),
+ LoggerFactory::getInstance( 'resourceloader' )
+);
$resourceLoader->respond( new ResourceLoaderContext( $resourceLoader, $wgRequest ) );
Profiler::instance()->setTemplated( true );