* 'loaderScripts' => [file path string or array of file path strings],
* // Modules which must be loaded before this module
* 'dependencies' => [module name string or array of module name strings],
+ * 'templates' => array(
+ * [template alias with file.ext] => [file path to a template file],
+ * ),
* // Styles to always load
* 'styles' => [file path string or array of file path strings],
* // Styles to include in specific skin contexts
$localBasePath = null,
$remoteBasePath = null
) {
+ // Flag to decide whether to automagically add the mediawiki.template module
+ $hasTemplates = false;
// localBasePath and remoteBasePath both have unbelievably long fallback chains
// and need to be handled separately.
list( $this->localBasePath, $this->remoteBasePath ) =
case 'styles':
$this->{$member} = (array)$option;
break;
+ case 'templates':
+ $hasTemplates = true;
+ $this->{$member} = (array)$option;
+ break;
// Collated lists of file paths
case 'languageScripts':
case 'skinScripts':
$this->{$member} = $option;
break;
- // templates
- case 'templates':
- $this->{$member} = (array) $option;
- break;
// Single strings
case 'group':
case 'position':
break;
}
}
+ if ( $hasTemplates ) {
+ $this->dependencies[] = 'mediawiki.template';
+ }
}
/**
/**
* Get the skip function.
- *
- * @return string|null
+ * @return null|string
+ * @throws MWException
*/
public function getSkipFunction() {
if ( !$this->skipFunction ) {
if ( isset( $this->modifiedTime[$context->getHash()] ) ) {
return $this->modifiedTime[$context->getHash()];
}
- wfProfileIn( __METHOD__ );
$files = array();
$files = array_merge(
$files,
$this->scripts,
+ $this->templates,
$context->getDebug() ? $this->debugScripts : array(),
$this->getLanguageScripts( $context->getLanguage() ),
self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' ),
$files[] = $this->skipFunction;
}
$files = array_map( array( $this, 'getLocalPath' ), $files );
- // Templates
- $templateFiles = array_map( array( $this, 'getLocalPath' ), $this->templates );
- $files = array_merge( $files, $templateFiles );
// File deps need to be treated separately because they're already prefixed
$files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) );
// giving max() an empty array
if ( count( $files ) === 0 ) {
$this->modifiedTime[$context->getHash()] = 1;
- wfProfileOut( __METHOD__ );
return $this->modifiedTime[$context->getHash()];
}
- wfProfileIn( __METHOD__ . '-filemtime' );
$filesMtime = max( array_map( array( __CLASS__, 'safeFilemtime' ), $files ) );
- wfProfileOut( __METHOD__ . '-filemtime' );
$this->modifiedTime[$context->getHash()] = max(
$filesMtime,
$this->getDefinitionMtime( $context )
);
- wfProfileOut( __METHOD__ );
return $this->modifiedTime[$context->getHash()];
}
'dependencies',
'messages',
'targets',
+ 'templates',
'group',
'position',
'skipFunction',
}
/**
- * Takes named templates by the module and adds them to the JavaScript output
- *
+ * Takes named templates by the module and returns an array mapping.
* @return array of templates mapping template alias to content
+ * @throws MWException
*/
- function getTemplates() {
+ public function getTemplates() {
$templates = array();
- foreach( $this->templates as $alias => $templatePath ) {
+ foreach ( $this->templates as $alias => $templatePath ) {
// Alias is optional
if ( is_int( $alias ) ) {
$alias = $templatePath;
$localPath = $this->getLocalPath( $templatePath );
if ( file_exists( $localPath ) ) {
$content = file_get_contents( $localPath );
- $templates[ $alias ] = $content;
+ $templates[$alias] = $content;
+ } else {
+ $msg = __METHOD__ . ": template file not found: \"$localPath\"";
+ wfDebugLog( 'resourceloader', $msg );
+ throw new MWException( $msg );
}
}
return $templates;