MediaWiki  1.29.2
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\ScopedCallback;
30 
34 abstract class ResourceLoaderModule implements LoggerAwareInterface {
35  # Type of resource
36  const TYPE_SCRIPTS = 'scripts';
37  const TYPE_STYLES = 'styles';
38  const TYPE_COMBINED = 'combined';
39 
40  # Desired load type
41  // Module only has styles (loaded via <style> or <link rel=stylesheet>)
42  const LOAD_STYLES = 'styles';
43  // Module may have other resources (loaded via mw.loader from a script)
44  const LOAD_GENERAL = 'general';
45 
46  # sitewide core module like a skin file or jQuery component
48 
49  # per-user module generated by the software
51 
52  # sitewide module generated from user-editable files, like MediaWiki:Common.js, or
53  # modules accessible to multiple users, such as those generated by the Gadgets extension.
55 
56  # per-user module generated from user-editable files, like User:Me/vector.js
58 
59  # an access constant; make sure this is kept as the largest number in this group
60  const ORIGIN_ALL = 10;
61 
62  # script and style modules form a hierarchy of trustworthiness, with core modules like
63  # skins and jQuery as most trustworthy, and user scripts as least trustworthy. We can
64  # limit the types of scripts and styles we allow to load on, say, sensitive special
65  # pages like Special:UserLogin and Special:Preferences
67 
68  /* Protected Members */
69 
70  protected $name = null;
71  protected $targets = [ 'desktop' ];
72 
73  // In-object cache for file dependencies
74  protected $fileDeps = [];
75  // In-object cache for message blob (keyed by language)
76  protected $msgBlobs = [];
77  // In-object cache for version hash
78  protected $versionHash = [];
79  // In-object cache for module content
80  protected $contents = [];
81 
85  protected $config;
86 
90  protected $deprecated = false;
91 
95  protected $logger;
96 
97  /* Methods */
98 
105  public function getName() {
106  return $this->name;
107  }
108 
115  public function setName( $name ) {
116  $this->name = $name;
117  }
118 
126  public function getOrigin() {
127  return $this->origin;
128  }
129 
134  public function getFlip( $context ) {
136 
137  return $wgContLang->getDir() !== $context->getDirection();
138  }
139 
145  protected function getDeprecationInformation() {
146  $deprecationInfo = $this->deprecated;
147  if ( $deprecationInfo ) {
148  $name = $this->getName();
149  $warning = 'This page is using the deprecated ResourceLoader module "' . $name . '".';
150  if ( is_string( $deprecationInfo ) ) {
151  $warning .= "\n" . $deprecationInfo;
152  }
153  return Xml::encodeJsCall(
154  'mw.log.warn',
155  [ $warning ]
156  );
157  } else {
158  return '';
159  }
160  }
161 
170  // Stub, override expected
171  return '';
172  }
173 
179  public function getTemplates() {
180  // Stub, override expected.
181  return [];
182  }
183 
188  public function getConfig() {
189  if ( $this->config === null ) {
190  // Ugh, fall back to default
191  $this->config = MediaWikiServices::getInstance()->getMainConfig();
192  }
193 
194  return $this->config;
195  }
196 
201  public function setConfig( Config $config ) {
202  $this->config = $config;
203  }
204 
210  public function setLogger( LoggerInterface $logger ) {
211  $this->logger = $logger;
212  }
213 
218  protected function getLogger() {
219  if ( !$this->logger ) {
220  $this->logger = new NullLogger();
221  }
222  return $this->logger;
223  }
224 
240  $resourceLoader = $context->getResourceLoader();
241  $derivative = new DerivativeResourceLoaderContext( $context );
242  $derivative->setModules( [ $this->getName() ] );
243  $derivative->setOnly( 'scripts' );
244  $derivative->setDebug( true );
245 
246  $url = $resourceLoader->createLoaderURL(
247  $this->getSource(),
248  $derivative
249  );
250 
251  return [ $url ];
252  }
253 
260  public function supportsURLLoading() {
261  return true;
262  }
263 
273  // Stub, override expected
274  return [];
275  }
276 
287  $resourceLoader = $context->getResourceLoader();
288  $derivative = new DerivativeResourceLoaderContext( $context );
289  $derivative->setModules( [ $this->getName() ] );
290  $derivative->setOnly( 'styles' );
291  $derivative->setDebug( true );
292 
293  $url = $resourceLoader->createLoaderURL(
294  $this->getSource(),
295  $derivative
296  );
297 
298  return [ 'all' => [ $url ] ];
299  }
300 
308  public function getMessages() {
309  // Stub, override expected
310  return [];
311  }
312 
318  public function getGroup() {
319  // Stub, override expected
320  return null;
321  }
322 
328  public function getSource() {
329  // Stub, override expected
330  return 'local';
331  }
332 
339  public function getPosition() {
340  return 'top';
341  }
342 
350  public function isRaw() {
351  return false;
352  }
353 
366  public function getDependencies( ResourceLoaderContext $context = null ) {
367  // Stub, override expected
368  return [];
369  }
370 
376  public function getTargets() {
377  return $this->targets;
378  }
379 
386  public function getType() {
387  return self::LOAD_GENERAL;
388  }
389 
404  public function getSkipFunction() {
405  return null;
406  }
407 
417  $vary = $context->getSkin() . '|' . $context->getLanguage();
418 
419  // Try in-object cache first
420  if ( !isset( $this->fileDeps[$vary] ) ) {
421  $dbr = wfGetDB( DB_REPLICA );
422  $deps = $dbr->selectField( 'module_deps',
423  'md_deps',
424  [
425  'md_module' => $this->getName(),
426  'md_skin' => $vary,
427  ],
428  __METHOD__
429  );
430 
431  if ( !is_null( $deps ) ) {
432  $this->fileDeps[$vary] = self::expandRelativePaths(
433  (array)FormatJson::decode( $deps, true )
434  );
435  } else {
436  $this->fileDeps[$vary] = [];
437  }
438  }
439  return $this->fileDeps[$vary];
440  }
441 
452  $vary = $context->getSkin() . '|' . $context->getLanguage();
453  $this->fileDeps[$vary] = $files;
454  }
455 
463  protected function saveFileDependencies( ResourceLoaderContext $context, $localFileRefs ) {
464 
465  try {
466  // Related bugs and performance considerations:
467  // 1. Don't needlessly change the database value with the same list in a
468  // different order or with duplicates.
469  // 2. Use relative paths to avoid ghost entries when $IP changes. (T111481)
470  // 3. Don't needlessly replace the database with the same value
471  // just because $IP changed (e.g. when upgrading a wiki).
472  // 4. Don't create an endless replace loop on every request for this
473  // module when '../' is used anywhere. Even though both are expanded
474  // (one expanded by getFileDependencies from the DB, the other is
475  // still raw as originally read by RL), the latter has not
476  // been normalized yet.
477 
478  // Normalise
479  $localFileRefs = array_values( array_unique( $localFileRefs ) );
480  sort( $localFileRefs );
481  $localPaths = self::getRelativePaths( $localFileRefs );
482 
483  $storedPaths = self::getRelativePaths( $this->getFileDependencies( $context ) );
484  // If the list has been modified since last time we cached it, update the cache
485  if ( $localPaths !== $storedPaths ) {
486  $vary = $context->getSkin() . '|' . $context->getLanguage();
488  $key = $cache->makeKey( __METHOD__, $this->getName(), $vary );
489  $scopeLock = $cache->getScopedLock( $key, 0 );
490  if ( !$scopeLock ) {
491  return; // T124649; avoid write slams
492  }
493 
494  $deps = FormatJson::encode( $localPaths );
495  $dbw = wfGetDB( DB_MASTER );
496  $dbw->upsert( 'module_deps',
497  [
498  'md_module' => $this->getName(),
499  'md_skin' => $vary,
500  'md_deps' => $deps,
501  ],
502  [ 'md_module', 'md_skin' ],
503  [
504  'md_deps' => $deps,
505  ]
506  );
507 
508  if ( $dbw->trxLevel() ) {
509  $dbw->onTransactionResolution(
510  function () use ( &$scopeLock ) {
511  ScopedCallback::consume( $scopeLock ); // release after commit
512  },
513  __METHOD__
514  );
515  }
516  }
517  } catch ( Exception $e ) {
518  wfDebugLog( 'resourceloader', __METHOD__ . ": failed to update DB: $e" );
519  }
520  }
521 
532  public static function getRelativePaths( array $filePaths ) {
533  global $IP;
534  return array_map( function ( $path ) use ( $IP ) {
535  return RelPath\getRelativePath( $path, $IP );
536  }, $filePaths );
537  }
538 
546  public static function expandRelativePaths( array $filePaths ) {
547  global $IP;
548  return array_map( function ( $path ) use ( $IP ) {
549  return RelPath\joinPath( $IP, $path );
550  }, $filePaths );
551  }
552 
561  if ( !$this->getMessages() ) {
562  // Don't bother consulting MessageBlobStore
563  return null;
564  }
565  // Message blobs may only vary language, not by context keys
566  $lang = $context->getLanguage();
567  if ( !isset( $this->msgBlobs[$lang] ) ) {
568  $this->getLogger()->warning( 'Message blob for {module} should have been preloaded', [
569  'module' => $this->getName(),
570  ] );
571  $store = $context->getResourceLoader()->getMessageBlobStore();
572  $this->msgBlobs[$lang] = $store->getBlob( $this, $lang );
573  }
574  return $this->msgBlobs[$lang];
575  }
576 
586  public function setMessageBlob( $blob, $lang ) {
587  $this->msgBlobs[$lang] = $blob;
588  }
589 
598  return [];
599  }
600 
609  $contextHash = $context->getHash();
610  // Cache this expensive operation. This calls builds the scripts, styles, and messages
611  // content which typically involves filesystem and/or database access.
612  if ( !array_key_exists( $contextHash, $this->contents ) ) {
613  $this->contents[$contextHash] = $this->buildContent( $context );
614  }
615  return $this->contents[$contextHash];
616  }
617 
625  final protected function buildContent( ResourceLoaderContext $context ) {
626  $rl = $context->getResourceLoader();
627  $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
628  $statStart = microtime( true );
629 
630  // Only include properties that are relevant to this context (e.g. only=scripts)
631  // and that are non-empty (e.g. don't include "templates" for modules without
632  // templates). This helps prevent invalidating cache for all modules when new
633  // optional properties are introduced.
634  $content = [];
635 
636  // Scripts
637  if ( $context->shouldIncludeScripts() ) {
638  // If we are in debug mode, we'll want to return an array of URLs if possible
639  // However, we can't do this if the module doesn't support it
640  // We also can't do this if there is an only= parameter, because we have to give
641  // the module a way to return a load.php URL without causing an infinite loop
642  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
643  $scripts = $this->getScriptURLsForDebug( $context );
644  } else {
645  $scripts = $this->getScript( $context );
646  // rtrim() because there are usually a few line breaks
647  // after the last ';'. A new line at EOF, a new line
648  // added by ResourceLoaderFileModule::readScriptFiles, etc.
649  if ( is_string( $scripts )
650  && strlen( $scripts )
651  && substr( rtrim( $scripts ), -1 ) !== ';'
652  ) {
653  // Append semicolon to prevent weird bugs caused by files not
654  // terminating their statements right (T29054)
655  $scripts .= ";\n";
656  }
657  }
658  $content['scripts'] = $scripts;
659  }
660 
661  // Styles
662  if ( $context->shouldIncludeStyles() ) {
663  $styles = [];
664  // Don't create empty stylesheets like [ '' => '' ] for modules
665  // that don't *have* any stylesheets (T40024).
666  $stylePairs = $this->getStyles( $context );
667  if ( count( $stylePairs ) ) {
668  // If we are in debug mode without &only= set, we'll want to return an array of URLs
669  // See comment near shouldIncludeScripts() for more details
670  if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
671  $styles = [
672  'url' => $this->getStyleURLsForDebug( $context )
673  ];
674  } else {
675  // Minify CSS before embedding in mw.loader.implement call
676  // (unless in debug mode)
677  if ( !$context->getDebug() ) {
678  foreach ( $stylePairs as $media => $style ) {
679  // Can be either a string or an array of strings.
680  if ( is_array( $style ) ) {
681  $stylePairs[$media] = [];
682  foreach ( $style as $cssText ) {
683  if ( is_string( $cssText ) ) {
684  $stylePairs[$media][] =
685  ResourceLoader::filter( 'minify-css', $cssText );
686  }
687  }
688  } elseif ( is_string( $style ) ) {
689  $stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
690  }
691  }
692  }
693  // Wrap styles into @media groups as needed and flatten into a numerical array
694  $styles = [
695  'css' => $rl->makeCombinedStyles( $stylePairs )
696  ];
697  }
698  }
699  $content['styles'] = $styles;
700  }
701 
702  // Messages
703  $blob = $this->getMessageBlob( $context );
704  if ( $blob ) {
705  $content['messagesBlob'] = $blob;
706  }
707 
708  $templates = $this->getTemplates();
709  if ( $templates ) {
710  $content['templates'] = $templates;
711  }
712 
713  $statTiming = microtime( true ) - $statStart;
714  $statName = strtr( $this->getName(), '.', '_' );
715  $stats->timing( "resourceloader_build.all", 1000 * $statTiming );
716  $stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
717 
718  return $content;
719  }
720 
744  // The startup module produces a manifest with versions representing the entire module.
745  // Typically, the request for the startup module itself has only=scripts. That must apply
746  // only to the startup module content, and not to the module version computed here.
748  $context->setModules( [] );
749  // Version hash must cover all resources, regardless of startup request itself.
750  $context->setOnly( null );
751  // Compute version hash based on content, not debug urls.
752  $context->setDebug( false );
753 
754  // Cache this somewhat expensive operation. Especially because some classes
755  // (e.g. startup module) iterate more than once over all modules to get versions.
756  $contextHash = $context->getHash();
757  if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
758 
759  if ( $this->enableModuleContentVersion() ) {
760  // Detect changes directly
761  $str = json_encode( $this->getModuleContent( $context ) );
762  } else {
763  // Infer changes based on definition and other metrics
764  $summary = $this->getDefinitionSummary( $context );
765  if ( !isset( $summary['_cacheEpoch'] ) ) {
766  throw new LogicException( 'getDefinitionSummary must call parent method' );
767  }
768  $str = json_encode( $summary );
769 
770  $mtime = $this->getModifiedTime( $context );
771  if ( $mtime !== null ) {
772  // Support: MediaWiki 1.25 and earlier
773  $str .= strval( $mtime );
774  }
775 
776  $mhash = $this->getModifiedHash( $context );
777  if ( $mhash !== null ) {
778  // Support: MediaWiki 1.25 and earlier
779  $str .= strval( $mhash );
780  }
781  }
782 
783  $this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
784  }
785  return $this->versionHash[$contextHash];
786  }
787 
797  public function enableModuleContentVersion() {
798  return false;
799  }
800 
845  return [
846  '_class' => static::class,
847  '_cacheEpoch' => $this->getConfig()->get( 'CacheEpoch' ),
848  ];
849  }
850 
859  return null;
860  }
861 
870  return null;
871  }
872 
885  if ( !is_string( $this->getModifiedHash( $context ) ) ) {
886  return 1;
887  }
888  // Dummy that is > 1
889  return 2;
890  }
891 
901  if ( $this->getDefinitionSummary( $context ) === null ) {
902  return 1;
903  }
904  // Dummy that is > 1
905  return 2;
906  }
907 
918  return false;
919  }
920 
922  private static $jsParser;
923  private static $parseCacheVersion = 1;
924 
933  protected function validateScriptFile( $fileName, $contents ) {
934  if ( $this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) {
935  // Try for cache hit
937  $key = $cache->makeKey(
938  'resourceloader',
939  'jsparse',
940  self::$parseCacheVersion,
941  md5( $contents )
942  );
943  $cacheEntry = $cache->get( $key );
944  if ( is_string( $cacheEntry ) ) {
945  return $cacheEntry;
946  }
947 
949  try {
950  $parser->parse( $contents, $fileName, 1 );
951  $result = $contents;
952  } catch ( Exception $e ) {
953  // We'll save this to cache to avoid having to validate broken JS over and over...
954  $err = $e->getMessage();
955  $result = "mw.log.error(" .
956  Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
957  }
958 
959  $cache->set( $key, $result );
960  return $result;
961  } else {
962  return $contents;
963  }
964  }
965 
969  protected static function javaScriptParser() {
970  if ( !self::$jsParser ) {
971  self::$jsParser = new JSParser();
972  }
973  return self::$jsParser;
974  }
975 
983  protected static function safeFilemtime( $filePath ) {
984  MediaWiki\suppressWarnings();
985  $mtime = filemtime( $filePath ) ?: 1;
986  MediaWiki\restoreWarnings();
987  return $mtime;
988  }
989 
998  protected static function safeFileHash( $filePath ) {
999  return FileContentsHasher::getFileContentsHash( $filePath );
1000  }
1001 }
ResourceLoaderModule\LOAD_GENERAL
const LOAD_GENERAL
Definition: ResourceLoaderModule.php:44
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
$context
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2612
ResourceLoaderModule\getFlip
getFlip( $context)
Definition: ResourceLoaderModule.php:134
ResourceLoaderModule\supportsURLLoading
supportsURLLoading()
Whether this module supports URL loading.
Definition: ResourceLoaderModule.php:260
ResourceLoaderModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's CSS in debug mode.
Definition: ResourceLoaderModule.php:286
ResourceLoaderModule\setMessageBlob
setMessageBlob( $blob, $lang)
Set in-object cache for message blobs.
Definition: ResourceLoaderModule.php:586
ResourceLoaderModule\setFileDependencies
setFileDependencies(ResourceLoaderContext $context, $files)
Set in-object cache for file dependencies.
Definition: ResourceLoaderModule.php:451
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:357
ResourceLoaderModule\getModifiedTime
getModifiedTime(ResourceLoaderContext $context)
Get this module's last modification timestamp for a given context.
Definition: ResourceLoaderModule.php:858
ResourceLoaderModule\TYPE_COMBINED
const TYPE_COMBINED
Definition: ResourceLoaderModule.php:38
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ResourceLoaderModule\ORIGIN_CORE_SITEWIDE
const ORIGIN_CORE_SITEWIDE
Definition: ResourceLoaderModule.php:47
captcha-old.count
count
Definition: captcha-old.py:225
ResourceLoaderModule\ORIGIN_USER_SITEWIDE
const ORIGIN_USER_SITEWIDE
Definition: ResourceLoaderModule.php:54
ResourceLoaderModule\isRaw
isRaw()
Whether this module's JS expects to work without the client-side ResourceLoader module.
Definition: ResourceLoaderModule.php:350
ResourceLoaderModule\$versionHash
$versionHash
Definition: ResourceLoaderModule.php:78
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:983
ResourceLoaderModule\getHashMtime
getHashMtime(ResourceLoaderContext $context)
Back-compat dummy for old subclass implementations of getModifiedTime().
Definition: ResourceLoaderModule.php:884
ResourceLoaderModule\setName
setName( $name)
Set this module's name.
Definition: ResourceLoaderModule.php:115
ResourceLoaderModule\setLogger
setLogger(LoggerInterface $logger)
Definition: ResourceLoaderModule.php:210
ResourceLoaderModule\saveFileDependencies
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:463
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1954
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
ResourceLoaderModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderModule.php:386
ResourceLoaderModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderModule.php:376
ResourceLoaderModule\$origin
$origin
Definition: ResourceLoaderModule.php:66
ResourceLoaderModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
Definition: ResourceLoaderModule.php:272
ResourceLoaderModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderModule.php:179
Xml\encodeJsVar
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.
Definition: Xml.php:627
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:1092
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:625
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:92
ResourceLoaderModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Definition: ResourceLoaderModule.php:597
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:143
ResourceLoaderModule\enableModuleContentVersion
enableModuleContentVersion()
Whether to generate version hash based on module content.
Definition: ResourceLoaderModule.php:797
Xml\encodeJsCall
static encodeJsCall( $name, $args, $pretty=false)
Create a call to a JavaScript function.
Definition: Xml.php:645
FormatJson\decode
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:187
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:127
ResourceLoaderModule\getGroup
getGroup()
Get the group this module is in.
Definition: ResourceLoaderModule.php:318
ResourceLoaderModule\$jsParser
static JSParser $jsParser
Lazy-initialized; use self::javaScriptParser()
Definition: ResourceLoaderModule.php:922
ResourceLoaderModule\getLogger
getLogger()
Definition: ResourceLoaderModule.php:218
ResourceLoaderModule\getDefinitionMtime
getDefinitionMtime(ResourceLoaderContext $context)
Back-compat dummy for old subclass implementations of getModifiedTime().
Definition: ResourceLoaderModule.php:900
ResourceLoaderModule\getScript
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Definition: ResourceLoaderModule.php:169
$blob
$blob
Definition: testCompression.php:63
$content
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition: hooks.txt:1049
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
ResourceLoaderModule\$contents
$contents
Definition: ResourceLoaderModule.php:80
$IP
$IP
Definition: update.php:3
ContextSource\getSkin
getSkin()
Get the Skin object.
Definition: ContextSource.php:153
ResourceLoaderModule\TYPE_SCRIPTS
const TYPE_SCRIPTS
Definition: ResourceLoaderModule.php:36
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
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:2536
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ResourceLoaderModule\expandRelativePaths
static expandRelativePaths(array $filePaths)
Expand directories relative to $IP.
Definition: ResourceLoaderModule.php:546
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:178
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ResourceLoaderModule\getOrigin
getOrigin()
Get this module's origin.
Definition: ResourceLoaderModule.php:126
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:560
ResourceLoaderModule\$parseCacheVersion
static $parseCacheVersion
Definition: ResourceLoaderModule.php:923
ResourceLoaderModule\isKnownEmpty
isKnownEmpty(ResourceLoaderContext $context)
Check whether this module is known to be empty.
Definition: ResourceLoaderModule.php:917
ResourceLoaderModule\getDeprecationInformation
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
Definition: ResourceLoaderModule.php:145
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2122
ResourceLoaderModule\safeFileHash
static safeFileHash( $filePath)
Compute a non-cryptographic string hash of a file's contents.
Definition: ResourceLoaderModule.php:998
ResourceLoaderModule\ORIGIN_USER_INDIVIDUAL
const ORIGIN_USER_INDIVIDUAL
Definition: ResourceLoaderModule.php:57
ResourceLoaderModule\$deprecated
array bool $deprecated
Definition: ResourceLoaderModule.php:90
ResourceLoaderModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Get a list of modules this module depends on.
Definition: ResourceLoaderModule.php:366
ResourceLoaderModule\getPosition
getPosition()
From where in the page HTML should this module be loaded?
Definition: ResourceLoaderModule.php:339
ResourceLoaderModule\$targets
$targets
Definition: ResourceLoaderModule.php:71
DerivativeResourceLoaderContext
Allows changing specific properties of a context object, without changing the main one.
Definition: DerivativeResourceLoaderContext.php:30
ResourceLoaderModule\$name
$name
Definition: ResourceLoaderModule.php:70
ResourceLoaderModule\LOAD_STYLES
const LOAD_STYLES
Definition: ResourceLoaderModule.php:42
ResourceLoaderModule\getMessages
getMessages()
Get the messages needed for this module.
Definition: ResourceLoaderModule.php:308
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
Definition: ResourceLoaderModule.php:933
ResourceLoaderModule\getModifiedHash
getModifiedHash(ResourceLoaderContext $context)
Helper method for providing a version hash to getVersionHash().
Definition: ResourceLoaderModule.php:869
ResourceLoaderModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderModule.php:844
ResourceLoaderModule\ORIGIN_CORE_INDIVIDUAL
const ORIGIN_CORE_INDIVIDUAL
Definition: ResourceLoaderModule.php:50
ResourceLoaderModule\getModuleContent
getModuleContent(ResourceLoaderContext $context)
Get an array of this module's resources.
Definition: ResourceLoaderModule.php:608
ResourceLoaderModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderModule.php:404
$resourceLoader
error also a ContextSource 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:2612
ResourceLoaderModule\ORIGIN_ALL
const ORIGIN_ALL
Definition: ResourceLoaderModule.php:60
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:34
ResourceLoaderModule\$config
Config $config
Definition: ResourceLoaderModule.php:85
ResourceLoaderModule\$logger
LoggerInterface $logger
Definition: ResourceLoaderModule.php:95
ResourceLoaderModule\$fileDeps
$fileDeps
Definition: ResourceLoaderModule.php:74
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
$cache
$cache
Definition: mcc.php:33
ResourceLoaderModule\setConfig
setConfig(Config $config)
Definition: ResourceLoaderModule.php:201
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
ResourceLoaderModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
Definition: ResourceLoaderModule.php:239
$path
$path
Definition: NoLocalSettings.php:26
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:532
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:416
ResourceLoaderModule\TYPE_STYLES
const TYPE_STYLES
Definition: ResourceLoaderModule.php:37
ResourceLoaderModule\getVersionHash
getVersionHash(ResourceLoaderContext $context)
Get a string identifying the current version of this module in a given context.
Definition: ResourceLoaderModule.php:743
ResourceLoaderModule\getSource
getSource()
Get the origin of this module.
Definition: ResourceLoaderModule.php:328
JSParser
Definition: jsminplus.php:674
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
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:969
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:76
ResourceLoaderModule\getName
getName()
Get this module's name.
Definition: ResourceLoaderModule.php:105
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:188
array
the array() calling protocol came about after MediaWiki 1.4rc1.
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56