3 * Resource loader module based on local JavaScript/CSS files.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Trevor Parscal
22 * @author Roan Kattouw
26 * ResourceLoader module based on local JavaScript/CSS files.
28 class ResourceLoaderFileModule
extends ResourceLoaderModule
{
29 /* Protected Members */
31 /** @var string Local base path, see __construct() */
32 protected $localBasePath = '';
34 /** @var string Remote base path, see __construct() */
35 protected $remoteBasePath = '';
37 /** @var array Saves a list of the templates named by the modules. */
38 protected $templates = array();
41 * @var array List of paths to JavaScript files to always include
44 * array( [file-path], [file-path], ... )
47 protected $scripts = array();
50 * @var array List of JavaScript files to include when using a specific language
53 * array( [language-code] => array( [file-path], [file-path], ... ), ... )
56 protected $languageScripts = array();
59 * @var array List of JavaScript files to include when using a specific skin
62 * array( [skin-name] => array( [file-path], [file-path], ... ), ... )
65 protected $skinScripts = array();
68 * @var array List of paths to JavaScript files to include in debug mode
71 * array( [skin-name] => array( [file-path], [file-path], ... ), ... )
74 protected $debugScripts = array();
77 * @var array List of paths to JavaScript files to include in the startup module
80 * array( [file-path], [file-path], ... )
83 protected $loaderScripts = array();
86 * @var array List of paths to CSS files to always include
89 * array( [file-path], [file-path], ... )
92 protected $styles = array();
95 * @var array List of paths to CSS files to include when using specific skins
98 * array( [file-path], [file-path], ... )
101 protected $skinStyles = array();
104 * @var array List of modules this module depends on
107 * array( [file-path], [file-path], ... )
110 protected $dependencies = array();
113 * @var string File name containing the body of the skip function
115 protected $skipFunction = null;
118 * @var array List of message keys used by this module
121 * array( [message-key], [message-key], ... )
124 protected $messages = array();
126 /** @var string Name of group to load this module in */
129 /** @var string Position on the page to load this module at */
130 protected $position = 'bottom';
132 /** @var bool Link to raw files in debug mode */
133 protected $debugRaw = true;
135 /** @var bool Whether mw.loader.state() call should be omitted */
136 protected $raw = false;
138 protected $targets = array( 'desktop' );
141 * @var bool Whether getStyleURLsForDebug should return raw file paths,
142 * or return load.php urls
144 protected $hasGeneratedStyles = false;
147 * @var array Place where readStyleFile() tracks file dependencies
150 * array( [file-path], [file-path], ... )
153 protected $localFileRefs = array();
158 * Constructs a new module from an options array.
160 * @param array $options List of options; if not given or empty, an empty module will be
162 * @param string $localBasePath Base path to prepend to all local paths in $options. Defaults
164 * @param string $remoteBasePath Base path to prepend to all remote paths in $options. Defaults
165 * to $wgResourceBasePath
167 * Below is a description for the $options array:
168 * @throws InvalidArgumentException
169 * @par Construction options:
172 * // Base path to prepend to all local paths in $options. Defaults to $IP
173 * 'localBasePath' => [base path],
174 * // Base path to prepend to all remote paths in $options. Defaults to $wgResourceBasePath
175 * 'remoteBasePath' => [base path],
176 * // Equivalent of remoteBasePath, but relative to $wgExtensionAssetsPath
177 * 'remoteExtPath' => [base path],
178 * // Equivalent of remoteBasePath, but relative to $wgStylePath
179 * 'remoteSkinPath' => [base path],
180 * // Scripts to always include
181 * 'scripts' => [file path string or array of file path strings],
182 * // Scripts to include in specific language contexts
183 * 'languageScripts' => array(
184 * [language code] => [file path string or array of file path strings],
186 * // Scripts to include in specific skin contexts
187 * 'skinScripts' => array(
188 * [skin name] => [file path string or array of file path strings],
190 * // Scripts to include in debug contexts
191 * 'debugScripts' => [file path string or array of file path strings],
192 * // Scripts to include in the startup module
193 * 'loaderScripts' => [file path string or array of file path strings],
194 * // Modules which must be loaded before this module
195 * 'dependencies' => [module name string or array of module name strings],
196 * 'templates' => array(
197 * [template alias with file.ext] => [file path to a template file],
199 * // Styles to always load
200 * 'styles' => [file path string or array of file path strings],
201 * // Styles to include in specific skin contexts
202 * 'skinStyles' => array(
203 * [skin name] => [file path string or array of file path strings],
205 * // Messages to always load
206 * 'messages' => [array of message key strings],
207 * // Group which this module should be loaded together with
208 * 'group' => [group name string],
209 * // Position on the page to load this module at
210 * 'position' => ['bottom' (default) or 'top']
211 * // Function that, if it returns true, makes the loader skip this module.
212 * // The file must contain valid JavaScript for execution in a private function.
213 * // The file must not contain the "function () {" and "}" wrapper though.
214 * 'skipFunction' => [file path]
218 public function __construct(
220 $localBasePath = null,
221 $remoteBasePath = null
223 // Flag to decide whether to automagically add the mediawiki.template module
224 $hasTemplates = false;
225 // localBasePath and remoteBasePath both have unbelievably long fallback chains
226 // and need to be handled separately.
227 list( $this->localBasePath
, $this->remoteBasePath
) =
228 self
::extractBasePaths( $options, $localBasePath, $remoteBasePath );
230 // Extract, validate and normalise remaining options
231 foreach ( $options as $member => $option ) {
233 // Lists of file paths
236 case 'loaderScripts':
238 $this->{$member} = (array)$option;
241 $hasTemplates = true;
242 $this->{$member} = (array)$option;
244 // Collated lists of file paths
245 case 'languageScripts':
248 if ( !is_array( $option ) ) {
249 throw new InvalidArgumentException(
250 "Invalid collated file path list error. " .
251 "'$option' given, array expected."
254 foreach ( $option as $key => $value ) {
255 if ( !is_string( $key ) ) {
256 throw new InvalidArgumentException(
257 "Invalid collated file path list key error. " .
258 "'$key' given, string expected."
261 $this->{$member}[$key] = (array)$value;
269 $option = array_values( array_unique( (array)$option ) );
272 $this->{$member} = $option;
276 $this->isPositionDefined
= true;
279 $this->{$member} = (string)$option;
284 $this->{$member} = (bool)$option;
288 if ( $hasTemplates ) {
289 $this->dependencies
[] = 'mediawiki.template';
290 // Ensure relevant template compiler module gets loaded
291 foreach ( $this->templates
as $alias => $templatePath ) {
292 if ( is_int( $alias ) ) {
293 $alias = $templatePath;
295 $suffix = explode( '.', $alias );
296 $suffix = end( $suffix );
297 $compilerModule = 'mediawiki.template.' . $suffix;
298 if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies
) ) {
299 $this->dependencies
[] = $compilerModule;
306 * Extract a pair of local and remote base paths from module definition information.
307 * Implementation note: the amount of global state used in this function is staggering.
309 * @param array $options Module definition
310 * @param string $localBasePath Path to use if not provided in module definition. Defaults
312 * @param string $remoteBasePath Path to use if not provided in module definition. Defaults
313 * to $wgResourceBasePath
314 * @return array Array( localBasePath, remoteBasePath )
316 public static function extractBasePaths(
318 $localBasePath = null,
319 $remoteBasePath = null
321 global $IP, $wgResourceBasePath;
323 // The different ways these checks are done, and their ordering, look very silly,
324 // but were preserved for backwards-compatibility just in case. Tread lightly.
326 if ( $localBasePath === null ) {
327 $localBasePath = $IP;
329 if ( $remoteBasePath === null ) {
330 $remoteBasePath = $wgResourceBasePath;
333 if ( isset( $options['remoteExtPath'] ) ) {
334 global $wgExtensionAssetsPath;
335 $remoteBasePath = $wgExtensionAssetsPath . '/' . $options['remoteExtPath'];
338 if ( isset( $options['remoteSkinPath'] ) ) {
340 $remoteBasePath = $wgStylePath . '/' . $options['remoteSkinPath'];
343 if ( array_key_exists( 'localBasePath', $options ) ) {
344 $localBasePath = (string)$options['localBasePath'];
347 if ( array_key_exists( 'remoteBasePath', $options ) ) {
348 $remoteBasePath = (string)$options['remoteBasePath'];
351 // Make sure the remote base path is a complete valid URL,
352 // but possibly protocol-relative to avoid cache pollution
353 $remoteBasePath = wfExpandUrl( $remoteBasePath, PROTO_RELATIVE
);
355 return array( $localBasePath, $remoteBasePath );
359 * Gets all scripts for a given context concatenated together.
361 * @param ResourceLoaderContext $context Context in which to generate script
362 * @return string JavaScript code for $context
364 public function getScript( ResourceLoaderContext
$context ) {
365 $files = $this->getScriptFiles( $context );
366 return $this->readScriptFiles( $files );
370 * @param ResourceLoaderContext $context
373 public function getScriptURLsForDebug( ResourceLoaderContext
$context ) {
375 foreach ( $this->getScriptFiles( $context ) as $file ) {
376 $urls[] = $this->getRemotePath( $file );
384 public function supportsURLLoading() {
385 return $this->debugRaw
;
391 * @return string|bool JavaScript code to be added to startup module
393 public function getLoaderScript() {
394 if ( count( $this->loaderScripts
) === 0 ) {
397 return $this->readScriptFiles( $this->loaderScripts
);
401 * Get all styles for a given context.
403 * @param ResourceLoaderContext $context
404 * @return array CSS code for $context as an associative array mapping media type to CSS text.
406 public function getStyles( ResourceLoaderContext
$context ) {
407 $styles = $this->readStyleFiles(
408 $this->getStyleFiles( $context ),
409 $this->getFlip( $context ),
412 // Collect referenced files
413 $this->localFileRefs
= array_unique( $this->localFileRefs
);
414 // If the list has been modified since last time we cached it, update the cache
416 if ( $this->localFileRefs
!== $this->getFileDependencies( $context->getSkin() ) ) {
417 $dbw = wfGetDB( DB_MASTER
);
418 $dbw->replace( 'module_deps',
419 array( array( 'md_module', 'md_skin' ) ), array(
420 'md_module' => $this->getName(),
421 'md_skin' => $context->getSkin(),
422 'md_deps' => FormatJson
::encode( $this->localFileRefs
),
426 } catch ( Exception
$e ) {
427 wfDebugLog( 'resourceloader', __METHOD__
. ": failed to update DB: $e" );
433 * @param ResourceLoaderContext $context
436 public function getStyleURLsForDebug( ResourceLoaderContext
$context ) {
437 if ( $this->hasGeneratedStyles
) {
438 // Do the default behaviour of returning a url back to load.php
439 // but with only=styles.
440 return parent
::getStyleURLsForDebug( $context );
442 // Our module consists entirely of real css files,
443 // in debug mode we can load those directly.
445 foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
446 $urls[$mediaType] = array();
447 foreach ( $list as $file ) {
448 $urls[$mediaType][] = $this->getRemotePath( $file );
455 * Gets list of message keys used by this module.
457 * @return array List of message keys
459 public function getMessages() {
460 return $this->messages
;
464 * Gets the name of the group this module should be loaded in.
466 * @return string Group name
468 public function getGroup() {
475 public function getPosition() {
476 return $this->position
;
480 * Gets list of names of modules this module depends on.
481 * @param ResourceLoaderContext context
482 * @return array List of module names
484 public function getDependencies( ResourceLoaderContext
$context = null ) {
485 return $this->dependencies
;
489 * Get the skip function.
490 * @return null|string
491 * @throws MWException
493 public function getSkipFunction() {
494 if ( !$this->skipFunction
) {
498 $localPath = $this->getLocalPath( $this->skipFunction
);
499 if ( !file_exists( $localPath ) ) {
500 throw new MWException( __METHOD__
. ": skip function file not found: \"$localPath\"" );
502 $contents = file_get_contents( $localPath );
503 if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
504 $contents = $this->validateScriptFile( $localPath, $contents );
512 public function isRaw() {
517 * Disable module content versioning.
519 * This class uses getDefinitionSummary() instead, to avoid filesystem overhead
520 * involved with building the full module content inside a startup request.
524 public function enableModuleContentVersion() {
529 * Helper method to gather file hashes for getDefinitionSummary.
531 * This function is context-sensitive, only computing hashes of files relevant to the
532 * given language, skin, etc.
534 * @see ResourceLoaderModule::getFileDependencies
535 * @param ResourceLoaderContext $context
538 protected function getFileHashes( ResourceLoaderContext
$context ) {
541 // Flatten style files into $files
542 $styles = self
::collateFilePathListByOption( $this->styles
, 'media', 'all' );
543 foreach ( $styles as $styleFiles ) {
544 $files = array_merge( $files, $styleFiles );
547 $skinFiles = self
::collateFilePathListByOption(
548 self
::tryForKey( $this->skinStyles
, $context->getSkin(), 'default' ),
552 foreach ( $skinFiles as $styleFiles ) {
553 $files = array_merge( $files, $styleFiles );
556 // Final merge, this should result in a master list of dependent files
557 $files = array_merge(
561 $context->getDebug() ?
$this->debugScripts
: array(),
562 $this->getLanguageScripts( $context->getLanguage() ),
563 self
::tryForKey( $this->skinScripts
, $context->getSkin(), 'default' ),
566 if ( $this->skipFunction
) {
567 $files[] = $this->skipFunction
;
569 $files = array_map( array( $this, 'getLocalPath' ), $files );
570 // File deps need to be treated separately because they're already prefixed
571 $files = array_merge( $files, $this->getFileDependencies( $context->getSkin() ) );
572 // Filter out any duplicates from getFileDependencies() and others.
573 // Most commonly introduced by compileLessFile(), which always includes the
574 // entry point Less file we already know about.
575 $files = array_values( array_unique( $files ) );
577 // Don't include keys or file paths here, only the hashes. Including that would needlessly
578 // cause global cache invalidation when files move or if e.g. the MediaWiki path changes.
579 // Any significant ordering is already detected by the definition summary.
580 return array_map( array( __CLASS__
, 'safeFileHash' ), $files );
584 * Get the definition summary for this module.
586 * @param ResourceLoaderContext $context
589 public function getDefinitionSummary( ResourceLoaderContext
$context ) {
590 $summary = parent
::getDefinitionSummary( $context );
594 // T104950: Do not include localBasePath or remoteBasePath!
595 // Those paths may vary over time and needlessly invalidate cache. If the path changes
596 // in a way that makes relative file paths point to something else, getFileHashes() will
597 // account for that already.
615 $options[$member] = $this->{$member};
619 'options' => $options,
620 'fileHashes' => $this->getFileHashes( $context ),
621 'msgBlobMtime' => $this->getMsgBlobMtime( $context->getLanguage() ),
627 * @param string|ResourceLoaderFilePath $path
630 protected function getLocalPath( $path ) {
631 if ( $path instanceof ResourceLoaderFilePath
) {
632 return $path->getLocalPath();
635 return "{$this->localBasePath}/$path";
639 * @param string|ResourceLoaderFilePath $path
642 protected function getRemotePath( $path ) {
643 if ( $path instanceof ResourceLoaderFilePath
) {
644 return $path->getRemotePath();
647 return "{$this->remoteBasePath}/$path";
651 * Infer the stylesheet language from a stylesheet file path.
654 * @param string $path
655 * @return string The stylesheet language name
657 public function getStyleSheetLang( $path ) {
658 return preg_match( '/\.less$/i', $path ) ?
'less' : 'css';
662 * Collates file paths by option (where provided).
664 * @param array $list List of file paths in any combination of index/path
665 * or path/options pairs
666 * @param string $option Option name
667 * @param mixed $default Default value if the option isn't set
668 * @return array List of file paths, collated by $option
670 protected static function collateFilePathListByOption( array $list, $option, $default ) {
671 $collatedFiles = array();
672 foreach ( (array)$list as $key => $value ) {
673 if ( is_int( $key ) ) {
674 // File name as the value
675 if ( !isset( $collatedFiles[$default] ) ) {
676 $collatedFiles[$default] = array();
678 $collatedFiles[$default][] = $value;
679 } elseif ( is_array( $value ) ) {
680 // File name as the key, options array as the value
681 $optionValue = isset( $value[$option] ) ?
$value[$option] : $default;
682 if ( !isset( $collatedFiles[$optionValue] ) ) {
683 $collatedFiles[$optionValue] = array();
685 $collatedFiles[$optionValue][] = $key;
688 return $collatedFiles;
692 * Get a list of element that match a key, optionally using a fallback key.
694 * @param array $list List of lists to select from
695 * @param string $key Key to look for in $map
696 * @param string $fallback Key to look for in $list if $key doesn't exist
697 * @return array List of elements from $map which matched $key or $fallback,
698 * or an empty list in case of no match
700 protected static function tryForKey( array $list, $key, $fallback = null ) {
701 if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
703 } elseif ( is_string( $fallback )
704 && isset( $list[$fallback] )
705 && is_array( $list[$fallback] )
707 return $list[$fallback];
713 * Get a list of file paths for all scripts in this module, in order of proper execution.
715 * @param ResourceLoaderContext $context
716 * @return array List of file paths
718 protected function getScriptFiles( ResourceLoaderContext
$context ) {
719 $files = array_merge(
721 $this->getLanguageScripts( $context->getLanguage() ),
722 self
::tryForKey( $this->skinScripts
, $context->getSkin(), 'default' )
724 if ( $context->getDebug() ) {
725 $files = array_merge( $files, $this->debugScripts
);
728 return array_unique( $files, SORT_REGULAR
);
732 * Get the set of language scripts for the given language,
733 * possibly using a fallback language.
735 * @param string $lang
738 private function getLanguageScripts( $lang ) {
739 $scripts = self
::tryForKey( $this->languageScripts
, $lang );
743 $fallbacks = Language
::getFallbacksFor( $lang );
744 foreach ( $fallbacks as $lang ) {
745 $scripts = self
::tryForKey( $this->languageScripts
, $lang );
755 * Get a list of file paths for all styles in this module, in order of proper inclusion.
757 * @param ResourceLoaderContext $context
758 * @return array List of file paths
760 public function getStyleFiles( ResourceLoaderContext
$context ) {
761 return array_merge_recursive(
762 self
::collateFilePathListByOption( $this->styles
, 'media', 'all' ),
763 self
::collateFilePathListByOption(
764 self
::tryForKey( $this->skinStyles
, $context->getSkin(), 'default' ),
772 * Gets a list of file paths for all skin styles in the module used by
775 * @param string $skinName The name of the skin
776 * @return array A list of file paths collated by media type
778 protected function getSkinStyleFiles( $skinName ) {
779 return self
::collateFilePathListByOption(
780 self
::tryForKey( $this->skinStyles
, $skinName ),
787 * Gets a list of file paths for all skin style files in the module,
788 * for all available skins.
790 * @return array A list of file paths collated by media type
792 protected function getAllSkinStyleFiles() {
793 $styleFiles = array();
794 $internalSkinNames = array_keys( Skin
::getSkinNames() );
795 $internalSkinNames[] = 'default';
797 foreach ( $internalSkinNames as $internalSkinName ) {
798 $styleFiles = array_merge_recursive(
800 $this->getSkinStyleFiles( $internalSkinName )
808 * Returns all style files and all skin style files used by this module.
812 public function getAllStyleFiles() {
813 $collatedStyleFiles = array_merge_recursive(
814 self
::collateFilePathListByOption( $this->styles
, 'media', 'all' ),
815 $this->getAllSkinStyleFiles()
820 foreach ( $collatedStyleFiles as $media => $styleFiles ) {
821 foreach ( $styleFiles as $styleFile ) {
822 $result[] = $this->getLocalPath( $styleFile );
830 * Gets the contents of a list of JavaScript files.
832 * @param array $scripts List of file paths to scripts to read, remap and concetenate
833 * @throws MWException
834 * @return string Concatenated and remapped JavaScript data from $scripts
836 protected function readScriptFiles( array $scripts ) {
837 if ( empty( $scripts ) ) {
841 foreach ( array_unique( $scripts, SORT_REGULAR
) as $fileName ) {
842 $localPath = $this->getLocalPath( $fileName );
843 if ( !file_exists( $localPath ) ) {
844 throw new MWException( __METHOD__
. ": script file not found: \"$localPath\"" );
846 $contents = file_get_contents( $localPath );
847 if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
848 // Static files don't really need to be checked as often; unlike
849 // on-wiki module they shouldn't change unexpectedly without
850 // admin interference.
851 $contents = $this->validateScriptFile( $fileName, $contents );
853 $js .= $contents . "\n";
859 * Gets the contents of a list of CSS files.
861 * @param array $styles List of media type/list of file paths pairs, to read, remap and
864 * @param ResourceLoaderContext $context (optional)
866 * @throws MWException
867 * @return array List of concatenated and remapped CSS data from $styles,
868 * keyed by media type
870 public function readStyleFiles( array $styles, $flip, $context = null ) {
871 if ( empty( $styles ) ) {
874 foreach ( $styles as $media => $files ) {
875 $uniqueFiles = array_unique( $files, SORT_REGULAR
);
876 $styleFiles = array();
877 foreach ( $uniqueFiles as $file ) {
878 $styleFiles[] = $this->readStyleFile( $file, $flip, $context );
880 $styles[$media] = implode( "\n", $styleFiles );
886 * Reads a style file.
888 * This method can be used as a callback for array_map()
890 * @param string $path File path of style file to read
892 * @param ResourceLoaderContext $context (optional)
894 * @return string CSS data in script file
895 * @throws MWException If the file doesn't exist
897 protected function readStyleFile( $path, $flip, $context = null ) {
898 $localPath = $this->getLocalPath( $path );
899 $remotePath = $this->getRemotePath( $path );
900 if ( !file_exists( $localPath ) ) {
901 $msg = __METHOD__
. ": style file not found: \"$localPath\"";
902 wfDebugLog( 'resourceloader', $msg );
903 throw new MWException( $msg );
906 if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
907 $compiler = $this->getLessCompiler( $context );
908 $style = $this->compileLessFile( $localPath, $compiler );
909 $this->hasGeneratedStyles
= true;
911 $style = file_get_contents( $localPath );
915 $style = CSSJanus
::transform( $style, true, false );
917 $localDir = dirname( $localPath );
918 $remoteDir = dirname( $remotePath );
919 // Get and register local file references
920 $this->localFileRefs
= array_merge(
921 $this->localFileRefs
,
922 CSSMin
::getLocalFileReferences( $style, $localDir )
924 return CSSMin
::remap(
925 $style, $localDir, $remoteDir, true
930 * Get whether CSS for this module should be flipped
931 * @param ResourceLoaderContext $context
934 public function getFlip( $context ) {
935 return $context->getDirection() === 'rtl';
939 * Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile']
941 * @return array Array of strings
943 public function getTargets() {
944 return $this->targets
;
948 * Compile a LESS file into CSS.
950 * Keeps track of all used files and adds them to localFileRefs.
953 * @throws Exception If lessc encounters a parse error
954 * @param string $fileName File path of LESS source
955 * @param lessc $compiler Compiler to use, if not default
956 * @return string CSS source
958 protected function compileLessFile( $fileName, $compiler = null ) {
960 $compiler = $this->getLessCompiler();
962 $result = $compiler->compileFile( $fileName );
963 $this->localFileRefs +
= array_keys( $compiler->allParsedFiles() );
968 * Get a LESS compiler instance for this module in given context.
970 * Just calls ResourceLoader::getLessCompiler() by default to get a global compiler.
972 * @param ResourceLoaderContext $context
973 * @throws MWException
977 protected function getLessCompiler( ResourceLoaderContext
$context = null ) {
978 return ResourceLoader
::getLessCompiler( $this->getConfig() );
982 * Takes named templates by the module and returns an array mapping.
983 * @return array of templates mapping template alias to content
984 * @throws MWException
986 public function getTemplates() {
987 $templates = array();
989 foreach ( $this->templates
as $alias => $templatePath ) {
991 if ( is_int( $alias ) ) {
992 $alias = $templatePath;
994 $localPath = $this->getLocalPath( $templatePath );
995 if ( file_exists( $localPath ) ) {
996 $content = file_get_contents( $localPath );
997 $templates[$alias] = $content;
999 $msg = __METHOD__
. ": template file not found: \"$localPath\"";
1000 wfDebugLog( 'resourceloader', $msg );
1001 throw new MWException( $msg );