$this->{$member}[$key] = (array)$value;
}
break;
+ case 'deprecated':
+ $this->deprecated = $option;
+ break;
// Lists of strings
case 'dependencies':
case 'messages':
*/
public function getScript( ResourceLoaderContext $context ) {
$files = $this->getScriptFiles( $context );
- return $this->readScriptFiles( $files );
+ return $this->getDeprecationInformation() . $this->readScriptFiles( $files );
}
/**
if ( !file_exists( $localPath ) ) {
throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
}
- $contents = file_get_contents( $localPath );
+ $contents = $this->stripBom( file_get_contents( $localPath ) );
if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
$contents = $this->validateScriptFile( $localPath, $contents );
}
if ( !file_exists( $localPath ) ) {
throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
}
- $contents = file_get_contents( $localPath );
+ $contents = $this->stripBom( file_get_contents( $localPath ) );
if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
// Static files don't really need to be checked as often; unlike
// on-wiki module they shouldn't change unexpectedly without
$style = $this->compileLessFile( $localPath, $context );
$this->hasGeneratedStyles = true;
} else {
- $style = file_get_contents( $localPath );
+ $style = $this->stripBom( file_get_contents( $localPath ) );
}
if ( $flip ) {
$localDir = dirname( $localPath );
$remoteDir = dirname( $remotePath );
// Get and register local file references
- $localFileRefs = CSSMin::getAllLocalFileReferences( $style, $localDir );
+ $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
foreach ( $localFileRefs as $file ) {
if ( file_exists( $file ) ) {
$this->localFileRefs[] = $file;
$this->missingLocalFileRefs[] = $file;
}
}
- return MemoizedCallable::call( 'CSSMin::remap',
- [ $style, $localDir, $remoteDir, true ] );
+ // Don't cache this call. remap() ensures data URIs embeds are up to date,
+ // and urls contain correct content hashes in their query string. (T128668)
+ return CSSMin::remap( $style, $localDir, $remoteDir, true );
}
/**
return $this->targets;
}
+ /**
+ * Get the module's load type.
+ *
+ * @since 1.28
+ * @return string
+ */
+ public function getType() {
+ $canBeStylesOnly = !(
+ // All options except 'styles', 'skinStyles' and 'debugRaw'
+ $this->scripts
+ || $this->debugScripts
+ || $this->templates
+ || $this->languageScripts
+ || $this->skinScripts
+ || $this->dependencies
+ || $this->messages
+ || $this->skipFunction
+ || $this->raw
+ );
+ return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
+ }
+
/**
* Compile a LESS file into CSS.
*
$localPath = $this->getLocalPath( $templatePath );
if ( file_exists( $localPath ) ) {
$content = file_get_contents( $localPath );
- $templates[$alias] = $content;
+ $templates[$alias] = $this->stripBom( $content );
} else {
$msg = __METHOD__ . ": template file not found: \"$localPath\"";
wfDebugLog( 'resourceloader', $msg );
}
return $templates;
}
+
+ /**
+ * Takes an input string and removes the UTF-8 BOM character if present
+ *
+ * We need to remove these after reading a file, because we concatenate our files and
+ * the BOM character is not valid in the middle of a string.
+ * We already assume UTF-8 everywhere, so this should be safe.
+ *
+ * @return string input minus the intial BOM char
+ */
+ protected function stripBom( $input ) {
+ if ( substr_compare( "\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
+ return substr( $input, 3 );
+ }
+ return $input;
+ }
}