"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "includes/resourceloader/ResourceLoaderFileModule.php" between
mediawiki-1.31.1.tar.gz and mediawiki-1.32.0.tar.gz

About: MediaWiki is a wiki engine (the collaborative editing software that runs for e.g. Wikipedia, the free encyclopedia).

ResourceLoaderFileModule.php  (mediawiki-1.31.1):ResourceLoaderFileModule.php  (mediawiki-1.32.0)
skipping to change at line 156 skipping to change at line 156
* @var array Place where readStyleFile() tracks file dependencies for no n-existent files. * @var array Place where readStyleFile() tracks file dependencies for no n-existent files.
* Used in tests to detect missing dependencies. * Used in tests to detect missing dependencies.
*/ */
protected $missingLocalFileRefs = []; protected $missingLocalFileRefs = [];
/** /**
* Constructs a new module from an options array. * Constructs a new module from an options array.
* *
* @param array $options List of options; if not given or empty, an empty module will be * @param array $options List of options; if not given or empty, an empty module will be
* constructed * constructed
* @param string $localBasePath Base path to prepend to all local paths i * @param string|null $localBasePath Base path to prepend to all local pa
n $options. Defaults ths in $options.
* to $IP * Defaults to $IP
* @param string $remoteBasePath Base path to prepend to all remote paths * @param string|null $remoteBasePath Base path to prepend to all remote
in $options. Defaults paths in $options.
* to $wgResourceBasePath * Defaults to $wgResourceBasePath
* *
* Below is a description for the $options array: * Below is a description for the $options array:
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @par Construction options: * @par Construction options:
* @code * @code
* [ * [
* // Base path to prepend to all local paths in $options. Defaul ts to $IP * // Base path to prepend to all local paths in $options. Defaul ts to $IP
* 'localBasePath' => [base path], * 'localBasePath' => [base path],
* // Base path to prepend to all remote paths in $options. Defau lts to $wgResourceBasePath * // Base path to prepend to all remote paths in $options. Defau lts to $wgResourceBasePath
* 'remoteBasePath' => [base path], * 'remoteBasePath' => [base path],
skipping to change at line 301 skipping to change at line 301
} }
} }
} }
} }
/** /**
* Extract a pair of local and remote base paths from module definition i nformation. * Extract a pair of local and remote base paths from module definition i nformation.
* Implementation note: the amount of global state used in this function is staggering. * Implementation note: the amount of global state used in this function is staggering.
* *
* @param array $options Module definition * @param array $options Module definition
* @param string $localBasePath Path to use if not provided in module def inition. Defaults * @param string|null $localBasePath Path to use if not provided in modul e definition. Defaults
* to $IP * to $IP
* @param string $remoteBasePath Path to use if not provided in module de finition. Defaults * @param string|null $remoteBasePath Path to use if not provided in modu le definition. Defaults
* to $wgResourceBasePath * to $wgResourceBasePath
* @return array Array( localBasePath, remoteBasePath ) * @return array Array( localBasePath, remoteBasePath )
*/ */
public static function extractBasePaths( public static function extractBasePaths(
$options = [], $options = [],
$localBasePath = null, $localBasePath = null,
$remoteBasePath = null $remoteBasePath = null
) { ) {
global $IP, $wgResourceBasePath; global $IP, $wgResourceBasePath;
skipping to change at line 463 skipping to change at line 463
public function getSkipFunction() { public function getSkipFunction() {
if ( !$this->skipFunction ) { if ( !$this->skipFunction ) {
return null; return null;
} }
$localPath = $this->getLocalPath( $this->skipFunction ); $localPath = $this->getLocalPath( $this->skipFunction );
if ( !file_exists( $localPath ) ) { if ( !file_exists( $localPath ) ) {
throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" ); throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
} }
$contents = $this->stripBom( file_get_contents( $localPath ) ); $contents = $this->stripBom( file_get_contents( $localPath ) );
if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' )
) {
$contents = $this->validateScriptFile( $localPath, $conte
nts );
}
return $contents; return $contents;
} }
/** /**
* @return bool * @return bool
*/ */
public function isRaw() { public function isRaw() {
return $this->raw; return $this->raw;
} }
skipping to change at line 489 skipping to change at line 486
* This class uses getDefinitionSummary() instead, to avoid filesystem ov erhead * This class uses getDefinitionSummary() instead, to avoid filesystem ov erhead
* involved with building the full module content inside a startup reques t. * involved with building the full module content inside a startup reques t.
* *
* @return bool * @return bool
*/ */
public function enableModuleContentVersion() { public function enableModuleContentVersion() {
return false; return false;
} }
/** /**
* Helper method to gather file hashes for getDefinitionSummary. * Helper method for getDefinitionSummary.
*
* This function is context-sensitive, only computing hashes of files rel
evant to the
* given language, skin, etc.
* *
* @see ResourceLoaderModule::getFileDependencies * @see ResourceLoaderModule::getFileDependencies
* @param ResourceLoaderContext $context * @param ResourceLoaderContext $context
* @return array * @return array
*/ */
protected function getFileHashes( ResourceLoaderContext $context ) { private function getFileHashes( ResourceLoaderContext $context ) {
$files = []; $files = [];
// Flatten style files into $files // Flatten style files into $files
$styles = self::collateFilePathListByOption( $this->styles, 'medi a', 'all' ); $styles = self::collateFilePathListByOption( $this->styles, 'medi a', 'all' );
foreach ( $styles as $styleFiles ) { foreach ( $styles as $styleFiles ) {
$files = array_merge( $files, $styleFiles ); $files = array_merge( $files, $styleFiles );
} }
$skinFiles = self::collateFilePathListByOption( $skinFiles = self::collateFilePathListByOption(
self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ), self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
skipping to change at line 644 skipping to change at line 638
$collatedFiles = []; $collatedFiles = [];
foreach ( (array)$list as $key => $value ) { foreach ( (array)$list as $key => $value ) {
if ( is_int( $key ) ) { if ( is_int( $key ) ) {
// File name as the value // File name as the value
if ( !isset( $collatedFiles[$default] ) ) { if ( !isset( $collatedFiles[$default] ) ) {
$collatedFiles[$default] = []; $collatedFiles[$default] = [];
} }
$collatedFiles[$default][] = $value; $collatedFiles[$default][] = $value;
} elseif ( is_array( $value ) ) { } elseif ( is_array( $value ) ) {
// File name as the key, options array as the val ue // File name as the key, options array as the val ue
$optionValue = isset( $value[$option] ) ? $value[ $option] : $default; $optionValue = $value[$option] ?? $default;
if ( !isset( $collatedFiles[$optionValue] ) ) { if ( !isset( $collatedFiles[$optionValue] ) ) {
$collatedFiles[$optionValue] = []; $collatedFiles[$optionValue] = [];
} }
$collatedFiles[$optionValue][] = $key; $collatedFiles[$optionValue][] = $key;
} }
} }
return $collatedFiles; return $collatedFiles;
} }
/** /**
* Get a list of element that match a key, optionally using a fallback ke y. * Get a list of element that match a key, optionally using a fallback ke y.
* *
* @param array $list List of lists to select from * @param array $list List of lists to select from
* @param string $key Key to look for in $map * @param string $key Key to look for in $map
* @param string $fallback Key to look for in $list if $key doesn't exist * @param string|null $fallback Key to look for in $list if $key doesn't exist
* @return array List of elements from $map which matched $key or $fallba ck, * @return array List of elements from $map which matched $key or $fallba ck,
* or an empty list in case of no match * or an empty list in case of no match
*/ */
protected static function tryForKey( array $list, $key, $fallback = null ) { protected static function tryForKey( array $list, $key, $fallback = null ) {
if ( isset( $list[$key] ) && is_array( $list[$key] ) ) { if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
return $list[$key]; return $list[$key];
} elseif ( is_string( $fallback ) } elseif ( is_string( $fallback )
&& isset( $list[$fallback] ) && isset( $list[$fallback] )
&& is_array( $list[$fallback] ) && is_array( $list[$fallback] )
) { ) {
return $list[$fallback]; return $list[$fallback];
} }
return []; return [];
} }
/** /**
* Get a list of file paths for all scripts in this module, in order of p roper execution. * Get a list of script file paths for this module, in order of proper ex ecution.
* *
* @param ResourceLoaderContext $context * @param ResourceLoaderContext $context
* @return array List of file paths * @return array List of file paths
*/ */
protected function getScriptFiles( ResourceLoaderContext $context ) { private function getScriptFiles( ResourceLoaderContext $context ) {
$files = array_merge( $files = array_merge(
$this->scripts, $this->scripts,
$this->getLanguageScripts( $context->getLanguage() ), $this->getLanguageScripts( $context->getLanguage() ),
self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ) self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
); );
if ( $context->getDebug() ) { if ( $context->getDebug() ) {
$files = array_merge( $files, $this->debugScripts ); $files = array_merge( $files, $this->debugScripts );
} }
return array_unique( $files, SORT_REGULAR ); return array_unique( $files, SORT_REGULAR );
skipping to change at line 720 skipping to change at line 714
return $scripts; return $scripts;
} }
} }
return []; return [];
} }
/** /**
* Get a list of file paths for all styles in this module, in order of pr oper inclusion. * Get a list of file paths for all styles in this module, in order of pr oper inclusion.
* *
* This is considered a private method. Exposed for internal use by WebIn
stallerOutput.
*
* @private
* @param ResourceLoaderContext $context * @param ResourceLoaderContext $context
* @return array List of file paths * @return array List of file paths
*/ */
public function getStyleFiles( ResourceLoaderContext $context ) { public function getStyleFiles( ResourceLoaderContext $context ) {
return array_merge_recursive( return array_merge_recursive(
self::collateFilePathListByOption( $this->styles, 'media' , 'all' ), self::collateFilePathListByOption( $this->styles, 'media' , 'all' ),
self::collateFilePathListByOption( self::collateFilePathListByOption(
self::tryForKey( $this->skinStyles, $context->get Skin(), 'default' ), self::tryForKey( $this->skinStyles, $context->get Skin(), 'default' ),
'media', 'media',
'all' 'all'
skipping to change at line 793 skipping to change at line 790
foreach ( $collatedStyleFiles as $media => $styleFiles ) { foreach ( $collatedStyleFiles as $media => $styleFiles ) {
foreach ( $styleFiles as $styleFile ) { foreach ( $styleFiles as $styleFile ) {
$result[] = $this->getLocalPath( $styleFile ); $result[] = $this->getLocalPath( $styleFile );
} }
} }
return $result; return $result;
} }
/** /**
* Gets the contents of a list of JavaScript files. * Get the contents of a list of JavaScript files. Helper for getScript() .
* *
* @param array $scripts List of file paths to scripts to read, remap and concetenate * @param array $scripts List of file paths to scripts to read, remap and concetenate
* @throws MWException
* @return string Concatenated and remapped JavaScript data from $scripts * @return string Concatenated and remapped JavaScript data from $scripts
* @throws MWException
*/ */
protected function readScriptFiles( array $scripts ) { private function readScriptFiles( array $scripts ) {
if ( empty( $scripts ) ) { if ( empty( $scripts ) ) {
return ''; return '';
} }
$js = ''; $js = '';
foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) { foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
$localPath = $this->getLocalPath( $fileName ); $localPath = $this->getLocalPath( $fileName );
if ( !file_exists( $localPath ) ) { if ( !file_exists( $localPath ) ) {
throw new MWException( __METHOD__ . ": script fil e not found: \"$localPath\"" ); throw new MWException( __METHOD__ . ": script fil e not found: \"$localPath\"" );
} }
$contents = $this->stripBom( file_get_contents( $localPat h ) ); $contents = $this->stripBom( file_get_contents( $localPat h ) );
if ( $this->getConfig()->get( 'ResourceLoaderValidateStat
icJS' ) ) {
// Static files don't really need to be checked a
s often; unlike
// on-wiki module they shouldn't change unexpecte
dly without
// admin interference.
$contents = $this->validateScriptFile( $fileName,
$contents );
}
$js .= $contents . "\n"; $js .= $contents . "\n";
} }
return $js; return $js;
} }
/** /**
* Gets the contents of a list of CSS files. * Get the contents of a list of CSS files.
* *
* @param array $styles List of media type/list of file paths pairs, to r * This is considered a private method. Exposed for internal use by WebIn
ead, remap and stallerOutput.
* concetenate
* @param bool $flip
* @param ResourceLoaderContext $context
* *
* @throws MWException * @private
* @param array $styles Map of media type to file paths to read, remap, a
nd concatenate
* @param bool $flip
* @param ResourceLoaderContext|null $context
* @return array List of concatenated and remapped CSS data from $styles, * @return array List of concatenated and remapped CSS data from $styles,
* keyed by media type * keyed by media type
* * @throws MWException
* @since 1.27 Calling this method without a ResourceLoaderContext instan ce * @since 1.27 Calling this method without a ResourceLoaderContext instan ce
* is deprecated. * is deprecated.
*/ */
public function readStyleFiles( array $styles, $flip, $context = null ) { public function readStyleFiles( array $styles, $flip, $context = null ) {
if ( $context === null ) { if ( $context === null ) {
wfDeprecated( __METHOD__ . ' without a ResourceLoader con text', '1.27' ); wfDeprecated( __METHOD__ . ' without a ResourceLoader con text', '1.27' );
$context = ResourceLoaderContext::newDummyContext(); $context = ResourceLoaderContext::newDummyContext();
} }
if ( empty( $styles ) ) { if ( empty( $styles ) ) {
skipping to change at line 962 skipping to change at line 953
* @param ResourceLoaderContext $context Context in which to generate scr ipt * @param ResourceLoaderContext $context Context in which to generate scr ipt
* @return string CSS source * @return string CSS source
*/ */
protected function compileLessFile( $fileName, ResourceLoaderContext $con text ) { protected function compileLessFile( $fileName, ResourceLoaderContext $con text ) {
static $cache; static $cache;
if ( !$cache ) { if ( !$cache ) {
$cache = ObjectCache::getLocalServerInstance( CACHE_ANYTH ING ); $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTH ING );
} }
// Construct a cache key from the LESS file name and a hash diges
t
// of the LESS variables used for compilation.
$vars = $this->getLessVars( $context ); $vars = $this->getLessVars( $context );
// Construct a cache key from the LESS file name, and a hash dige
st
// of the LESS variables used for compilation.
ksort( $vars ); ksort( $vars );
$varsHash = hash( 'md4', serialize( $vars ) ); $varsHash = hash( 'md4', serialize( $vars ) );
$cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash ) ; $cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash ) ;
$cachedCompile = $cache->get( $cacheKey ); $cachedCompile = $cache->get( $cacheKey );
// If we got a cached value, we have to validate it by getting a // If we got a cached value, we have to validate it by getting a
// checksum of all the files that were loaded by the parser and // checksum of all the files that were loaded by the parser and
// ensuring it matches the cached entry's. // ensuring it matches the cached entry's.
if ( isset( $cachedCompile['hash'] ) ) { if ( isset( $cachedCompile['hash'] ) ) {
$contentHash = FileContentsHasher::getFileContentsHash( $ cachedCompile['files'] ); $contentHash = FileContentsHasher::getFileContentsHash( $ cachedCompile['files'] );
 End of changes. 22 change blocks. 
47 lines changed or deleted 33 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)