class ResourceLoader {
/* Protected Static Members */
+ protected static $filterCacheVersion = 1;
/** Array: List of module name/ResourceLoaderModule object pairs */
protected $modules = array();
// Try for cache hit
// Use CACHE_ANYTHING since filtering is very slow compared to DB queries
- $key = wfMemcKey( 'resourceloader', 'filter', $filter, md5( $data ) );
+ $key = wfMemcKey( 'resourceloader', 'filter', $filter, self::$filterCacheVersion, md5( $data ) );
$cache = wfGetCache( CACHE_ANYTHING );
$cacheEntry = $cache->get( $key );
if ( is_string( $cacheEntry ) ) {
return $cacheEntry;
}
+ $result = '';
// Run the filter - we've already verified one of these will work
try {
switch ( $filter ) {
$result = JavaScriptDistiller::stripWhiteSpace(
$data, $wgResourceLoaderMinifyJSVerticalSpace
);
+ $result .= "\n\n/* cache key: $key */\n";
break;
case 'minify-css':
$result = CSSMin::minify( $data );
+ $result .= "\n\n/* cache key: $key */\n";
break;
}
foreach ( $name as $key => $value ) {
$this->register( $key, $value );
}
+ wfProfileOut( __METHOD__ );
return;
}
* Get the ResourceLoaderModule object for a given module name.
*
* @param $name String: Module name
- * @return Mixed: ResourceLoaderModule if module has been registered, null otherwise
+ * @return ResourceLoaderModule if module has been registered, null otherwise
*/
public function getModule( $name ) {
if ( !isset( $this->modules[$name] ) ) {
// Some clients send "timestamp;length=123". Strip the part after the first ';'
// so we get a valid timestamp.
$ims = $context->getRequest()->getHeader( 'If-Modified-Since' );
- if ( $ims !== false ) {
+ // Never send 304s in debug mode
+ if ( $ims !== false && !$context->getDebug() ) {
$imsTS = strtok( $ims, ';' );
if ( $mtime <= wfTimestamp( TS_UNIX, $imsTS ) ) {
// There's another bug in ob_gzhandler (see also the comment at
return '/* No modules requested. Max made me put this here */';
}
+ wfProfileIn( __METHOD__ );
// Pre-fetch blobs
if ( $context->shouldIncludeMessages() ) {
try {
$out .= self::makeMessageSetScript( new XmlJsCode( $messagesBlob ) );
break;
default:
- // Minify CSS before embedding in mediaWiki.loader.implement call
+ // Minify CSS before embedding in mw.loader.implement call
// (unless in debug mode)
if ( !$context->getDebug() ) {
foreach ( $styles as $media => $style ) {
}
}
- if ( $context->getDebug() ) {
- return $exceptions . $out;
- } else {
+ if ( !$context->getDebug() ) {
if ( $context->getOnly() === 'styles' ) {
- return $exceptions . $this->filter( 'minify-css', $out );
+ $out = $this->filter( 'minify-css', $out );
} else {
- return $exceptions . $this->filter( 'minify-js', $out );
+ $out = $this->filter( 'minify-js', $out );
}
}
+
+ wfProfileOut( __METHOD__ );
+ return $exceptions . $out;
}
/* Static Methods */
/**
- * Returns JS code to call to mediaWiki.loader.implement for a module with
+ * Returns JS code to call to mw.loader.implement for a module with
* given properties.
*
* @param $name Module name
$scripts = implode( $scripts, "\n" );
}
return Xml::encodeJsCall(
- 'mediaWiki.loader.implement',
+ 'mw.loader.implement',
array(
$name,
new XmlJsCode( "function( $, mw ) {{$scripts}}" ),
* JSON-encoded message blob containing the same data, wrapped in an XmlJsCode object.
*/
public static function makeMessageSetScript( $messages ) {
- return Xml::encodeJsCall( 'mediaWiki.messages.set', array( (object)$messages ) );
+ return Xml::encodeJsCall( 'mw.messages.set', array( (object)$messages ) );
}
/**
}
/**
- * Returns a JS call to mediaWiki.loader.state, which sets the state of a
+ * Returns a JS call to mw.loader.state, which sets the state of a
* module or modules to a given value. Has two calling conventions:
*
* - ResourceLoader::makeLoaderStateScript( $name, $state ):
*/
public static function makeLoaderStateScript( $name, $state = null ) {
if ( is_array( $name ) ) {
- return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name ) );
+ return Xml::encodeJsCall( 'mw.loader.state', array( $name ) );
} else {
- return Xml::encodeJsCall( 'mediaWiki.loader.state', array( $name, $state ) );
+ return Xml::encodeJsCall( 'mw.loader.state', array( $name, $state ) );
}
}
}
/**
- * Returns JS code which calls mediaWiki.loader.register with the given
+ * Returns JS code which calls mw.loader.register with the given
* parameters. Has three calling conventions:
*
* - ResourceLoader::makeLoaderRegisterScript( $name, $version, $dependencies, $group ):
$dependencies = null, $group = null )
{
if ( is_array( $name ) ) {
- return Xml::encodeJsCall( 'mediaWiki.loader.register', array( $name ) );
+ return Xml::encodeJsCall( 'mw.loader.register', array( $name ) );
} else {
$version = (int) $version > 1 ? (int) $version : 1;
- return Xml::encodeJsCall( 'mediaWiki.loader.register',
+ return Xml::encodeJsCall( 'mw.loader.register',
array( $name, $version, $dependencies, $group ) );
}
}
* @param $configuration Array: List of configuration values keyed by variable name
*/
public static function makeConfigSetScript( array $configuration ) {
- return Xml::encodeJsCall( 'mediaWiki.config.set', array( $configuration ) );
+ return Xml::encodeJsCall( 'mw.config.set', array( $configuration ) );
}
/**