protected $remoteBasePath = '';
/** @var array Saves a list of the templates named by the modules. */
- protected $templates = array();
+ protected $templates = [];
/**
* @var array List of paths to JavaScript files to always include
* array( [file-path], [file-path], ... )
* @endcode
*/
- protected $scripts = array();
+ protected $scripts = [];
/**
* @var array List of JavaScript files to include when using a specific language
* array( [language-code] => array( [file-path], [file-path], ... ), ... )
* @endcode
*/
- protected $languageScripts = array();
+ protected $languageScripts = [];
/**
* @var array List of JavaScript files to include when using a specific skin
* array( [skin-name] => array( [file-path], [file-path], ... ), ... )
* @endcode
*/
- protected $skinScripts = array();
+ protected $skinScripts = [];
/**
* @var array List of paths to JavaScript files to include in debug mode
* array( [skin-name] => array( [file-path], [file-path], ... ), ... )
* @endcode
*/
- protected $debugScripts = array();
+ protected $debugScripts = [];
/**
* @var array List of paths to CSS files to always include
* array( [file-path], [file-path], ... )
* @endcode
*/
- protected $styles = array();
+ protected $styles = [];
/**
* @var array List of paths to CSS files to include when using specific skins
* array( [file-path], [file-path], ... )
* @endcode
*/
- protected $skinStyles = array();
+ protected $skinStyles = [];
/**
* @var array List of modules this module depends on
* array( [file-path], [file-path], ... )
* @endcode
*/
- protected $dependencies = array();
+ protected $dependencies = [];
/**
* @var string File name containing the body of the skip function
* array( [message-key], [message-key], ... )
* @endcode
*/
- protected $messages = array();
+ protected $messages = [];
/** @var string Name of group to load this module in */
protected $group;
/** @var bool Whether mw.loader.state() call should be omitted */
protected $raw = false;
- protected $targets = array( 'desktop' );
+ protected $targets = [ 'desktop' ];
/**
* @var bool Whether getStyleURLsForDebug should return raw file paths,
* array( [file-path], [file-path], ... )
* @endcode
*/
- protected $localFileRefs = array();
+ protected $localFileRefs = [];
/**
* @var array Place where readStyleFile() tracks file dependencies for non-existent files.
* Used in tests to detect missing dependencies.
*/
- protected $missingLocalFileRefs = array();
+ protected $missingLocalFileRefs = [];
/* Methods */
* @endcode
*/
public function __construct(
- $options = array(),
+ $options = [],
$localBasePath = null,
$remoteBasePath = null
) {
* @return array Array( localBasePath, remoteBasePath )
*/
public static function extractBasePaths(
- $options = array(),
+ $options = [],
$localBasePath = null,
$remoteBasePath = null
) {
$remoteBasePath = (string)$options['remoteBasePath'];
}
- // Make sure the remote base path is a complete valid URL,
- // but possibly protocol-relative to avoid cache pollution
- $remoteBasePath = wfExpandUrl( $remoteBasePath, PROTO_RELATIVE );
-
- return array( $localBasePath, $remoteBasePath );
+ return [ $localBasePath, $remoteBasePath ];
}
/**
* @return array
*/
public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
- $urls = array();
+ $urls = [];
foreach ( $this->getScriptFiles( $context ) as $file ) {
- $urls[] = $this->getRemotePath( $file );
+ $urls[] = OutputPage::transformResourcePath(
+ $this->getConfig(),
+ $this->getRemotePath( $file )
+ );
}
return $urls;
}
}
// Our module consists entirely of real css files,
// in debug mode we can load those directly.
- $urls = array();
+ $urls = [];
foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
- $urls[$mediaType] = array();
+ $urls[$mediaType] = [];
foreach ( $list as $file ) {
- $urls[$mediaType][] = $this->getRemotePath( $file );
+ $urls[$mediaType][] = OutputPage::transformResourcePath(
+ $this->getConfig(),
+ $this->getRemotePath( $file )
+ );
}
}
return $urls;
/**
* Gets list of names of modules this module depends on.
- * @param ResourceLoaderContext context
+ * @param ResourceLoaderContext|null $context
* @return array List of module names
*/
public function getDependencies( ResourceLoaderContext $context = null ) {
* @return array
*/
protected function getFileHashes( ResourceLoaderContext $context ) {
- $files = array();
+ $files = [];
// Flatten style files into $files
$styles = self::collateFilePathListByOption( $this->styles, 'media', 'all' );
$files,
$this->scripts,
$this->templates,
- $context->getDebug() ? $this->debugScripts : array(),
+ $context->getDebug() ? $this->debugScripts : [],
$this->getLanguageScripts( $context->getLanguage() ),
self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
);
if ( $this->skipFunction ) {
$files[] = $this->skipFunction;
}
- $files = array_map( array( $this, 'getLocalPath' ), $files );
+ $files = array_map( [ $this, 'getLocalPath' ], $files );
// File deps need to be treated separately because they're already prefixed
$files = array_merge( $files, $this->getFileDependencies( $context ) );
// Filter out any duplicates from getFileDependencies() and others.
// Don't include keys or file paths here, only the hashes. Including that would needlessly
// cause global cache invalidation when files move or if e.g. the MediaWiki path changes.
// Any significant ordering is already detected by the definition summary.
- return array_map( array( __CLASS__, 'safeFileHash' ), $files );
+ return array_map( [ __CLASS__, 'safeFileHash' ], $files );
}
/**
public function getDefinitionSummary( ResourceLoaderContext $context ) {
$summary = parent::getDefinitionSummary( $context );
- $options = array();
- foreach ( array(
+ $options = [];
+ foreach ( [
// The following properties are omitted because they don't affect the module reponse:
// - localBasePath (Per T104950; Changes when absolute directory name changes. If
// this affects 'scripts' and other file paths, getFileHashes accounts for that.)
'skipFunction',
'debugRaw',
'raw',
- ) as $member ) {
+ ] as $member ) {
$options[$member] = $this->{$member};
};
- $summary[] = array(
+ $summary[] = [
'options' => $options,
'fileHashes' => $this->getFileHashes( $context ),
- 'msgBlobMtime' => $this->getMsgBlobMtime( $context->getLanguage() ),
- );
+ 'messageBlob' => $this->getMessageBlob( $context ),
+ ];
return $summary;
}
* @return array List of file paths, collated by $option
*/
protected static function collateFilePathListByOption( array $list, $option, $default ) {
- $collatedFiles = array();
+ $collatedFiles = [];
foreach ( (array)$list as $key => $value ) {
if ( is_int( $key ) ) {
// File name as the value
if ( !isset( $collatedFiles[$default] ) ) {
- $collatedFiles[$default] = array();
+ $collatedFiles[$default] = [];
}
$collatedFiles[$default][] = $value;
} elseif ( is_array( $value ) ) {
// File name as the key, options array as the value
$optionValue = isset( $value[$option] ) ? $value[$option] : $default;
if ( !isset( $collatedFiles[$optionValue] ) ) {
- $collatedFiles[$optionValue] = array();
+ $collatedFiles[$optionValue] = [];
}
$collatedFiles[$optionValue][] = $key;
}
) {
return $list[$fallback];
}
- return array();
+ return [];
}
/**
}
}
- return array();
+ return [];
}
/**
* @return array A list of file paths collated by media type
*/
protected function getAllSkinStyleFiles() {
- $styleFiles = array();
+ $styleFiles = [];
$internalSkinNames = array_keys( Skin::getSkinNames() );
$internalSkinNames[] = 'default';
$this->getAllSkinStyleFiles()
);
- $result = array();
+ $result = [];
foreach ( $collatedStyleFiles as $media => $styleFiles ) {
foreach ( $styleFiles as $styleFile ) {
}
if ( empty( $styles ) ) {
- return array();
+ return [];
}
foreach ( $styles as $media => $files ) {
$uniqueFiles = array_unique( $files, SORT_REGULAR );
- $styleFiles = array();
+ $styleFiles = [];
foreach ( $uniqueFiles as $file ) {
$styleFiles[] = $this->readStyleFile( $file, $flip, $context );
}
}
}
return MemoizedCallable::call( 'CSSMin::remap',
- array( $style, $localDir, $remoteDir, true ) );
+ [ $style, $localDir, $remoteDir, true ] );
}
/**
}
}
- $compiler = ResourceLoader::getLessCompiler( $this->getConfig(), $vars );
+ $compiler = $context->getResourceLoader()->getLessCompiler( $vars );
$css = $compiler->parseFile( $fileName )->getCss();
$files = $compiler->AllParsedFiles();
$this->localFileRefs = array_merge( $this->localFileRefs, $files );
- $cache->set( $cacheKey, array(
+ $cache->set( $cacheKey, [
'css' => $css,
'files' => $files,
'hash' => FileContentsHasher::getFileContentsHash( $files ),
- ), 60 * 60 * 24 ); // 86400 seconds, or 24 hours.
+ ], 60 * 60 * 24 ); // 86400 seconds, or 24 hours.
return $css;
}
* @throws MWException
*/
public function getTemplates() {
- $templates = array();
+ $templates = [];
foreach ( $this->templates as $alias => $templatePath ) {
// Alias is optional