}
// Defaults
$options += array( 'cache' => true, 'cacheReport' => false );
+ $stats = RequestContext::getMain()->getStats();
// Don't filter empty content
if ( trim( $data ) === '' ) {
$cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
$cacheEntry = $cache->get( $key );
if ( is_string( $cacheEntry ) ) {
- wfIncrStats( "resourceloader_cache.$filter.hit" );
+ $stats->increment( "resourceloader_cache.$filter.hit" );
return $cacheEntry;
}
$result = '';
try {
- $stats = RequestContext::getMain()->getStats();
$statStart = microtime( true );
-
$result = self::applyFilter( $filter, $data, $this->config );
-
$statTiming = microtime( true ) - $statStart;
- $stats->timing( "resourceloader_cache.$filter.miss", 1000 * $statTiming );
+ $stats->increment( "resourceloader_cache.$filter.miss" );
+ $stats->timing( "resourceloader_cache.$filter.timing", 1000 * $statTiming );
if ( $options['cacheReport'] ) {
$result .= "\n/* cache key: $key */";
}
$this->register( include "$IP/resources/Resources.php" );
$this->register( include "$IP/resources/ResourcesOOUI.php" );
// Register extension modules
- Hooks::run( 'ResourceLoaderRegisterModules', array( &$this ) );
$this->register( $config->get( 'ResourceModules' ) );
+ Hooks::run( 'ResourceLoaderRegisterModules', array( &$this ) );
if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
$this->registerTestModules();
if ( $context->getImageObj() && $this->errors ) {
// We can't show both the error messages and the response when it's an image.
- $errorText = '';
- foreach ( $this->errors as $error ) {
- $errorText .= $error . "\n";
- }
- $response = $errorText;
+ $response = implode( "\n\n", $this->errors );
} elseif ( $this->errors ) {
- // Prepend comments indicating errors
- $errorText = '';
- foreach ( $this->errors as $error ) {
- $errorText .= self::makeComment( $error );
+ $errorText = implode( "\n\n", $this->errors );
+ $errorResponse = self::makeComment( $errorText );
+ if ( $context->shouldIncludeScripts() ) {
+ $errorResponse .= 'if (window.console && console.error) {'
+ . Xml::encodeJsCall( 'console.error', array( $errorText ) )
+ . "}\n";
}
- $response = $errorText . $response;
+
+ // Prepend error info to the response
+ $response = $errorResponse . $response;
}
$this->errors = array();
protected static function formatExceptionNoComment( $e ) {
global $wgShowExceptionDetails;
- if ( $wgShowExceptionDetails ) {
- return $e->__toString();
- } else {
- return wfMessage( 'internalerror' )->text();
+ if ( !$wgShowExceptionDetails ) {
+ return 'Internal error';
}
+
+ return $e->__toString();
}
/**
$out .= $scripts;
} elseif ( is_array( $scripts ) ) {
// ...except when $scripts is an array of URLs
- $out .= self::makeLoaderImplementScript( $name, $scripts, array(), array() );
+ $out .= self::makeLoaderImplementScript( $name, $scripts, array(), array(), array() );
}
break;
case 'styles':
$query = self::createLoaderQuery( $context, $extraQuery );
$script = $this->getLoadScript( $source );
- // Prevent the IE6 extension check from being triggered (bug 28840)
- // by appending a character that's invalid in Windows extensions ('*')
- return wfExpandUrl( wfAppendQuery( $script, $query ) . '&*', PROTO_RELATIVE );
+ return wfAppendQuery( $script, $query );
}
/**
$only, $printable, $handheld, $extraQuery
);
- // Prevent the IE6 extension check from being triggered (bug 28840)
- // by appending a character that's invalid in Windows extensions ('*')
- return wfExpandUrl( wfAppendQuery( $wgLoadScript, $query ) . '&*', PROTO_RELATIVE );
+ return wfAppendQuery( $wgLoadScript, $query );
}
/**
* @param Config $config
* @throws MWException
* @since 1.22
- * @return lessc
+ * @return Less_Parser
*/
public static function getLessCompiler( Config $config ) {
// When called from the installer, it is possible that a required PHP extension
// is missing (at least for now; see bug 47564). If this is the case, throw an
// exception (caught by the installer) to prevent a fatal error later on.
- if ( !class_exists( 'lessc' ) ) {
- throw new MWException( 'MediaWiki requires the lessphp compiler' );
- }
- if ( !function_exists( 'ctype_digit' ) ) {
- throw new MWException( 'lessc requires the Ctype extension' );
+ if ( !class_exists( 'Less_Parser' ) ) {
+ throw new MWException( 'MediaWiki requires the less.php parser' );
}
- $less = new lessc();
- $less->setPreserveComments( true );
- $less->setVariables( self::getLessVars( $config ) );
- $less->setImportDir( $config->get( 'ResourceLoaderLESSImportPaths' ) );
- foreach ( $config->get( 'ResourceLoaderLESSFunctions' ) as $name => $func ) {
- $less->registerFunction( $name, $func );
- }
- return $less;
+ $parser = new Less_Parser;
+ $parser->ModifyVars( self::getLessVars( $config ) );
+ $parser->SetImportDirs( array_fill_keys( $config->get( 'ResourceLoaderLESSImportPaths' ), '' ) );
+ $parser->SetOption( 'relativeUrls', false );
+ $parser->SetCacheDir( $config->get( 'CacheDirectory' ) ?: wfTempDir() );
+
+ return $parser;
}
/**