MediaWiki  1.33.0
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 use Wikimedia\ScopedCallback;
31 
35 abstract class ResourceLoaderModule implements LoggerAwareInterface {
36  # Type of resource
37  const TYPE_SCRIPTS = 'scripts';
38  const TYPE_STYLES = 'styles';
39  const TYPE_COMBINED = 'combined';
40 
41  # Desired load type
42  // Module only has styles (loaded via <style> or <link rel=stylesheet>)
43  const LOAD_STYLES = 'styles';
44  // Module may have other resources (loaded via mw.loader from a script)
45  const LOAD_GENERAL = 'general';
46 
47  # sitewide core module like a skin file or jQuery component
49 
50  # per-user module generated by the software
52 
53  # sitewide module generated from user-editable files, like MediaWiki:Common.js, or
54  # modules accessible to multiple users, such as those generated by the Gadgets extension.
56 
57  # per-user module generated from user-editable files, like User:Me/vector.js
59 
60  # an access constant; make sure this is kept as the largest number in this group
61  const ORIGIN_ALL = 10;
62 
63  # script and style modules form a hierarchy of trustworthiness, with core modules like
64  # skins and jQuery as most trustworthy, and user scripts as least trustworthy. We can
65  # limit the types of scripts and styles we allow to load on, say, sensitive special
66  # pages like Special:UserLogin and Special:Preferences
68 
69  protected $name = null;
70  protected $targets = [ 'desktop' ];
71 
72  // In-object cache for file dependencies
73  protected $fileDeps = [];
74  // In-object cache for message blob (keyed by language)
75  protected $msgBlobs = [];
76  // In-object cache for version hash
77  protected $versionHash = [];
78  // In-object cache for module content
79  protected $contents = [];
80 
84  protected $config;
85 
89  protected $deprecated = false;
90 
94  protected $logger;
95 
102  public function getName() {
103  return $this->name;
104  }
105 
112  public function setName( $name ) {
113  $this->name = $name;
114  }
115 
123  public function getOrigin() {
124  return $this->origin;
125  }
126 
131  public function getFlip( $context ) {
132  return MediaWikiServices::getInstance()->getContentLanguage()->getDir() !==
133  $context->getDirection();
134  }
135 
141  public function getDeprecationInformation() {
142  $deprecationInfo = $this->deprecated;
143  if ( $deprecationInfo ) {
144  $name = $this->getName();
145  $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
146  if ( is_string( $deprecationInfo ) ) {
147  $warning .= "\n" . $deprecationInfo;
148  }
149  return Xml::encodeJsCall(
150  'mw.log.warn',
151  [ $warning ]
152  );
153  } else {
154  return '';
155  }
156  }
157 
178  // Stub, override expected
179  return '';
180  }
181 
187  public function getTemplates() {
188  // Stub, override expected.
189  return [];
190  }
191 
196  public function getConfig() {
197  if ( $this->config === null ) {
198  // Ugh, fall back to default
199  $this->config = MediaWikiServices::getInstance()->getMainConfig();
200  }
201 
202  return $this->config;
203  }
204 
209  public function setConfig( Config $config ) {
210  $this->config = $config;
211  }
212 
218  public function setLogger( LoggerInterface $logger ) {
219  $this->logger = $logger;
220  }
221 
226  protected function getLogger() {
227  if ( !$this->logger ) {
228  $this->logger = new NullLogger();
229  }
230  return $this->logger;
231  }
232 
248  $resourceLoader = $context->getResourceLoader();
249  $derivative = new DerivativeResourceLoaderContext( $context );
250  $derivative->setModules( [ $this->getName() ] );
251  $derivative->setOnly( 'scripts' );
252  $derivative->setDebug( true );
253 
254  $url = $resourceLoader->createLoaderURL(
255  $this->getSource(),
256  $derivative
257  );
258 
259  return [ $url ];
260  }
261 
268  public function supportsURLLoading() {
269  return true;
270  }
271 
281  // Stub, override expected
282  return [];
283  }
284 
295  $resourceLoader = $context->getResourceLoader();
296  $derivative = new DerivativeResourceLoaderContext( $context );
297  $derivative->setModules( [ $this->getName() ] );
298  $derivative->setOnly( 'styles' );
299  $derivative->setDebug( true );
300 
301  $url = $resourceLoader->createLoaderURL(
302  $this->getSource(),
303  $derivative
304  );
305 
306  return [ 'all' => [ $url ] ];
307  }
308 
316  public function getMessages() {
317  // Stub, override expected
318  return [];
319  }
320 
326  public function getGroup() {
327  // Stub, override expected
328  return null;
329  }
330 
336  public function getSource() {
337  // Stub, override expected
338  return 'local';
339  }
340 
348  public function isRaw() {
349  return false;
350  }
351 
364  public function getDependencies( ResourceLoaderContext $context = null ) {
365  // Stub, override expected
366  return [];
367  }
368 
374  public function getTargets() {
375  return $this->targets;
376  }
377 
384  public function getType() {
385  return self::LOAD_GENERAL;
386  }
387 
402  public function getSkipFunction() {
403  return null;
404  }
405 
415  $vary = $context->getSkin() . '|' . $context->getLanguage();
416 
417  // Try in-object cache first
418  if ( !isset( $this->fileDeps[$vary] ) ) {
419  $dbr = wfGetDB( DB_REPLICA );
420  $deps = $dbr->selectField( 'module_deps',
421  'md_deps',
422  [
423  'md_module' => $this->getName(),
424  'md_skin' => $vary,
425  ],
426  __METHOD__
427  );
428 
429  if ( !is_null( $deps ) ) {
430  $this->fileDeps[$vary] = self::expandRelativePaths(
431  (array)json_decode( $deps, true )
432  );
433  } else {
434  $this->fileDeps[$vary] = [];
435  }
436  }
437  return $this->fileDeps[$vary];
438  }
439 
450  $vary = $context->getSkin() . '|' . $context->getLanguage();
451  $this->fileDeps[$vary] = $files;
452  }
453 
461  protected function saveFileDependencies( ResourceLoaderContext $context, $localFileRefs ) {
462  try {
463  // Related bugs and performance considerations:
464  // 1. Don't needlessly change the database value with the same list in a
465  // different order or with duplicates.
466  // 2. Use relative paths to avoid ghost entries when $IP changes. (T111481)
467  // 3. Don't needlessly replace the database with the same value
468  // just because $IP changed (e.g. when upgrading a wiki).
469  // 4. Don't create an endless replace loop on every request for this
470  // module when '../' is used anywhere. Even though both are expanded
471  // (one expanded by getFileDependencies from the DB, the other is
472  // still raw as originally read by RL), the latter has not
473  // been normalized yet.
474 
475  // Normalise
476  $localFileRefs = array_values( array_unique( $localFileRefs ) );
477  sort( $localFileRefs );
478  $localPaths = self::getRelativePaths( $localFileRefs );
479  $storedPaths = self::getRelativePaths( $this->getFileDependencies( $context ) );
480 
481  if ( $localPaths === $storedPaths ) {
482  // Unchanged. Avoid needless database query (especially master conn!).
483  return;
484  }
485 
486  // The file deps list has changed, we want to update it.
487  $vary = $context->getSkin() . '|' . $context->getLanguage();
489  $key = $cache->makeKey( __METHOD__, $this->getName(), $vary );
490  $scopeLock = $cache->getScopedLock( $key, 0 );
491  if ( !$scopeLock ) {
492  // Another request appears to be doing this update already.
493  // Avoid write slams (T124649).
494  return;
495  }
496 
497  // No needless escaping as this isn't HTML output.
498  // Only stored in the database and parsed in PHP.
499  $deps = json_encode( $localPaths, JSON_UNESCAPED_SLASHES );
500  $dbw = wfGetDB( DB_MASTER );
501  $dbw->upsert( 'module_deps',
502  [
503  'md_module' => $this->getName(),
504  'md_skin' => $vary,
505  'md_deps' => $deps,
506  ],
507  [ [ 'md_module', 'md_skin' ] ],
508  [
509  'md_deps' => $deps,
510  ]
511  );
512 
513  if ( $dbw->trxLevel() ) {
514  $dbw->onTransactionResolution(
515  function () use ( &$scopeLock ) {
516  ScopedCallback::consume( $scopeLock ); // release after commit
517  },
518  __METHOD__
519  );
520  }
521  } catch ( Exception $e ) {
522  // Probably a DB failure. Either the read query from getFileDependencies(),
523  // or the write query above.
524  wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" );
525  }
526  }
527 
538  public static function getRelativePaths( array $filePaths ) {
539  global $IP;
540  return array_map( function ( $path ) use ( $IP ) {
541  return RelPath::getRelativePath( $path, $IP );
542  }, $filePaths );
543  }
544 
552  public static function expandRelativePaths( array $filePaths ) {
553  global $IP;
554  return array_map( function ( $path ) use ( $IP ) {
555  return RelPath::joinPath( $IP, $path );
556  }, $filePaths );
557  }
558 
567  if ( !$this->getMessages() ) {
568  // Don't bother consulting MessageBlobStore
569  return null;
570  }
571  // Message blobs may only vary language, not by context keys
572  $lang = $context->getLanguage();
573  if ( !isset( $this->msgBlobs[$lang] ) ) {
574  $this->getLogger()->warning( 'Message blob for {module} should have been preloaded', [
575  'module' => $this->getName(),
576  ] );
577  $store = $context->getResourceLoader()->getMessageBlobStore();
578  $this->msgBlobs[$lang] = $store->getBlob( $this, $lang );
579  }
580  return $this->msgBlobs[$lang];
581  }
582 
592  public function setMessageBlob( $blob, $lang ) {
593  $this->msgBlobs[$lang] = $blob;
594  }
595 
610  final public function getHeaders( ResourceLoaderContext $context ) {
611  $headers = [];
612 
613  $formattedLinks = [];
614  foreach ( $this->getPreloadLinks( $context ) as $url => $attribs ) {
615  $link = "<{$url}>;rel=preload";
616  foreach ( $attribs as $key => $val ) {
617  $link .= ";{$key}={$val}";
618  }
619  $formattedLinks[] = $link;
620  }
621  if ( $formattedLinks ) {
622  $headers[] = 'Link: ' . implode( ',', $formattedLinks );
623  }
624 
625  return $headers;
626  }
627 
668  return [];
669  }
670 
679  return [];
680  }
681 
690  $contextHash = $context->getHash();
691  // Cache this expensive operation. This calls builds the scripts, styles, and messages
692  // content which typically involves filesystem and/or database access.
693  if ( !array_key_exists( $contextHash, $this->contents ) ) {
694  $this->contents[$contextHash] = $this->buildContent( $context );
695  }
696  return $this->contents[$contextHash];
697  }
698 
706  final protected function buildContent( ResourceLoaderContext $context ) {
707  $rl = $context->getResourceLoader();
708  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
709  $statStart = microtime( true );
710 
711  // This MUST build both scripts and styles, regardless of whether $context->getOnly()
712  // is 'scripts' or 'styles' because the result is used by getVersionHash which
713  // must be consistent regardless of the 'only' filter on the current request.
714  // Also, when introducing new module content resources (e.g. templates, headers),
715  // these should only be included in the array when they are non-empty so that
716  // existing modules not using them do not get their cache invalidated.
717  $content = [];
718 
719  // Scripts
720  // If we are in debug mode, we'll want to return an array of URLs if possible
721  // However, we can't do this if the module doesn't support it.
722  // We also can't do this if there is an only= parameter, because we have to give
723  // the module a way to return a load.php URL without causing an infinite loop
724  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
725  $scripts = $this->getScriptURLsForDebug( $context );
726  } else {
727  $scripts = $this->getScript( $context );
728  // Make the script safe to concatenate by making sure there is at least one
729  // trailing new line at the end of the content. Previously, this looked for
730  // a semi-colon instead, but that breaks concatenation if the semicolon
731  // is inside a comment like "// foo();". Instead, simply use a
732  // line break as separator which matches JavaScript native logic for implicitly
733  // ending statements even if a semi-colon is missing.
734  // Bugs: T29054, T162719.
735  if ( is_string( $scripts )
736  && strlen( $scripts )
737  && substr( $scripts, -1 ) !== "\n"
738  ) {
739  $scripts .= "\n";
740  }
741  }
742  $content['scripts'] = $scripts;
743 
744  $styles = [];
745  // Don't create empty stylesheets like [ '' => '' ] for modules
746  // that don't *have* any stylesheets (T40024).
747  $stylePairs = $this->getStyles( $context );
748  if ( count( $stylePairs ) ) {
749  // If we are in debug mode without &only= set, we'll want to return an array of URLs
750  // See comment near shouldIncludeScripts() for more details
751  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
752  $styles = [
753  'url' => $this->getStyleURLsForDebug( $context )
754  ];
755  } else {
756  // Minify CSS before embedding in mw.loader.implement call
757  // (unless in debug mode)
758  if ( !$context->getDebug() ) {
759  foreach ( $stylePairs as $media => $style ) {
760  // Can be either a string or an array of strings.
761  if ( is_array( $style ) ) {
762  $stylePairs[$media] = [];
763  foreach ( $style as $cssText ) {
764  if ( is_string( $cssText ) ) {
765  $stylePairs[$media][] =
766  ResourceLoader::filter( 'minify-css', $cssText );
767  }
768  }
769  } elseif ( is_string( $style ) ) {
770  $stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
771  }
772  }
773  }
774  // Wrap styles into @media groups as needed and flatten into a numerical array
775  $styles = [
776  'css' => $rl->makeCombinedStyles( $stylePairs )
777  ];
778  }
779  }
780  $content['styles'] = $styles;
781 
782  // Messages
783  $blob = $this->getMessageBlob( $context );
784  if ( $blob ) {
785  $content['messagesBlob'] = $blob;
786  }
787 
788  $templates = $this->getTemplates();
789  if ( $templates ) {
790  $content['templates'] = $templates;
791  }
792 
793  $headers = $this->getHeaders( $context );
794  if ( $headers ) {
795  $content['headers'] = $headers;
796  }
797 
798  $statTiming = microtime( true ) - $statStart;
799  $statName = strtr( $this->getName(), '.', '_' );
800  $stats->timing( "resourceloader_build.all", 1000 * $statTiming );
801  $stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
802 
803  return $content;
804  }
805 
824  // Cache this somewhat expensive operation. Especially because some classes
825  // (e.g. startup module) iterate more than once over all modules to get versions.
826  $contextHash = $context->getHash();
827  if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
828  if ( $this->enableModuleContentVersion() ) {
829  // Detect changes directly by hashing the module contents.
830  $str = json_encode( $this->getModuleContent( $context ) );
831  } else {
832  // Infer changes based on definition and other metrics
833  $summary = $this->getDefinitionSummary( $context );
834  if ( !isset( $summary['_class'] ) ) {
835  throw new LogicException( 'getDefinitionSummary must call parent method' );
836  }
837  $str = json_encode( $summary );
838  }
839 
840  $this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
841  }
842  return $this->versionHash[$contextHash];
843  }
844 
854  public function enableModuleContentVersion() {
855  return false;
856  }
857 
902  return [
903  '_class' => static::class,
904  // Make sure that when filter cache for minification is invalidated,
905  // we also change the HTTP urls and mw.loader.store keys (T176884).
906  '_cacheVersion' => ResourceLoader::CACHE_VERSION,
907  ];
908  }
909 
920  return false;
921  }
922 
934  return $this->getGroup() === 'private';
935  }
936 
938  private static $jsParser;
939  private static $parseCacheVersion = 1;
940 
949  protected function validateScriptFile( $fileName, $contents ) {
950  if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
951  return $contents;
952  }
953  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
954  return $cache->getWithSetCallback(
955  $cache->makeGlobalKey(
956  'resourceloader',
957  'jsparse',
958  self::$parseCacheVersion,
959  md5( $contents ),
960  $fileName
961  ),
962  $cache::TTL_WEEK,
963  function () use ( $contents, $fileName ) {
965  $err = null;
966  try {
967  Wikimedia\suppressWarnings();
968  $parser->parse( $contents, $fileName, 1 );
969  } catch ( Exception $e ) {
970  $err = $e;
971  } finally {
972  Wikimedia\restoreWarnings();
973  }
974  if ( $err ) {
975  // Send the error to the browser console client-side.
976  // By returning this as replacement for the actual script,
977  // we ensure modules are safe to load in a batch request,
978  // without causing other unrelated modules to break.
979  return 'mw.log.error(' .
980  Xml::encodeJsVar( 'JavaScript parse error: ' . $err->getMessage() ) .
981  ');';
982  }
983  return $contents;
984  }
985  );
986  }
987 
991  protected static function javaScriptParser() {
992  if ( !self::$jsParser ) {
993  self::$jsParser = new JSParser();
994  }
995  return self::$jsParser;
996  }
997 
1005  protected static function safeFilemtime( $filePath ) {
1006  Wikimedia\suppressWarnings();
1007  $mtime = filemtime( $filePath ) ?: 1;
1008  Wikimedia\restoreWarnings();
1009  return $mtime;
1010  }
1011 
1020  protected static function safeFileHash( $filePath ) {
1021  return FileContentsHasher::getFileContentsHash( $filePath );
1022  }
1023 }
ResourceLoaderModule\LOAD_GENERAL
const LOAD_GENERAL
Definition: ResourceLoaderModule.php:45
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
ResourceLoaderModule\getFlip
getFlip( $context)
Definition: ResourceLoaderModule.php:131
ResourceLoaderModule\supportsURLLoading
supportsURLLoading()
Whether this module supports URL loading.
Definition: ResourceLoaderModule.php:268
ResourceLoaderModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's CSS in debug mode.
Definition: ResourceLoaderModule.php:294
ResourceLoaderModule\setMessageBlob
setMessageBlob( $blob, $lang)
Set in-object cache for message blobs.
Definition: ResourceLoaderModule.php:592
ResourceLoaderModule\setFileDependencies
setFileDependencies(ResourceLoaderContext $context, $files)
Set in-object cache for file dependencies.
Definition: ResourceLoaderModule.php:449
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:356
$context
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2636
ResourceLoaderModule\TYPE_COMBINED
const TYPE_COMBINED
Definition: ResourceLoaderModule.php:39
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ResourceLoaderModule\ORIGIN_CORE_SITEWIDE
const ORIGIN_CORE_SITEWIDE
Definition: ResourceLoaderModule.php:48
captcha-old.count
count
Definition: captcha-old.py:249
ResourceLoaderModule\ORIGIN_USER_SITEWIDE
const ORIGIN_USER_SITEWIDE
Definition: ResourceLoaderModule.php:55
ResourceLoaderModule\isRaw
isRaw()
Whether this module's JS expects to work without the client-side ResourceLoader module.
Definition: ResourceLoaderModule.php:348
ResourceLoaderModule\$versionHash
$versionHash
Definition: ResourceLoaderModule.php:77
ResourceLoaderModule\safeFilemtime
static safeFilemtime( $filePath)
Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist.
Definition: ResourceLoaderModule.php:1005
ResourceLoaderModule\setName
setName( $name)
Set this module's name.
Definition: ResourceLoaderModule.php:112
ResourceLoaderModule\setLogger
setLogger(LoggerInterface $logger)
Definition: ResourceLoaderModule.php:218
ResourceLoaderModule\saveFileDependencies
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:461
ResourceLoaderModule\getHeaders
getHeaders(ResourceLoaderContext $context)
Get headers to send as part of a module web response.
Definition: ResourceLoaderModule.php:610
ResourceLoaderModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderModule.php:384
ResourceLoaderModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderModule.php:374
ResourceLoaderModule\shouldEmbedModule
shouldEmbedModule(ResourceLoaderContext $context)
Check whether this module should be embeded rather than linked.
Definition: ResourceLoaderModule.php:933
ResourceLoaderModule\$origin
$origin
Definition: ResourceLoaderModule.php:67
$resourceLoader
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition: hooks.txt:2636
ResourceLoaderModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
Definition: ResourceLoaderModule.php:280
ResourceLoaderModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderModule.php:187
Xml\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:659
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1043
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ResourceLoaderModule\buildContent
buildContent(ResourceLoaderContext $context)
Bundle all resources attached to this module into an array.
Definition: ResourceLoaderModule.php:706
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:89
ResourceLoaderModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Definition: ResourceLoaderModule.php:678
$dbr
$dbr
Definition: testCompression.php:50
ResourceLoaderModule\enableModuleContentVersion
enableModuleContentVersion()
Whether to generate version hash based on module content.
Definition: ResourceLoaderModule.php:854
Xml\encodeJsCall
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
Definition: Xml.php:677
name
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
Config
Interface for configuration instances.
Definition: Config.php:28
ResourceLoaderModule\getGroup
getGroup()
Get the group this module is in.
Definition: ResourceLoaderModule.php:326
ResourceLoaderModule\$jsParser
static JSParser $jsParser
Lazy-initialized; use self::javaScriptParser()
Definition: ResourceLoaderModule.php:938
ResourceLoaderModule\getLogger
getLogger()
Definition: ResourceLoaderModule.php:226
ResourceLoaderModule\getScript
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Definition: ResourceLoaderModule.php:177
$blob
$blob
Definition: testCompression.php:65
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
ResourceLoaderModule\$contents
$contents
Definition: ResourceLoaderModule.php:79
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1985
$IP
$IP
Definition: update.php:3
ResourceLoaderModule\TYPE_SCRIPTS
const TYPE_SCRIPTS
Definition: ResourceLoaderModule.php:37
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
contents
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their contents
Definition: database.txt:2
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1802
ResourceLoaderModule\expandRelativePaths
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
Definition: ResourceLoaderModule.php:552
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:166
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ResourceLoaderModule\getOrigin
getOrigin()
Get this module's origin.
Definition: ResourceLoaderModule.php:123
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:566
ResourceLoaderModule\$parseCacheVersion
static $parseCacheVersion
Definition: ResourceLoaderModule.php:939
ResourceLoaderModule\isKnownEmpty
isKnownEmpty(ResourceLoaderContext $context)
Check whether this module is known to be empty.
Definition: ResourceLoaderModule.php:919
ResourceLoaderModule\getDeprecationInformation
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
Definition: ResourceLoaderModule.php:141
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
ResourceLoaderModule\safeFileHash
static safeFileHash( $filePath)
Compute a non-cryptographic string hash of a file's contents.
Definition: ResourceLoaderModule.php:1020
ResourceLoaderModule\ORIGIN_USER_INDIVIDUAL
const ORIGIN_USER_INDIVIDUAL
Definition: ResourceLoaderModule.php:58
ResourceLoaderModule\$deprecated
array bool $deprecated
Definition: ResourceLoaderModule.php:89
ResourceLoaderModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Get a list of modules this module depends on.
Definition: ResourceLoaderModule.php:364
ResourceLoaderModule\$targets
$targets
Definition: ResourceLoaderModule.php:70
ResourceLoaderModule\getPreloadLinks
getPreloadLinks(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
Definition: ResourceLoaderModule.php:667
DerivativeResourceLoaderContext
Allows changing specific properties of a context object, without changing the main one.
Definition: DerivativeResourceLoaderContext.php:30
ResourceLoaderModule\$name
$name
Definition: ResourceLoaderModule.php:69
ResourceLoaderModule\LOAD_STYLES
const LOAD_STYLES
Definition: ResourceLoaderModule.php:43
ResourceLoaderModule\getMessages
getMessages()
Get the messages needed for this module.
Definition: ResourceLoaderModule.php:316
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
Definition: ResourceLoaderModule.php:949
ResourceLoaderModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderModule.php:901
ResourceLoaderModule\ORIGIN_CORE_INDIVIDUAL
const ORIGIN_CORE_INDIVIDUAL
Definition: ResourceLoaderModule.php:51
ResourceLoaderModule\getModuleContent
getModuleContent(ResourceLoaderContext $context)
Get an array of this module's resources.
Definition: ResourceLoaderModule.php:689
ResourceLoaderModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderModule.php:402
ResourceLoaderModule\ORIGIN_ALL
const ORIGIN_ALL
Definition: ResourceLoaderModule.php:61
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:35
ResourceLoaderModule\$config
Config $config
Definition: ResourceLoaderModule.php:84
ResourceLoaderModule\$logger
LoggerInterface $logger
Definition: ResourceLoaderModule.php:94
ResourceLoaderModule\$fileDeps
$fileDeps
Definition: ResourceLoaderModule.php:73
$cache
$cache
Definition: mcc.php:33
ResourceLoaderModule\setConfig
setConfig(Config $config)
Definition: ResourceLoaderModule.php:209
ResourceLoaderModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
Definition: ResourceLoaderModule.php:247
$path
$path
Definition: NoLocalSettings.php:25
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ResourceLoaderModule\getRelativePaths
static getRelativePaths(array $filePaths)
Make file paths relative to MediaWiki directory.
Definition: ResourceLoaderModule.php:538
$link
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3053
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:414
ResourceLoaderModule\TYPE_STYLES
const TYPE_STYLES
Definition: ResourceLoaderModule.php:38
ResourceLoaderModule\getVersionHash
getVersionHash(ResourceLoaderContext $context)
Get a string identifying the current version of this module in a given context.
Definition: ResourceLoaderModule.php:823
$content
$content
Definition: pageupdater.txt:72
ResourceLoaderModule\getSource
getSource()
Get the source of this module.
Definition: ResourceLoaderModule.php:336
JSParser
Definition: jsminplus.php:674
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ResourceLoaderModule\javaScriptParser
static javaScriptParser()
Definition: ResourceLoaderModule.php:991
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
ResourceLoaderModule\$msgBlobs
$msgBlobs
Definition: ResourceLoaderModule.php:75
ResourceLoaderModule\getName
getName()
Get this module's name.
Definition: ResourceLoaderModule.php:102
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:196