MediaWiki  master
ResourceLoaderModule.php
Go to the documentation of this file.
1 <?php
26 use Psr\Log\LoggerAwareInterface;
27 use Psr\Log\LoggerInterface;
28 use Psr\Log\NullLogger;
29 use Wikimedia\AtEase\AtEase;
30 use Wikimedia\RelPath;
31 
39 abstract class ResourceLoaderModule implements LoggerAwareInterface {
41  protected $config;
43  protected $logger;
44 
52  protected $origin = self::ORIGIN_CORE_SITEWIDE;
53 
55  protected $name = null;
57  protected $targets = [ 'desktop' ];
58 
60  protected $fileDeps = [];
62  protected $msgBlobs = [];
64  protected $versionHash = [];
66  protected $contents = [];
67 
69  private $hookRunner;
70 
75 
77  protected $deprecated = false;
78 
80  public const TYPE_SCRIPTS = 'scripts';
82  public const TYPE_STYLES = 'styles';
84  public const TYPE_COMBINED = 'combined';
85 
87  public const LOAD_STYLES = 'styles';
89  public const LOAD_GENERAL = 'general';
90 
92  public const ORIGIN_CORE_SITEWIDE = 1;
94  public const ORIGIN_CORE_INDIVIDUAL = 2;
100  public const ORIGIN_USER_SITEWIDE = 3;
102  public const ORIGIN_USER_INDIVIDUAL = 4;
104  public const ORIGIN_ALL = 10;
105 
112  public function getName() {
113  return $this->name;
114  }
115 
122  public function setName( $name ) {
123  $this->name = $name;
124  }
125 
133  public function setDependencyAccessCallbacks( callable $loadCallback, callable $saveCallback ) {
134  $this->depLoadCallback = $loadCallback;
135  $this->depSaveCallback = $saveCallback;
136  }
137 
145  public function getOrigin() {
146  return $this->origin;
147  }
148 
153  public function getFlip( ResourceLoaderContext $context ) {
154  return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
155  $context->getDirection();
156  }
157 
164  public function getDeprecationInformation( ResourceLoaderContext $context ) {
165  $deprecationInfo = $this->deprecated;
166  if ( $deprecationInfo ) {
167  $name = $this->getName();
168  $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
169  if ( is_string( $deprecationInfo ) ) {
170  $warning .= "\n" . $deprecationInfo;
171  }
172  return 'mw.log.warn(' . $context->encodeJson( $warning ) . ');';
173  } else {
174  return '';
175  }
176  }
177 
198  public function getScript( ResourceLoaderContext $context ) {
199  // Stub, override expected
200  return '';
201  }
202 
209  public function getTemplates() {
210  // Stub, override expected.
211  return [];
212  }
213 
218  public function getConfig() {
219  if ( $this->config === null ) {
220  // Ugh, fall back to default
221  $this->config = MediaWikiServices::getInstance()->getMainConfig();
222  }
223 
224  return $this->config;
225  }
226 
231  public function setConfig( Config $config ) {
232  $this->config = $config;
233  }
234 
239  public function setLogger( LoggerInterface $logger ) {
240  $this->logger = $logger;
241  }
242 
247  protected function getLogger() {
248  if ( !$this->logger ) {
249  $this->logger = new NullLogger();
250  }
251  return $this->logger;
252  }
253 
258  public function setHookContainer( HookContainer $hookContainer ) : void {
259  $this->hookRunner = new HookRunner( $hookContainer );
260  }
261 
269  protected function getHookRunner() : HookRunner {
270  return $this->hookRunner;
271  }
272 
288  public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
289  $resourceLoader = $context->getResourceLoader();
290  $derivative = new DerivativeResourceLoaderContext( $context );
291  $derivative->setModules( [ $this->getName() ] );
292  $derivative->setOnly( 'scripts' );
293  $derivative->setDebug( true );
294 
295  $url = $resourceLoader->createLoaderURL(
296  $this->getSource(),
297  $derivative
298  );
299 
300  return [ $url ];
301  }
302 
311  public function supportsURLLoading() {
312  return true;
313  }
314 
324  public function getStyles( ResourceLoaderContext $context ) {
325  // Stub, override expected
326  return [];
327  }
328 
339  public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
340  $resourceLoader = $context->getResourceLoader();
341  $derivative = new DerivativeResourceLoaderContext( $context );
342  $derivative->setModules( [ $this->getName() ] );
343  $derivative->setOnly( 'styles' );
344  $derivative->setDebug( true );
345 
346  $url = $resourceLoader->createLoaderURL(
347  $this->getSource(),
348  $derivative
349  );
350 
351  return [ 'all' => [ $url ] ];
352  }
353 
362  public function getMessages() {
363  // Stub, override expected
364  return [];
365  }
366 
373  public function getGroup() {
374  // Stub, override expected
375  return null;
376  }
377 
384  public function getSource() {
385  // Stub, override expected
386  return 'local';
387  }
388 
402  public function getDependencies( ResourceLoaderContext $context = null ) {
403  // Stub, override expected
404  return [];
405  }
406 
413  public function getTargets() {
414  return $this->targets;
415  }
416 
424  public function getType() {
425  return self::LOAD_GENERAL;
426  }
427 
443  public function getSkipFunction() {
444  return null;
445  }
446 
462  protected function getFileDependencies( ResourceLoaderContext $context ) {
463  $variant = self::getVary( $context );
464 
465  if ( !isset( $this->fileDeps[$variant] ) ) {
466  if ( $this->depLoadCallback ) {
467  $this->fileDeps[$variant] =
468  call_user_func( $this->depLoadCallback, $this->getName(), $variant );
469  } else {
470  $this->getLogger()->info( __METHOD__ . ": no callback registered" );
471  $this->fileDeps[$variant] = [];
472  }
473  }
474 
475  return $this->fileDeps[$variant];
476  }
477 
489  public function setFileDependencies( ResourceLoaderContext $context, array $paths ) {
490  $variant = self::getVary( $context );
491  $this->fileDeps[$variant] = $paths;
492  }
493 
501  protected function saveFileDependencies( ResourceLoaderContext $context, array $curFileRefs ) {
502  if ( !$this->depSaveCallback ) {
503  $this->getLogger()->info( __METHOD__ . ": no callback registered" );
504 
505  return;
506  }
507 
508  try {
509  // Pitfalls and performance considerations:
510  // 1. Don't keep updating the tracked paths due to duplicates or sorting.
511  // 2. Use relative paths to avoid ghost entries when $IP changes. (T111481)
512  // 3. Don't needlessly replace tracked paths with the same value
513  // just because $IP changed (e.g. when upgrading a wiki).
514  // 4. Don't create an endless replace loop on every request for this
515  // module when '../' is used anywhere. Even though both are expanded
516  // (one expanded by getFileDependencies from the DB, the other is
517  // still raw as originally read by RL), the latter has not
518  // been normalized yet.
519  call_user_func(
520  $this->depSaveCallback,
521  $this->getName(),
522  self::getVary( $context ),
523  self::getRelativePaths( $curFileRefs ),
524  self::getRelativePaths( $this->getFileDependencies( $context ) )
525  );
526  } catch ( Exception $e ) {
527  $this->getLogger()->warning(
528  __METHOD__ . ": failed to update dependencies: {$e->getMessage()}",
529  [ 'exception' => $e ]
530  );
531  }
532  }
533 
544  public static function getRelativePaths( array $filePaths ) {
545  global $IP;
546  return array_map( function ( $path ) use ( $IP ) {
547  return RelPath::getRelativePath( $path, $IP );
548  }, $filePaths );
549  }
550 
558  public static function expandRelativePaths( array $filePaths ) {
559  global $IP;
560  return array_map( function ( $path ) use ( $IP ) {
561  return RelPath::joinPath( $IP, $path );
562  }, $filePaths );
563  }
564 
573  protected function getMessageBlob( ResourceLoaderContext $context ) {
574  if ( !$this->getMessages() ) {
575  // Don't bother consulting MessageBlobStore
576  return null;
577  }
578  // Message blobs may only vary language, not by context keys
579  $lang = $context->getLanguage();
580  if ( !isset( $this->msgBlobs[$lang] ) ) {
581  $this->getLogger()->warning( 'Message blob for {module} should have been preloaded', [
582  'module' => $this->getName(),
583  ] );
584  $store = $context->getResourceLoader()->getMessageBlobStore();
585  $this->msgBlobs[$lang] = $store->getBlob( $this, $lang );
586  }
587  return $this->msgBlobs[$lang];
588  }
589 
599  public function setMessageBlob( $blob, $lang ) {
600  $this->msgBlobs[$lang] = $blob;
601  }
602 
617  final public function getHeaders( ResourceLoaderContext $context ) {
618  $headers = [];
619 
620  $formattedLinks = [];
621  foreach ( $this->getPreloadLinks( $context ) as $url => $attribs ) {
622  $link = "<{$url}>;rel=preload";
623  foreach ( $attribs as $key => $val ) {
624  $link .= ";{$key}={$val}";
625  }
626  $formattedLinks[] = $link;
627  }
628  if ( $formattedLinks ) {
629  $headers[] = 'Link: ' . implode( ',', $formattedLinks );
630  }
631 
632  return $headers;
633  }
634 
676  protected function getPreloadLinks( ResourceLoaderContext $context ) {
677  return [];
678  }
679 
688  protected function getLessVars( ResourceLoaderContext $context ) {
689  return [];
690  }
691 
699  public function getModuleContent( ResourceLoaderContext $context ) {
700  $contextHash = $context->getHash();
701  // Cache this expensive operation. This calls builds the scripts, styles, and messages
702  // content which typically involves filesystem and/or database access.
703  if ( !array_key_exists( $contextHash, $this->contents ) ) {
704  $this->contents[$contextHash] = $this->buildContent( $context );
705  }
706  return $this->contents[$contextHash];
707  }
708 
716  final protected function buildContent( ResourceLoaderContext $context ) {
717  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
718  $statStart = microtime( true );
719 
720  // This MUST build both scripts and styles, regardless of whether $context->getOnly()
721  // is 'scripts' or 'styles' because the result is used by getVersionHash which
722  // must be consistent regardless of the 'only' filter on the current request.
723  // Also, when introducing new module content resources (e.g. templates, headers),
724  // these should only be included in the array when they are non-empty so that
725  // existing modules not using them do not get their cache invalidated.
726  $content = [];
727 
728  // Scripts
729  // If we are in debug mode, we'll want to return an array of URLs if possible
730  // However, we can't do this if the module doesn't support it.
731  // We also can't do this if there is an only= parameter, because we have to give
732  // the module a way to return a load.php URL without causing an infinite loop
733  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
734  $scripts = $this->getScriptURLsForDebug( $context );
735  } else {
736  $scripts = $this->getScript( $context );
737  // Make the script safe to concatenate by making sure there is at least one
738  // trailing new line at the end of the content. Previously, this looked for
739  // a semi-colon instead, but that breaks concatenation if the semicolon
740  // is inside a comment like "// foo();". Instead, simply use a
741  // line break as separator which matches JavaScript native logic for implicitly
742  // ending statements even if a semi-colon is missing.
743  // Bugs: T29054, T162719.
744  if ( is_string( $scripts )
745  && strlen( $scripts )
746  && substr( $scripts, -1 ) !== "\n"
747  ) {
748  $scripts .= "\n";
749  }
750  }
751  $content['scripts'] = $scripts;
752 
753  $styles = [];
754  // Don't create empty stylesheets like [ '' => '' ] for modules
755  // that don't *have* any stylesheets (T40024).
756  $stylePairs = $this->getStyles( $context );
757  if ( count( $stylePairs ) ) {
758  // If we are in debug mode without &only= set, we'll want to return an array of URLs
759  // See comment near shouldIncludeScripts() for more details
760  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
761  $styles = [
762  'url' => $this->getStyleURLsForDebug( $context )
763  ];
764  } else {
765  // Minify CSS before embedding in mw.loader.implement call
766  // (unless in debug mode)
767  if ( !$context->getDebug() ) {
768  foreach ( $stylePairs as $media => $style ) {
769  // Can be either a string or an array of strings.
770  if ( is_array( $style ) ) {
771  $stylePairs[$media] = [];
772  foreach ( $style as $cssText ) {
773  if ( is_string( $cssText ) ) {
774  $stylePairs[$media][] =
775  ResourceLoader::filter( 'minify-css', $cssText );
776  }
777  }
778  } elseif ( is_string( $style ) ) {
779  $stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
780  }
781  }
782  }
783  // Wrap styles into @media groups as needed and flatten into a numerical array
784  $styles = [
785  'css' => ResourceLoader::makeCombinedStyles( $stylePairs )
786  ];
787  }
788  }
789  $content['styles'] = $styles;
790 
791  // Messages
792  $blob = $this->getMessageBlob( $context );
793  if ( $blob ) {
794  $content['messagesBlob'] = $blob;
795  }
796 
797  $templates = $this->getTemplates();
798  if ( $templates ) {
799  $content['templates'] = $templates;
800  }
801 
802  $headers = $this->getHeaders( $context );
803  if ( $headers ) {
804  $content['headers'] = $headers;
805  }
806 
807  $statTiming = microtime( true ) - $statStart;
808  $statName = strtr( $this->getName(), '.', '_' );
809  $stats->timing( "resourceloader_build.all", 1000 * $statTiming );
810  $stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
811 
812  return $content;
813  }
814 
832  public function getVersionHash( ResourceLoaderContext $context ) {
833  // Cache this somewhat expensive operation. Especially because some classes
834  // (e.g. startup module) iterate more than once over all modules to get versions.
835  $contextHash = $context->getHash();
836  if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
837  if ( $this->enableModuleContentVersion() ) {
838  // Detect changes directly by hashing the module contents.
839  $str = json_encode( $this->getModuleContent( $context ) );
840  } else {
841  // Infer changes based on definition and other metrics
842  $summary = $this->getDefinitionSummary( $context );
843  if ( !isset( $summary['_class'] ) ) {
844  throw new LogicException( 'getDefinitionSummary must call parent method' );
845  }
846  $str = json_encode( $summary );
847  }
848 
849  $this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
850  }
851  return $this->versionHash[$contextHash];
852  }
853 
864  public function enableModuleContentVersion() {
865  return false;
866  }
867 
911  public function getDefinitionSummary( ResourceLoaderContext $context ) {
912  return [
913  '_class' => static::class,
914  // Make sure that when filter cache for minification is invalidated,
915  // we also change the HTTP urls and mw.loader.store keys (T176884).
916  '_cacheVersion' => ResourceLoader::CACHE_VERSION,
917  ];
918  }
919 
931  public function isKnownEmpty( ResourceLoaderContext $context ) {
932  return false;
933  }
934 
946  public function shouldEmbedModule( ResourceLoaderContext $context ) {
947  return $this->getGroup() === 'private';
948  }
949 
950  private static $parseCacheVersion = 1;
951 
960  protected function validateScriptFile( $fileName, $contents ) {
961  if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
962  return $contents;
963  }
964  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
965  return $cache->getWithSetCallback(
966  $cache->makeGlobalKey(
967  'resourceloader-jsparse',
968  self::$parseCacheVersion,
969  md5( $contents ),
970  $fileName
971  ),
972  $cache::TTL_WEEK,
973  function () use ( $contents, $fileName ) {
974  $parser = new JSParser();
975  $err = null;
976  try {
977  AtEase::suppressWarnings();
978  $parser->parse( $contents, $fileName, 1 );
979  } catch ( Exception $e ) {
980  $err = $e;
981  } finally {
982  AtEase::restoreWarnings();
983  }
984  if ( $err ) {
985  // Send the error to the browser console client-side.
986  // By returning this as replacement for the actual script,
987  // we ensure modules are safe to load in a batch request,
988  // without causing other unrelated modules to break.
989  return 'mw.log.error(' . Xml::encodeJsVar(
990  'JavaScript parse error (scripts need to be valid ECMAScript 5): ' .
991  $err->getMessage() ) . ');';
992  }
993  return $contents;
994  }
995  );
996  }
997 
1006  protected static function safeFileHash( $filePath ) {
1007  return FileContentsHasher::getFileContentsHash( $filePath );
1008  }
1009 
1017  public static function getVary( ResourceLoaderContext $context ) {
1018  return implode( '|', [
1019  $context->getSkin(),
1020  $context->getLanguage(),
1021  ] );
1022  }
1023 }
ResourceLoader\filter
static filter( $filter, $data, array $options=[])
Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
Definition: ResourceLoader.php:180
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:33
ResourceLoaderModule\supportsURLLoading
supportsURLLoading()
Whether this module supports URL loading.
Definition: ResourceLoaderModule.php:311
ResourceLoaderModule\$depLoadCallback
callback $depLoadCallback
Function of (module name, variant) to get indirect file dependencies.
Definition: ResourceLoaderModule.php:72
ResourceLoaderModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's CSS in debug mode.
Definition: ResourceLoaderModule.php:339
ResourceLoaderModule\setMessageBlob
setMessageBlob( $blob, $lang)
Set in-object cache for message blobs.
Definition: ResourceLoaderModule.php:599
ResourceLoaderContext\getDirection
getDirection()
Definition: ResourceLoaderContext.php:174
ResourceLoaderModule\getFlip
getFlip(ResourceLoaderContext $context)
Definition: ResourceLoaderModule.php:153
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:157
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
ResourceLoaderModule\setDependencyAccessCallbacks
setDependencyAccessCallbacks(callable $loadCallback, callable $saveCallback)
Inject the functions that load/save the indirect file path dependency list from storage.
Definition: ResourceLoaderModule.php:133
ResourceLoaderContext\getResourceLoader
getResourceLoader()
Definition: ResourceLoaderContext.php:123
ResourceLoaderModule\$contents
array $contents
Map of (context hash => cached module content)
Definition: ResourceLoaderModule.php:66
ResourceLoaderModule\getHookRunner
getHookRunner()
Get a HookRunner for running core hooks.
Definition: ResourceLoaderModule.php:269
ResourceLoaderModule\$depSaveCallback
callback $depSaveCallback
Function of (module name, variant) to get indirect file dependencies.
Definition: ResourceLoaderModule.php:74
ResourceLoaderModule\setName
setName( $name)
Set this module's name.
Definition: ResourceLoaderModule.php:122
ResourceLoaderModule\setLogger
setLogger(LoggerInterface $logger)
Definition: ResourceLoaderModule.php:239
ResourceLoaderModule\getHeaders
getHeaders(ResourceLoaderContext $context)
Get headers to send as part of a module web response.
Definition: ResourceLoaderModule.php:617
ResourceLoaderModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderModule.php:424
ResourceLoaderModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderModule.php:413
ResourceLoaderModule\shouldEmbedModule
shouldEmbedModule(ResourceLoaderContext $context)
Check whether this module should be embeded rather than linked.
Definition: ResourceLoaderModule.php:946
ResourceLoaderModule\getVary
static getVary(ResourceLoaderContext $context)
Get vary string.
Definition: ResourceLoaderModule.php:1017
ResourceLoaderModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
Definition: ResourceLoaderModule.php:324
ResourceLoaderContext\getOnly
getOnly()
Definition: ResourceLoaderContext.php:245
ResourceLoaderModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderModule.php:209
ResourceLoaderModule\setFileDependencies
setFileDependencies(ResourceLoaderContext $context, array $paths)
Set the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:489
ResourceLoaderModule\saveFileDependencies
saveFileDependencies(ResourceLoaderContext $context, array $curFileRefs)
Save the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:501
Xml\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:666
ResourceLoaderModule\setHookContainer
setHookContainer(HookContainer $hookContainer)
Definition: ResourceLoaderModule.php:258
ResourceLoaderModule\buildContent
buildContent(ResourceLoaderContext $context)
Bundle all resources attached to this module into an array.
Definition: ResourceLoaderModule.php:716
FileContentsHasher\getFileContentsHash
static getFileContentsHash( $filePaths, $algo='md4')
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...
Definition: FileContentsHasher.php:88
ResourceLoaderModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Definition: ResourceLoaderModule.php:688
ResourceLoaderModule\enableModuleContentVersion
enableModuleContentVersion()
Whether to generate version hash based on module content.
Definition: ResourceLoaderModule.php:864
Config
Interface for configuration instances.
Definition: Config.php:30
ResourceLoaderModule\getGroup
getGroup()
Get the group this module is in.
Definition: ResourceLoaderModule.php:373
ResourceLoaderModule\getLogger
getLogger()
Definition: ResourceLoaderModule.php:247
ResourceLoaderModule\getScript
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Definition: ResourceLoaderModule.php:198
$blob
$blob
Definition: testCompression.php:70
ResourceLoader\makeHash
static makeHash( $value)
Create a hash for module versioning purposes.
Definition: ResourceLoader.php:732
ResourceLoaderContext\getDebug
getDebug()
Definition: ResourceLoaderContext.php:238
ResourceLoaderModule\$origin
int $origin
Script and style modules form a hierarchy of trustworthiness, with core modules like skins and jQuery...
Definition: ResourceLoaderModule.php:52
ResourceLoaderModule\getDeprecationInformation
getDeprecationInformation(ResourceLoaderContext $context)
Get JS representing deprecation information for the current module if available.
Definition: ResourceLoaderModule.php:164
ResourceLoaderModule\expandRelativePaths
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
Definition: ResourceLoaderModule.php:558
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:156
ResourceLoaderModule\$versionHash
array $versionHash
Map of (context hash => cached module version hash)
Definition: ResourceLoaderModule.php:64
ResourceLoaderModule\getOrigin
getOrigin()
Get this module's origin.
Definition: ResourceLoaderModule.php:145
ResourceLoaderModule\$msgBlobs
array $msgBlobs
Map of (language => in-object cache for message blob)
Definition: ResourceLoaderModule.php:62
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:573
ResourceLoaderModule\$parseCacheVersion
static $parseCacheVersion
Definition: ResourceLoaderModule.php:950
ResourceLoaderModule\isKnownEmpty
isKnownEmpty(ResourceLoaderContext $context)
Check whether this module is known to be empty.
Definition: ResourceLoaderModule.php:931
$content
$content
Definition: router.php:76
ResourceLoaderModule\$deprecated
string bool $deprecated
Deprecation string or true if deprecated; false otherwise.
Definition: ResourceLoaderModule.php:77
ResourceLoaderModule\$targets
string[] $targets
What client platforms the module targets (e.g.
Definition: ResourceLoaderModule.php:57
ResourceLoaderModule\safeFileHash
static safeFileHash( $filePath)
Compute a non-cryptographic string hash of a file's contents.
Definition: ResourceLoaderModule.php:1006
ResourceLoaderModule\$name
string null $name
Module name.
Definition: ResourceLoaderModule.php:55
ResourceLoaderModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Get a list of modules this module depends on.
Definition: ResourceLoaderModule.php:402
ResourceLoader\makeCombinedStyles
static makeCombinedStyles(array $stylePairs)
Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks...
Definition: ResourceLoader.php:1416
ResourceLoaderModule\getPreloadLinks
getPreloadLinks(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Definition: ResourceLoaderModule.php:676
DerivativeResourceLoaderContext
A mutable version of ResourceLoaderContext.
Definition: DerivativeResourceLoaderContext.php:33
ResourceLoaderModule\getMessages
getMessages()
Get the messages needed for this module.
Definition: ResourceLoaderModule.php:362
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
Definition: ResourceLoaderModule.php:960
ResourceLoaderModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderModule.php:911
ResourceLoaderContext\getSkin
getSkin()
Definition: ResourceLoaderContext.php:188
ResourceLoaderModule\getModuleContent
getModuleContent(ResourceLoaderContext $context)
Get an array of this module's resources.
Definition: ResourceLoaderModule.php:699
ResourceLoaderModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderModule.php:443
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:39
ResourceLoaderModule\$config
Config $config
Definition: ResourceLoaderModule.php:41
ResourceLoaderModule\$logger
LoggerInterface $logger
Definition: ResourceLoaderModule.php:43
$cache
$cache
Definition: mcc.php:33
ResourceLoaderModule\setConfig
setConfig(Config $config)
Definition: ResourceLoaderModule.php:231
ResourceLoaderModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
Definition: ResourceLoaderModule.php:288
$path
$path
Definition: NoLocalSettings.php:25
ResourceLoaderModule\getRelativePaths
static getRelativePaths(array $filePaths)
Make file paths relative to MediaWiki directory.
Definition: ResourceLoaderModule.php:544
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:462
ResourceLoaderModule\getVersionHash
getVersionHash(ResourceLoaderContext $context)
Get a string identifying the current version of this module in a given context.
Definition: ResourceLoaderModule.php:832
ResourceLoaderModule\getSource
getSource()
Get the source of this module.
Definition: ResourceLoaderModule.php:384
JSParser
Definition: jsminplus.php:675
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:44
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:570
ResourceLoaderContext\getHash
getHash()
All factors that uniquely identify this request, except 'modules'.
Definition: ResourceLoaderContext.php:357
ResourceLoaderModule\$fileDeps
array $fileDeps
Map of (variant => indirect file dependencies)
Definition: ResourceLoaderModule.php:60
$IP
$IP
Definition: WebStart.php:49
ResourceLoaderModule\$hookRunner
HookRunner null $hookRunner
Definition: ResourceLoaderModule.php:69
ResourceLoaderContext\encodeJson
encodeJson( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
Definition: ResourceLoaderContext.php:405
ResourceLoaderModule\getName
getName()
Get this module's name.
Definition: ResourceLoaderModule.php:112
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:218