2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* ResourceLoader module based on local JavaScript/CSS files.
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
class ResourceLoaderFileModule extends ResourceLoaderModule {
|
2010-10-19 20:59:23 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Protected Members */
|
2010-10-19 23:02:15 +00:00
|
|
|
|
2010-10-27 22:22:10 +00:00
|
|
|
/** @var {string} Local base path, see __construct() */
|
|
|
|
|
protected $localBasePath = '';
|
|
|
|
|
/** @var {string} Remote base path, see __construct() */
|
|
|
|
|
protected $remoteBasePath = '';
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of paths to JavaScript files to always include
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected $scripts = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of JavaScript files to include when using a specific language
|
|
|
|
|
* @format array( [language-code] => array( [file-path], [file-path], ... ), ... )
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected $languageScripts = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of JavaScript files to include when using a specific skin
|
|
|
|
|
* @format array( [skin-name] => array( [file-path], [file-path], ... ), ... )
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected $skinScripts = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of paths to JavaScript files to include in debug mode
|
|
|
|
|
* @format array( [skin-name] => array( [file-path], [file-path], ... ), ... )
|
|
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
protected $debugScripts = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of paths to JavaScript files to include in the startup module
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
protected $loaderScripts = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of paths to CSS files to always include
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
protected $styles = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of paths to CSS files to include when using specific skins
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected $skinStyles = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of modules this module depends on
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
protected $dependencies = array();
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} List of message keys used by this module
|
|
|
|
|
* @format array( [message-key], [message-key], ... )
|
|
|
|
|
*/
|
2010-10-26 20:17:32 +00:00
|
|
|
protected $messages = array();
|
|
|
|
|
/** @var {string} Name of group to load this module in */
|
2010-10-19 22:48:52 +00:00
|
|
|
protected $group;
|
2010-10-21 01:03:46 +00:00
|
|
|
/** @var {boolean} Link to raw files in debug mode */
|
|
|
|
|
protected $debugRaw = true;
|
2010-10-20 20:43:30 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} Cache for mtime
|
|
|
|
|
* @format array( [hash] => [mtime], [hash] => [mtime], ... )
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
protected $modifiedTime = array();
|
2010-10-27 19:59:10 +00:00
|
|
|
/**
|
|
|
|
|
* @var {array} Place where readStyleFile() tracks file dependencies
|
|
|
|
|
* @format array( [file-path], [file-path], ... )
|
|
|
|
|
*/
|
|
|
|
|
protected $localFileRefs = array();
|
2010-10-19 18:25:42 +00:00
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Constructs a new module from an options array.
|
2010-10-19 18:25:42 +00:00
|
|
|
*
|
2010-10-19 20:59:23 +00:00
|
|
|
* @param {array} $options Options array. If not given or empty, an empty module will be constructed
|
2010-10-27 22:22:10 +00:00
|
|
|
* @param {string} $localBasePath base path to prepend to all local paths in $options. Defaults to $IP
|
|
|
|
|
* @param {string} $remoteBasePath base path to prepend to all remote paths in $options. Defaults to $wgScriptPath
|
2010-10-19 20:59:23 +00:00
|
|
|
*
|
|
|
|
|
* @format $options
|
|
|
|
|
* array(
|
|
|
|
|
* // Scripts to always include
|
|
|
|
|
* 'scripts' => [file path string or array of file path strings],
|
|
|
|
|
* // Scripts to include in specific language contexts
|
2010-10-19 18:25:42 +00:00
|
|
|
* 'languageScripts' => array(
|
2010-10-19 20:59:23 +00:00
|
|
|
* [language code] => [file path string or array of file path strings],
|
2010-10-19 18:25:42 +00:00
|
|
|
* ),
|
2010-10-19 20:59:23 +00:00
|
|
|
* // Scripts to include in specific skin contexts
|
|
|
|
|
* 'skinScripts' => array(
|
|
|
|
|
* [skin name] => [file path string or array of file path strings],
|
|
|
|
|
* ),
|
|
|
|
|
* // Scripts to include in debug contexts
|
|
|
|
|
* 'debugScripts' => [file path string or array of file path strings],
|
|
|
|
|
* // Scripts to include in the startup module
|
2010-10-19 22:48:52 +00:00
|
|
|
* 'loaderScripts' => [file path string or array of file path strings],
|
2010-10-19 20:59:23 +00:00
|
|
|
* // Modules which must be loaded before this module
|
|
|
|
|
* 'dependencies' => [modile name string or array of module name strings],
|
|
|
|
|
* // Styles to always load
|
|
|
|
|
* 'styles' => [file path string or array of file path strings],
|
|
|
|
|
* // Styles to include in specific skin contexts
|
2010-10-19 18:25:42 +00:00
|
|
|
* 'skinStyles' => array(
|
2010-10-19 20:59:23 +00:00
|
|
|
* [skin name] => [file path string or array of file path strings],
|
2010-10-19 18:25:42 +00:00
|
|
|
* ),
|
2010-10-19 20:59:23 +00:00
|
|
|
* // Messages to always load
|
|
|
|
|
* 'messages' => [array of message key strings],
|
|
|
|
|
* // Group which this module should be loaded together with
|
|
|
|
|
* 'group' => [group name string],
|
2010-10-19 18:25:42 +00:00
|
|
|
* )
|
|
|
|
|
*/
|
2010-10-27 22:22:10 +00:00
|
|
|
public function __construct( $options = array(), $localBasePath = null, $remoteBasePath = null ) {
|
|
|
|
|
global $IP, $wgScriptPath;
|
|
|
|
|
$this->localBasePath = $localBasePath === null ? $IP : $localBasePath;
|
|
|
|
|
$this->remoteBasePath = $remoteBasePath === null ? $wgScriptPath : $remoteBasePath;
|
2010-10-19 20:59:23 +00:00
|
|
|
foreach ( $options as $member => $option ) {
|
|
|
|
|
switch ( $member ) {
|
|
|
|
|
// Lists of file paths
|
2010-10-19 18:25:42 +00:00
|
|
|
case 'scripts':
|
|
|
|
|
case 'debugScripts':
|
2010-10-19 22:48:52 +00:00
|
|
|
case 'loaderScripts':
|
2010-10-19 18:25:42 +00:00
|
|
|
case 'styles':
|
2010-10-27 22:22:10 +00:00
|
|
|
$this->{$member} = (array) $option;
|
2010-10-19 20:59:23 +00:00
|
|
|
break;
|
|
|
|
|
// Collated lists of file paths
|
|
|
|
|
case 'languageScripts':
|
|
|
|
|
case 'skinScripts':
|
2010-10-19 18:25:42 +00:00
|
|
|
case 'skinStyles':
|
2010-10-21 22:34:26 +00:00
|
|
|
if ( !is_array( $option ) ) {
|
|
|
|
|
throw new MWException(
|
|
|
|
|
"Invalid collated file path list error. '$option' given, array expected."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
foreach ( $option as $key => $value ) {
|
|
|
|
|
if ( !is_string( $key ) ) {
|
|
|
|
|
throw new MWException(
|
|
|
|
|
"Invalid collated file path list key error. '$key' given, string expected."
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-10-27 22:22:10 +00:00
|
|
|
$this->{$member}[$key] = (array) $value;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2010-10-21 22:34:26 +00:00
|
|
|
break;
|
2010-10-19 20:59:23 +00:00
|
|
|
// Lists of strings
|
2010-10-19 18:25:42 +00:00
|
|
|
case 'dependencies':
|
|
|
|
|
case 'messages':
|
2010-10-19 20:59:23 +00:00
|
|
|
$this->{$member} = (array) $option;
|
2010-10-19 18:25:42 +00:00
|
|
|
break;
|
2010-10-19 20:59:23 +00:00
|
|
|
// Single strings
|
2010-10-19 18:25:42 +00:00
|
|
|
case 'group':
|
2010-10-21 01:03:46 +00:00
|
|
|
$this->{$member} = (string) $option;
|
|
|
|
|
break;
|
|
|
|
|
// Single booleans
|
|
|
|
|
case 'debugRaw':
|
|
|
|
|
$this->{$member} = (bool) $option;
|
2010-10-19 18:25:42 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets all scripts for a given context concatenated together.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @param {ResourceLoaderContext} $context Context in which to generate script
|
|
|
|
|
* @return {string} JavaScript code for $context
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2010-10-31 15:35:01 +00:00
|
|
|
global $wgServer;
|
2010-10-21 01:03:46 +00:00
|
|
|
|
|
|
|
|
$files = array_merge(
|
|
|
|
|
$this->scripts,
|
|
|
|
|
self::tryForKey( $this->languageScripts, $context->getLanguage() ),
|
|
|
|
|
self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
|
|
|
|
|
);
|
2010-10-19 22:48:52 +00:00
|
|
|
if ( $context->getDebug() ) {
|
2010-10-21 01:03:46 +00:00
|
|
|
$files = array_merge( $files, $this->debugScripts );
|
|
|
|
|
if ( $this->debugRaw ) {
|
2010-10-21 21:25:27 +00:00
|
|
|
$script = '';
|
2010-10-21 01:03:46 +00:00
|
|
|
foreach ( $files as $file ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$path = $wgServer . $this->getRemotePath( $file );
|
|
|
|
|
$script .= "\n\t" . Xml::encodeJsCall( 'mediaWiki.loader.load', array( $path ) );
|
2010-10-21 01:03:46 +00:00
|
|
|
}
|
2010-10-21 21:25:27 +00:00
|
|
|
return $script;
|
2010-10-21 01:03:46 +00:00
|
|
|
}
|
2010-10-19 22:48:52 +00:00
|
|
|
}
|
2010-10-27 22:22:10 +00:00
|
|
|
return $this->readScriptFiles( $files );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets loader script.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @return {string} JavaScript code to be added to startup module
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-19 22:48:52 +00:00
|
|
|
public function getLoaderScript() {
|
2010-10-19 23:00:52 +00:00
|
|
|
if ( count( $this->loaderScripts ) == 0 ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-10-27 22:22:10 +00:00
|
|
|
return $this->readScriptFiles( $this->loaderScripts );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets all styles for a given context concatenated together.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @param {ResourceLoaderContext} $context Context in which to generate styles
|
|
|
|
|
* @return {string} CSS code for $context
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
public function getStyles( ResourceLoaderContext $context ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
// Merge general styles and skin specific styles, retaining media type collation
|
2010-10-27 19:59:10 +00:00
|
|
|
$styles = $this->readStyleFiles( $this->styles );
|
|
|
|
|
$skinStyles = $this->readStyleFiles( self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ) );
|
2010-10-21 22:34:26 +00:00
|
|
|
|
2010-10-19 22:48:52 +00:00
|
|
|
foreach ( $skinStyles as $media => $style ) {
|
|
|
|
|
if ( isset( $styles[$media] ) ) {
|
|
|
|
|
$styles[$media] .= $style;
|
|
|
|
|
} else {
|
|
|
|
|
$styles[$media] = $style;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Collect referenced files
|
2010-10-27 19:59:10 +00:00
|
|
|
$this->localFileRefs = array_unique( $this->localFileRefs );
|
2010-10-19 22:48:52 +00:00
|
|
|
// If the list has been modified since last time we cached it, update the cache
|
2010-10-27 19:59:10 +00:00
|
|
|
if ( $this->localFileRefs !== $this->getFileDependencies( $context->getSkin() ) ) {
|
2010-10-19 18:25:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
$dbw->replace( 'module_deps',
|
|
|
|
|
array( array( 'md_module', 'md_skin' ) ), array(
|
|
|
|
|
'md_module' => $this->getName(),
|
|
|
|
|
'md_skin' => $context->getSkin(),
|
2010-10-27 19:59:10 +00:00
|
|
|
'md_deps' => FormatJson::encode( $this->localFileRefs ),
|
2010-10-19 18:25:42 +00:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return $styles;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 22:48:52 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets list of message keys used by this module.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @return {array} List of message keys
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getMessages() {
|
|
|
|
|
return $this->messages;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 22:48:52 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets the name of the group this module should be loaded in.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @return {string} Group name
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getGroup() {
|
|
|
|
|
return $this->group;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 22:48:52 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets list of names of modules this module depends on.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @return {array} List of module names
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getDependencies() {
|
|
|
|
|
return $this->dependencies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Get the last modified timestamp of this module.
|
|
|
|
|
*
|
|
|
|
|
* Last modified timestamps are calculated from the highest last modified timestamp of this module's constituent
|
|
|
|
|
* files as well as the files it depends on. This function is context-sensitive, only performing calculations on
|
|
|
|
|
* files relevant to the given language, skin and debug mode.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @param {ResourceLoaderContext} $context Context in which to calculate the modified time
|
|
|
|
|
* @return {integer} UNIX timestamp
|
|
|
|
|
* @see {ResourceLoaderModule::getFileDependencies}
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
|
|
|
|
if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
|
|
|
|
|
return $this->modifiedTime[$context->getHash()];
|
|
|
|
|
}
|
|
|
|
|
wfProfileIn( __METHOD__ );
|
|
|
|
|
|
2010-10-19 23:47:56 +00:00
|
|
|
$files = array();
|
|
|
|
|
|
|
|
|
|
// Flatten style files into $files
|
|
|
|
|
$styles = self::collateFilePathListByOption( $this->styles, 'media', 'all' );
|
|
|
|
|
foreach ( $styles as $styleFiles ) {
|
|
|
|
|
$files = array_merge( $files, $styleFiles );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2010-10-19 22:48:52 +00:00
|
|
|
$skinFiles = self::tryForKey(
|
|
|
|
|
self::collateFilePathListByOption( $this->skinStyles, 'media', 'all' ), $context->getSkin(), 'default'
|
2010-10-19 18:25:42 +00:00
|
|
|
);
|
|
|
|
|
foreach ( $skinFiles as $styleFiles ) {
|
2010-10-19 23:47:56 +00:00
|
|
|
$files = array_merge( $files, $styleFiles );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Final merge, this should result in a master list of dependent files
|
|
|
|
|
$files = array_merge(
|
2010-10-19 23:47:56 +00:00
|
|
|
$files,
|
2010-10-19 18:25:42 +00:00
|
|
|
$this->scripts,
|
|
|
|
|
$context->getDebug() ? $this->debugScripts : array(),
|
2010-10-19 22:48:52 +00:00
|
|
|
self::tryForKey( $this->languageScripts, $context->getLanguage() ),
|
|
|
|
|
self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ),
|
2010-10-27 22:22:10 +00:00
|
|
|
$this->loaderScripts
|
2010-10-19 18:25:42 +00:00
|
|
|
);
|
2010-10-27 22:22:10 +00:00
|
|
|
$files = array_map( array( $this, 'getLocalPath' ), $files );
|
|
|
|
|
// File deps need to be treated separately because they're already prefixed
|
|
|
|
|
$files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
|
2010-10-20 20:43:30 +00:00
|
|
|
// If a module is nothing but a list of dependencies, we need to avoid giving max() an empty array
|
|
|
|
|
if ( count( $files ) === 0 ) {
|
|
|
|
|
return $this->modifiedTime[$context->getHash()] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
wfProfileIn( __METHOD__.'-filemtime' );
|
2010-10-27 22:22:10 +00:00
|
|
|
$filesMtime = max( array_map( 'filemtime', $files ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
wfProfileOut( __METHOD__.'-filemtime' );
|
|
|
|
|
$this->modifiedTime[$context->getHash()] = max( $filesMtime, $this->getMsgBlobMtime( $context->getLanguage() ) );
|
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $this->modifiedTime[$context->getHash()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Protected Members */
|
|
|
|
|
|
2010-10-27 22:22:10 +00:00
|
|
|
protected function getLocalPath( $path ) {
|
|
|
|
|
return "{$this->localBasePath}/$path";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getRemotePath( $path ) {
|
|
|
|
|
return "{$this->remoteBasePath}/$path";
|
2010-10-19 20:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Collates file paths by option (where provided).
|
2010-10-19 20:59:23 +00:00
|
|
|
*
|
|
|
|
|
* @param {array} $list List of file paths in any combination of index/path or path/options pairs
|
2010-10-19 22:48:52 +00:00
|
|
|
* @return {array} List of file paths, collated by $option
|
2010-10-19 20:59:23 +00:00
|
|
|
*/
|
|
|
|
|
protected static function collateFilePathListByOption( array $list, $option, $default ) {
|
|
|
|
|
$collatedFiles = array();
|
|
|
|
|
foreach ( (array) $list as $key => $value ) {
|
|
|
|
|
if ( is_int( $key ) ) {
|
|
|
|
|
// File name as the value
|
|
|
|
|
if ( !isset( $collatedFiles[$default] ) ) {
|
|
|
|
|
$collatedFiles[$default] = array();
|
|
|
|
|
}
|
|
|
|
|
$collatedFiles[$default][] = $value;
|
|
|
|
|
} else if ( is_array( $value ) ) {
|
|
|
|
|
// File name as the key, options array as the value
|
2010-10-20 20:43:30 +00:00
|
|
|
$optionValue = isset( $value[$option] ) ? $value[$option] : $default;
|
|
|
|
|
if ( !isset( $collatedFiles[$optionValue] ) ) {
|
|
|
|
|
$collatedFiles[$optionValue] = array();
|
2010-10-19 20:59:23 +00:00
|
|
|
}
|
2010-10-20 20:43:30 +00:00
|
|
|
$collatedFiles[$optionValue][] = $key;
|
2010-10-19 20:59:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $collatedFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets a list of element that match a key, optionally using a fallback key.
|
2010-10-19 23:02:15 +00:00
|
|
|
*
|
2010-10-20 20:56:33 +00:00
|
|
|
* @param {array} $list List of lists to select from
|
2010-10-19 22:48:52 +00:00
|
|
|
* @param {string} $key Key to look for in $map
|
2010-10-20 20:56:33 +00:00
|
|
|
* @param {string} $fallback Key to look for in $list if $key doesn't exist
|
2010-10-19 22:48:52 +00:00
|
|
|
* @return {array} List of elements from $map which matched $key or $fallback, or an empty list in case of no match
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-20 20:56:33 +00:00
|
|
|
protected static function tryForKey( array $list, $key, $fallback = null ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
|
2010-10-20 20:56:33 +00:00
|
|
|
return $list[$key];
|
|
|
|
|
} else if ( is_string( $fallback ) && isset( $list[$fallback] ) && is_array( $list[$fallback] ) ) {
|
|
|
|
|
return $list[$fallback];
|
2010-10-19 22:48:52 +00:00
|
|
|
}
|
|
|
|
|
return array();
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets the contents of a list of JavaScript files.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @param {array} $scripts List of file paths to scripts to read, remap and concetenate
|
|
|
|
|
* @return {string} Concatenated and remapped JavaScript data from $scripts
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-27 22:22:10 +00:00
|
|
|
protected function readScriptFiles( array $scripts ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
if ( empty( $scripts ) ) {
|
2010-10-19 18:25:42 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2010-10-27 22:22:10 +00:00
|
|
|
return implode( "\n", array_map( 'file_get_contents', array_map( array( $this, 'getLocalPath' ), array_unique( $scripts ) ) ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Gets the contents of a list of CSS files.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* @param {array} $styles List of file paths to styles to read, remap and concetenate
|
|
|
|
|
* @return {array} List of concatenated and remapped CSS data from $styles, keyed by media type
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-27 19:59:10 +00:00
|
|
|
protected function readStyleFiles( array $styles ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
if ( empty( $styles ) ) {
|
|
|
|
|
return array();
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2010-10-19 20:59:23 +00:00
|
|
|
$styles = self::collateFilePathListByOption( $styles, 'media', 'all' );
|
2010-10-19 18:25:42 +00:00
|
|
|
foreach ( $styles as $media => $files ) {
|
2010-10-19 22:48:52 +00:00
|
|
|
$styles[$media] = implode(
|
2010-10-27 19:59:10 +00:00
|
|
|
"\n", array_map( array( $this, 'readStyleFile' ), array_unique( $files ) )
|
2010-10-19 22:48:52 +00:00
|
|
|
);
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
return $styles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-20 00:22:25 +00:00
|
|
|
* Reads a style file.
|
2010-10-19 22:48:52 +00:00
|
|
|
*
|
|
|
|
|
* This method can be used as a callback for array_map()
|
|
|
|
|
*
|
|
|
|
|
* @param {string} $path File path of script file to read
|
|
|
|
|
* @return {string} CSS data in script file
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
2010-10-31 15:35:01 +00:00
|
|
|
protected function readStyleFile( $path ) {
|
2010-10-27 22:22:10 +00:00
|
|
|
$style = file_get_contents( $this->getLocalPath( $path ) );
|
|
|
|
|
$dir = $this->getLocalPath( dirname( $path ) );
|
|
|
|
|
$remoteDir = $this->getRemotePath( dirname( $path ) );
|
2010-10-27 19:59:10 +00:00
|
|
|
// Get and register local file references
|
|
|
|
|
$this->localFileRefs = array_merge( $this->localFileRefs, CSSMin::getLocalFileReferences( $style, $dir ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
return CSSMin::remap(
|
2010-10-27 22:22:10 +00:00
|
|
|
$style, $dir, $remoteDir, true
|
2010-10-19 18:25:42 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|