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\RelPath;
30 
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 
107  private const USERJSPARSE_CACHE_VERSION = 2;
108 
115  public function getName() {
116  return $this->name;
117  }
118 
125  public function setName( $name ) {
126  $this->name = $name;
127  }
128 
136  public function setDependencyAccessCallbacks( callable $loadCallback, callable $saveCallback ) {
137  $this->depLoadCallback = $loadCallback;
138  $this->depSaveCallback = $saveCallback;
139  }
140 
148  public function getOrigin() {
149  return $this->origin;
150  }
151 
156  public function getFlip( ResourceLoaderContext $context ) {
157  return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
158  $context->getDirection();
159  }
160 
167  public function getDeprecationInformation( ResourceLoaderContext $context ) {
168  $deprecationInfo = $this->deprecated;
169  if ( $deprecationInfo ) {
170  $name = $this->getName();
171  $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
172  if ( is_string( $deprecationInfo ) ) {
173  $warning .= "\n" . $deprecationInfo;
174  }
175  return 'mw.log.warn(' . $context->encodeJson( $warning ) . ');';
176  } else {
177  return '';
178  }
179  }
180 
201  public function getScript( ResourceLoaderContext $context ) {
202  // Stub, override expected
203  return '';
204  }
205 
212  public function getTemplates() {
213  // Stub, override expected.
214  return [];
215  }
216 
221  public function getConfig() {
222  if ( $this->config === null ) {
223  // Ugh, fall back to default
224  $this->config = MediaWikiServices::getInstance()->getMainConfig();
225  }
226 
227  return $this->config;
228  }
229 
234  public function setConfig( Config $config ) {
235  $this->config = $config;
236  }
237 
242  public function setLogger( LoggerInterface $logger ) {
243  $this->logger = $logger;
244  }
245 
250  protected function getLogger() {
251  if ( !$this->logger ) {
252  $this->logger = new NullLogger();
253  }
254  return $this->logger;
255  }
256 
261  public function setHookContainer( HookContainer $hookContainer ) : void {
262  $this->hookRunner = new HookRunner( $hookContainer );
263  }
264 
272  protected function getHookRunner() : HookRunner {
273  return $this->hookRunner;
274  }
275 
291  public function getScriptURLsForDebug( ResourceLoaderContext $context ) {
292  $resourceLoader = $context->getResourceLoader();
293  $derivative = new DerivativeResourceLoaderContext( $context );
294  $derivative->setModules( [ $this->getName() ] );
295  $derivative->setOnly( 'scripts' );
296  $derivative->setDebug( true );
297 
298  $url = $resourceLoader->createLoaderURL(
299  $this->getSource(),
300  $derivative
301  );
302 
303  return [ $url ];
304  }
305 
314  public function supportsURLLoading() {
315  return true;
316  }
317 
327  public function getStyles( ResourceLoaderContext $context ) {
328  // Stub, override expected
329  return [];
330  }
331 
342  public function getStyleURLsForDebug( ResourceLoaderContext $context ) {
343  $resourceLoader = $context->getResourceLoader();
344  $derivative = new DerivativeResourceLoaderContext( $context );
345  $derivative->setModules( [ $this->getName() ] );
346  $derivative->setOnly( 'styles' );
347  $derivative->setDebug( true );
348 
349  $url = $resourceLoader->createLoaderURL(
350  $this->getSource(),
351  $derivative
352  );
353 
354  return [ 'all' => [ $url ] ];
355  }
356 
365  public function getMessages() {
366  // Stub, override expected
367  return [];
368  }
369 
376  public function getGroup() {
377  // Stub, override expected
378  return null;
379  }
380 
387  public function getSource() {
388  // Stub, override expected
389  return 'local';
390  }
391 
405  public function getDependencies( ResourceLoaderContext $context = null ) {
406  // Stub, override expected
407  return [];
408  }
409 
416  public function getTargets() {
417  return $this->targets;
418  }
419 
427  public function getType() {
428  return self::LOAD_GENERAL;
429  }
430 
446  public function getSkipFunction() {
447  return null;
448  }
449 
465  protected function getFileDependencies( ResourceLoaderContext $context ) {
466  $variant = self::getVary( $context );
467 
468  if ( !isset( $this->fileDeps[$variant] ) ) {
469  if ( $this->depLoadCallback ) {
470  $this->fileDeps[$variant] =
471  call_user_func( $this->depLoadCallback, $this->getName(), $variant );
472  } else {
473  $this->getLogger()->info( __METHOD__ . ": no callback registered" );
474  $this->fileDeps[$variant] = [];
475  }
476  }
477 
478  return $this->fileDeps[$variant];
479  }
480 
492  public function setFileDependencies( ResourceLoaderContext $context, array $paths ) {
493  $variant = self::getVary( $context );
494  $this->fileDeps[$variant] = $paths;
495  }
496 
504  protected function saveFileDependencies( ResourceLoaderContext $context, array $curFileRefs ) {
505  if ( !$this->depSaveCallback ) {
506  $this->getLogger()->info( __METHOD__ . ": no callback registered" );
507 
508  return;
509  }
510 
511  try {
512  // Pitfalls and performance considerations:
513  // 1. Don't keep updating the tracked paths due to duplicates or sorting.
514  // 2. Use relative paths to avoid ghost entries when $IP changes. (T111481)
515  // 3. Don't needlessly replace tracked paths with the same value
516  // just because $IP changed (e.g. when upgrading a wiki).
517  // 4. Don't create an endless replace loop on every request for this
518  // module when '../' is used anywhere. Even though both are expanded
519  // (one expanded by getFileDependencies from the DB, the other is
520  // still raw as originally read by RL), the latter has not
521  // been normalized yet.
522  call_user_func(
523  $this->depSaveCallback,
524  $this->getName(),
525  self::getVary( $context ),
526  self::getRelativePaths( $curFileRefs ),
527  self::getRelativePaths( $this->getFileDependencies( $context ) )
528  );
529  } catch ( Exception $e ) {
530  $this->getLogger()->warning(
531  __METHOD__ . ": failed to update dependencies: {$e->getMessage()}",
532  [ 'exception' => $e ]
533  );
534  }
535  }
536 
547  public static function getRelativePaths( array $filePaths ) {
548  global $IP;
549  return array_map( function ( $path ) use ( $IP ) {
550  return RelPath::getRelativePath( $path, $IP );
551  }, $filePaths );
552  }
553 
561  public static function expandRelativePaths( array $filePaths ) {
562  global $IP;
563  return array_map( function ( $path ) use ( $IP ) {
564  return RelPath::joinPath( $IP, $path );
565  }, $filePaths );
566  }
567 
576  protected function getMessageBlob( ResourceLoaderContext $context ) {
577  if ( !$this->getMessages() ) {
578  // Don't bother consulting MessageBlobStore
579  return null;
580  }
581  // Message blobs may only vary language, not by context keys
582  $lang = $context->getLanguage();
583  if ( !isset( $this->msgBlobs[$lang] ) ) {
584  $this->getLogger()->warning( 'Message blob for {module} should have been preloaded', [
585  'module' => $this->getName(),
586  ] );
587  $store = $context->getResourceLoader()->getMessageBlobStore();
588  $this->msgBlobs[$lang] = $store->getBlob( $this, $lang );
589  }
590  return $this->msgBlobs[$lang];
591  }
592 
602  public function setMessageBlob( $blob, $lang ) {
603  $this->msgBlobs[$lang] = $blob;
604  }
605 
620  final public function getHeaders( ResourceLoaderContext $context ) {
621  $headers = [];
622 
623  $formattedLinks = [];
624  foreach ( $this->getPreloadLinks( $context ) as $url => $attribs ) {
625  $link = "<{$url}>;rel=preload";
626  foreach ( $attribs as $key => $val ) {
627  $link .= ";{$key}={$val}";
628  }
629  $formattedLinks[] = $link;
630  }
631  if ( $formattedLinks ) {
632  $headers[] = 'Link: ' . implode( ',', $formattedLinks );
633  }
634 
635  return $headers;
636  }
637 
679  protected function getPreloadLinks( ResourceLoaderContext $context ) {
680  return [];
681  }
682 
691  protected function getLessVars( ResourceLoaderContext $context ) {
692  return [];
693  }
694 
702  public function getModuleContent( ResourceLoaderContext $context ) {
703  $contextHash = $context->getHash();
704  // Cache this expensive operation. This calls builds the scripts, styles, and messages
705  // content which typically involves filesystem and/or database access.
706  if ( !array_key_exists( $contextHash, $this->contents ) ) {
707  $this->contents[$contextHash] = $this->buildContent( $context );
708  }
709  return $this->contents[$contextHash];
710  }
711 
719  final protected function buildContent( ResourceLoaderContext $context ) {
720  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
721  $statStart = microtime( true );
722 
723  // This MUST build both scripts and styles, regardless of whether $context->getOnly()
724  // is 'scripts' or 'styles' because the result is used by getVersionHash which
725  // must be consistent regardless of the 'only' filter on the current request.
726  // Also, when introducing new module content resources (e.g. templates, headers),
727  // these should only be included in the array when they are non-empty so that
728  // existing modules not using them do not get their cache invalidated.
729  $content = [];
730 
731  // Scripts
732  // If we are in debug mode, we'll want to return an array of URLs if possible
733  // However, we can't do this if the module doesn't support it.
734  // We also can't do this if there is an only= parameter, because we have to give
735  // the module a way to return a load.php URL without causing an infinite loop
736  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
737  $scripts = $this->getScriptURLsForDebug( $context );
738  } else {
739  $scripts = $this->getScript( $context );
740  // Make the script safe to concatenate by making sure there is at least one
741  // trailing new line at the end of the content. Previously, this looked for
742  // a semi-colon instead, but that breaks concatenation if the semicolon
743  // is inside a comment like "// foo();". Instead, simply use a
744  // line break as separator which matches JavaScript native logic for implicitly
745  // ending statements even if a semi-colon is missing.
746  // Bugs: T29054, T162719.
747  if ( is_string( $scripts )
748  && strlen( $scripts )
749  && substr( $scripts, -1 ) !== "\n"
750  ) {
751  $scripts .= "\n";
752  }
753  }
754  $content['scripts'] = $scripts;
755 
756  $styles = [];
757  // Don't create empty stylesheets like [ '' => '' ] for modules
758  // that don't *have* any stylesheets (T40024).
759  $stylePairs = $this->getStyles( $context );
760  if ( count( $stylePairs ) ) {
761  // If we are in debug mode without &only= set, we'll want to return an array of URLs
762  // See comment near shouldIncludeScripts() for more details
763  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
764  $styles = [
765  'url' => $this->getStyleURLsForDebug( $context )
766  ];
767  } else {
768  // Minify CSS before embedding in mw.loader.implement call
769  // (unless in debug mode)
770  if ( !$context->getDebug() ) {
771  foreach ( $stylePairs as $media => $style ) {
772  // Can be either a string or an array of strings.
773  if ( is_array( $style ) ) {
774  $stylePairs[$media] = [];
775  foreach ( $style as $cssText ) {
776  if ( is_string( $cssText ) ) {
777  $stylePairs[$media][] =
778  ResourceLoader::filter( 'minify-css', $cssText );
779  }
780  }
781  } elseif ( is_string( $style ) ) {
782  $stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
783  }
784  }
785  }
786  // Wrap styles into @media groups as needed and flatten into a numerical array
787  $styles = [
788  'css' => ResourceLoader::makeCombinedStyles( $stylePairs )
789  ];
790  }
791  }
792  $content['styles'] = $styles;
793 
794  // Messages
795  $blob = $this->getMessageBlob( $context );
796  if ( $blob ) {
797  $content['messagesBlob'] = $blob;
798  }
799 
800  $templates = $this->getTemplates();
801  if ( $templates ) {
802  $content['templates'] = $templates;
803  }
804 
805  $headers = $this->getHeaders( $context );
806  if ( $headers ) {
807  $content['headers'] = $headers;
808  }
809 
810  $statTiming = microtime( true ) - $statStart;
811  $statName = strtr( $this->getName(), '.', '_' );
812  $stats->timing( "resourceloader_build.all", 1000 * $statTiming );
813  $stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
814 
815  return $content;
816  }
817 
835  public function getVersionHash( ResourceLoaderContext $context ) {
836  // Cache this somewhat expensive operation. Especially because some classes
837  // (e.g. startup module) iterate more than once over all modules to get versions.
838  $contextHash = $context->getHash();
839  if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
840  if ( $this->enableModuleContentVersion() ) {
841  // Detect changes directly by hashing the module contents.
842  $str = json_encode( $this->getModuleContent( $context ) );
843  } else {
844  // Infer changes based on definition and other metrics
845  $summary = $this->getDefinitionSummary( $context );
846  if ( !isset( $summary['_class'] ) ) {
847  throw new LogicException( 'getDefinitionSummary must call parent method' );
848  }
849  $str = json_encode( $summary );
850  }
851 
852  $this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
853  }
854  return $this->versionHash[$contextHash];
855  }
856 
867  public function enableModuleContentVersion() {
868  return false;
869  }
870 
914  public function getDefinitionSummary( ResourceLoaderContext $context ) {
915  return [
916  '_class' => static::class,
917  // Make sure that when filter cache for minification is invalidated,
918  // we also change the HTTP urls and mw.loader.store keys (T176884).
919  '_cacheVersion' => ResourceLoader::CACHE_VERSION,
920  ];
921  }
922 
934  public function isKnownEmpty( ResourceLoaderContext $context ) {
935  return false;
936  }
937 
949  public function shouldEmbedModule( ResourceLoaderContext $context ) {
950  return $this->getGroup() === 'private';
951  }
952 
961  protected function validateScriptFile( $fileName, $contents ) {
962  $error = null;
963 
964  if ( $this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
965  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
966  // Cache potentially slow parsing of JavaScript code during the
967  // critical path. This happens lazily when responding to requests
968  // for modules=site, modules=user, and Gadgets.
969  $error = $cache->getWithSetCallback(
970  $cache->makeKey(
971  'resourceloader-userjsparse',
972  self::USERJSPARSE_CACHE_VERSION,
973  md5( $contents ),
974  $fileName
975  ),
976  $cache::TTL_WEEK,
977  function () use ( $contents, $fileName ) {
978  $parser = new JSParser();
979  try {
980  // Ignore compiler warnings (T77169)
981  // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
982  @$parser->parse( $contents, $fileName, 1 );
983  } catch ( Exception $e ) {
984  return $e->getMessage();
985  }
986  // Cache success as null
987  return null;
988  }
989  );
990  }
991 
992  if ( $error ) {
993  // Send the error to the browser console client-side.
994  // By returning this as replacement for the actual script,
995  // we ensure user-provided scripts are safe to include in a batch
996  // request, without risk of a syntax error in this blob breaking
997  // the response itself.
998  return 'mw.log.error(' .
999  json_encode(
1000  'JavaScript parse error (scripts need to be valid ECMAScript 5): ' .
1001  $error
1002  ) .
1003  ');';
1004  } else {
1005  return $contents;
1006  }
1007  }
1008 
1017  protected static function safeFileHash( $filePath ) {
1018  return FileContentsHasher::getFileContentsHash( $filePath );
1019  }
1020 
1028  public static function getVary( ResourceLoaderContext $context ) {
1029  return implode( '|', [
1030  $context->getSkin(),
1031  $context->getLanguage(),
1032  ] );
1033  }
1034 }
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:314
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:342
ResourceLoaderModule\setMessageBlob
setMessageBlob( $blob, $lang)
Set in-object cache for message blobs.
Definition: ResourceLoaderModule.php:602
ResourceLoaderContext\getDirection
getDirection()
Definition: ResourceLoaderContext.php:174
ResourceLoaderModule\getFlip
getFlip(ResourceLoaderContext $context)
Definition: ResourceLoaderModule.php:156
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:166
$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:136
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:272
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:125
ResourceLoaderModule\setLogger
setLogger(LoggerInterface $logger)
Definition: ResourceLoaderModule.php:242
ResourceLoaderModule\getHeaders
getHeaders(ResourceLoaderContext $context)
Get headers to send as part of a module web response.
Definition: ResourceLoaderModule.php:620
ResourceLoaderModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderModule.php:427
ResourceLoaderModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderModule.php:416
ResourceLoaderModule\shouldEmbedModule
shouldEmbedModule(ResourceLoaderContext $context)
Check whether this module should be embeded rather than linked.
Definition: ResourceLoaderModule.php:949
ResourceLoader\HookRunner
Definition: HookRunner.php:18
ResourceLoaderModule\getVary
static getVary(ResourceLoaderContext $context)
Get vary string.
Definition: ResourceLoaderModule.php:1028
ResourceLoaderModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
Definition: ResourceLoaderModule.php:327
ResourceLoaderContext\getOnly
getOnly()
Definition: ResourceLoaderContext.php:245
ResourceLoaderModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderModule.php:212
ResourceLoaderModule\setFileDependencies
setFileDependencies(ResourceLoaderContext $context, array $paths)
Set the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:492
ResourceLoaderModule\saveFileDependencies
saveFileDependencies(ResourceLoaderContext $context, array $curFileRefs)
Save the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:504
ResourceLoaderModule\setHookContainer
setHookContainer(HookContainer $hookContainer)
Definition: ResourceLoaderModule.php:261
ResourceLoaderModule\buildContent
buildContent(ResourceLoaderContext $context)
Bundle all resources attached to this module into an array.
Definition: ResourceLoaderModule.php:719
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:691
ResourceLoaderModule\enableModuleContentVersion
enableModuleContentVersion()
Whether to generate version hash based on module content.
Definition: ResourceLoaderModule.php:867
Config
Interface for configuration instances.
Definition: Config.php:30
ResourceLoaderModule\getGroup
getGroup()
Get the group this module is in.
Definition: ResourceLoaderModule.php:376
ResourceLoaderModule\getLogger
getLogger()
Definition: ResourceLoaderModule.php:250
ResourceLoaderModule\getScript
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Definition: ResourceLoaderModule.php:201
$blob
$blob
Definition: testCompression.php:70
ResourceLoader\makeHash
static makeHash( $value)
Create a hash for module versioning purposes.
Definition: ResourceLoader.php:731
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:167
ResourceLoaderModule\expandRelativePaths
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
Definition: ResourceLoaderModule.php:561
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:148
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:576
ResourceLoaderModule\isKnownEmpty
isKnownEmpty(ResourceLoaderContext $context)
Check whether this module is known to be empty.
Definition: ResourceLoaderModule.php:934
$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:1017
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:405
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:1415
ResourceLoaderModule\getPreloadLinks
getPreloadLinks(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Definition: ResourceLoaderModule.php:679
DerivativeResourceLoaderContext
A mutable version of ResourceLoaderContext.
Definition: DerivativeResourceLoaderContext.php:33
ResourceLoaderModule\getMessages
getMessages()
Get the messages needed for this module.
Definition: ResourceLoaderModule.php:365
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a user-provided JavaScript blob.
Definition: ResourceLoaderModule.php:961
ResourceLoaderModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderModule.php:914
ResourceLoaderContext\getSkin
getSkin()
Definition: ResourceLoaderContext.php:188
ResourceLoaderModule\getModuleContent
getModuleContent(ResourceLoaderContext $context)
Get an array of this module's resources.
Definition: ResourceLoaderModule.php:702
ResourceLoaderModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderModule.php:446
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:234
ResourceLoaderModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
Definition: ResourceLoaderModule.php:291
$path
$path
Definition: NoLocalSettings.php:25
ResourceLoaderModule\getRelativePaths
static getRelativePaths(array $filePaths)
Make file paths relative to MediaWiki directory.
Definition: ResourceLoaderModule.php:547
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the indirect dependencies for this module persuant to the skin/language context.
Definition: ResourceLoaderModule.php:465
ResourceLoaderModule\getVersionHash
getVersionHash(ResourceLoaderContext $context)
Get a string identifying the current version of this module in a given context.
Definition: ResourceLoaderModule.php:835
ResourceLoaderModule\getSource
getSource()
Get the source of this module.
Definition: ResourceLoaderModule.php:387
JSParser
Definition: jsminplus.php:675
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
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:115
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:221