MediaWiki  1.27.2
ResourceLoaderFileModule.php
Go to the documentation of this file.
1 <?php
29  /* Protected Members */
30 
32  protected $localBasePath = '';
33 
35  protected $remoteBasePath = '';
36 
38  protected $templates = [];
39 
47  protected $scripts = [];
48 
56  protected $languageScripts = [];
57 
65  protected $skinScripts = [];
66 
74  protected $debugScripts = [];
75 
83  protected $styles = [];
84 
92  protected $skinStyles = [];
93 
101  protected $dependencies = [];
102 
106  protected $skipFunction = null;
107 
115  protected $messages = [];
116 
118  protected $group;
119 
121  protected $position = 'bottom';
122 
124  protected $debugRaw = true;
125 
127  protected $raw = false;
128 
129  protected $targets = [ 'desktop' ];
130 
135  protected $hasGeneratedStyles = false;
136 
144  protected $localFileRefs = [];
145 
150  protected $missingLocalFileRefs = [];
151 
152  /* Methods */
153 
213  public function __construct(
214  $options = [],
215  $localBasePath = null,
216  $remoteBasePath = null
217  ) {
218  // Flag to decide whether to automagically add the mediawiki.template module
219  $hasTemplates = false;
220  // localBasePath and remoteBasePath both have unbelievably long fallback chains
221  // and need to be handled separately.
222  list( $this->localBasePath, $this->remoteBasePath ) =
223  self::extractBasePaths( $options, $localBasePath, $remoteBasePath );
224 
225  // Extract, validate and normalise remaining options
226  foreach ( $options as $member => $option ) {
227  switch ( $member ) {
228  // Lists of file paths
229  case 'scripts':
230  case 'debugScripts':
231  case 'styles':
232  $this->{$member} = (array)$option;
233  break;
234  case 'templates':
235  $hasTemplates = true;
236  $this->{$member} = (array)$option;
237  break;
238  // Collated lists of file paths
239  case 'languageScripts':
240  case 'skinScripts':
241  case 'skinStyles':
242  if ( !is_array( $option ) ) {
243  throw new InvalidArgumentException(
244  "Invalid collated file path list error. " .
245  "'$option' given, array expected."
246  );
247  }
248  foreach ( $option as $key => $value ) {
249  if ( !is_string( $key ) ) {
250  throw new InvalidArgumentException(
251  "Invalid collated file path list key error. " .
252  "'$key' given, string expected."
253  );
254  }
255  $this->{$member}[$key] = (array)$value;
256  }
257  break;
258  // Lists of strings
259  case 'dependencies':
260  case 'messages':
261  case 'targets':
262  // Normalise
263  $option = array_values( array_unique( (array)$option ) );
264  sort( $option );
265 
266  $this->{$member} = $option;
267  break;
268  // Single strings
269  case 'position':
270  case 'group':
271  case 'skipFunction':
272  $this->{$member} = (string)$option;
273  break;
274  // Single booleans
275  case 'debugRaw':
276  case 'raw':
277  $this->{$member} = (bool)$option;
278  break;
279  }
280  }
281  if ( $hasTemplates ) {
282  $this->dependencies[] = 'mediawiki.template';
283  // Ensure relevant template compiler module gets loaded
284  foreach ( $this->templates as $alias => $templatePath ) {
285  if ( is_int( $alias ) ) {
286  $alias = $templatePath;
287  }
288  $suffix = explode( '.', $alias );
289  $suffix = end( $suffix );
290  $compilerModule = 'mediawiki.template.' . $suffix;
291  if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies ) ) {
292  $this->dependencies[] = $compilerModule;
293  }
294  }
295  }
296  }
297 
309  public static function extractBasePaths(
310  $options = [],
311  $localBasePath = null,
312  $remoteBasePath = null
313  ) {
315 
316  // The different ways these checks are done, and their ordering, look very silly,
317  // but were preserved for backwards-compatibility just in case. Tread lightly.
318 
319  if ( $localBasePath === null ) {
321  }
322  if ( $remoteBasePath === null ) {
324  }
325 
326  if ( isset( $options['remoteExtPath'] ) ) {
328  $remoteBasePath = $wgExtensionAssetsPath . '/' . $options['remoteExtPath'];
329  }
330 
331  if ( isset( $options['remoteSkinPath'] ) ) {
333  $remoteBasePath = $wgStylePath . '/' . $options['remoteSkinPath'];
334  }
335 
336  if ( array_key_exists( 'localBasePath', $options ) ) {
337  $localBasePath = (string)$options['localBasePath'];
338  }
339 
340  if ( array_key_exists( 'remoteBasePath', $options ) ) {
341  $remoteBasePath = (string)$options['remoteBasePath'];
342  }
343 
344  return [ $localBasePath, $remoteBasePath ];
345  }
346 
354  $files = $this->getScriptFiles( $context );
355  return $this->readScriptFiles( $files );
356  }
357 
363  $urls = [];
364  foreach ( $this->getScriptFiles( $context ) as $file ) {
366  $this->getConfig(),
367  $this->getRemotePath( $file )
368  );
369  }
370  return $urls;
371  }
372 
376  public function supportsURLLoading() {
377  return $this->debugRaw;
378  }
379 
387  $styles = $this->readStyleFiles(
388  $this->getStyleFiles( $context ),
389  $this->getFlip( $context ),
390  $context
391  );
392  // Collect referenced files
393  $this->saveFileDependencies( $context, $this->localFileRefs );
394 
395  return $styles;
396  }
397 
403  if ( $this->hasGeneratedStyles ) {
404  // Do the default behaviour of returning a url back to load.php
405  // but with only=styles.
406  return parent::getStyleURLsForDebug( $context );
407  }
408  // Our module consists entirely of real css files,
409  // in debug mode we can load those directly.
410  $urls = [];
411  foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
412  $urls[$mediaType] = [];
413  foreach ( $list as $file ) {
415  $this->getConfig(),
416  $this->getRemotePath( $file )
417  );
418  }
419  }
420  return $urls;
421  }
422 
428  public function getMessages() {
429  return $this->messages;
430  }
431 
437  public function getGroup() {
438  return $this->group;
439  }
440 
444  public function getPosition() {
445  return $this->position;
446  }
447 
453  public function getDependencies( ResourceLoaderContext $context = null ) {
454  return $this->dependencies;
455  }
456 
462  public function getSkipFunction() {
463  if ( !$this->skipFunction ) {
464  return null;
465  }
466 
467  $localPath = $this->getLocalPath( $this->skipFunction );
468  if ( !file_exists( $localPath ) ) {
469  throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
470  }
471  $contents = $this->stripBom( file_get_contents( $localPath ) );
472  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
473  $contents = $this->validateScriptFile( $localPath, $contents );
474  }
475  return $contents;
476  }
477 
481  public function isRaw() {
482  return $this->raw;
483  }
484 
493  public function enableModuleContentVersion() {
494  return false;
495  }
496 
508  $files = [];
509 
510  // Flatten style files into $files
511  $styles = self::collateFilePathListByOption( $this->styles, 'media', 'all' );
512  foreach ( $styles as $styleFiles ) {
513  $files = array_merge( $files, $styleFiles );
514  }
515 
516  $skinFiles = self::collateFilePathListByOption(
517  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
518  'media',
519  'all'
520  );
521  foreach ( $skinFiles as $styleFiles ) {
522  $files = array_merge( $files, $styleFiles );
523  }
524 
525  // Final merge, this should result in a master list of dependent files
526  $files = array_merge(
527  $files,
528  $this->scripts,
529  $this->templates,
530  $context->getDebug() ? $this->debugScripts : [],
531  $this->getLanguageScripts( $context->getLanguage() ),
532  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
533  );
534  if ( $this->skipFunction ) {
536  }
537  $files = array_map( [ $this, 'getLocalPath' ], $files );
538  // File deps need to be treated separately because they're already prefixed
539  $files = array_merge( $files, $this->getFileDependencies( $context ) );
540  // Filter out any duplicates from getFileDependencies() and others.
541  // Most commonly introduced by compileLessFile(), which always includes the
542  // entry point Less file we already know about.
543  $files = array_values( array_unique( $files ) );
544 
545  // Don't include keys or file paths here, only the hashes. Including that would needlessly
546  // cause global cache invalidation when files move or if e.g. the MediaWiki path changes.
547  // Any significant ordering is already detected by the definition summary.
548  return array_map( [ __CLASS__, 'safeFileHash' ], $files );
549  }
550 
558  $summary = parent::getDefinitionSummary( $context );
559 
560  $options = [];
561  foreach ( [
562  // The following properties are omitted because they don't affect the module reponse:
563  // - localBasePath (Per T104950; Changes when absolute directory name changes. If
564  // this affects 'scripts' and other file paths, getFileHashes accounts for that.)
565  // - remoteBasePath (Per T104950)
566  // - dependencies (provided via startup module)
567  // - targets
568  // - group (provided via startup module)
569  // - position (only used by OutputPage)
570  'scripts',
571  'debugScripts',
572  'styles',
573  'languageScripts',
574  'skinScripts',
575  'skinStyles',
576  'messages',
577  'templates',
578  'skipFunction',
579  'debugRaw',
580  'raw',
581  ] as $member ) {
582  $options[$member] = $this->{$member};
583  };
584 
585  $summary[] = [
586  'options' => $options,
587  'fileHashes' => $this->getFileHashes( $context ),
588  'messageBlob' => $this->getMessageBlob( $context ),
589  ];
590  return $summary;
591  }
592 
597  protected function getLocalPath( $path ) {
598  if ( $path instanceof ResourceLoaderFilePath ) {
599  return $path->getLocalPath();
600  }
601 
602  return "{$this->localBasePath}/$path";
603  }
604 
609  protected function getRemotePath( $path ) {
610  if ( $path instanceof ResourceLoaderFilePath ) {
611  return $path->getRemotePath();
612  }
613 
614  return "{$this->remoteBasePath}/$path";
615  }
616 
624  public function getStyleSheetLang( $path ) {
625  return preg_match( '/\.less$/i', $path ) ? 'less' : 'css';
626  }
627 
637  protected static function collateFilePathListByOption( array $list, $option, $default ) {
638  $collatedFiles = [];
639  foreach ( (array)$list as $key => $value ) {
640  if ( is_int( $key ) ) {
641  // File name as the value
642  if ( !isset( $collatedFiles[$default] ) ) {
643  $collatedFiles[$default] = [];
644  }
645  $collatedFiles[$default][] = $value;
646  } elseif ( is_array( $value ) ) {
647  // File name as the key, options array as the value
648  $optionValue = isset( $value[$option] ) ? $value[$option] : $default;
649  if ( !isset( $collatedFiles[$optionValue] ) ) {
650  $collatedFiles[$optionValue] = [];
651  }
652  $collatedFiles[$optionValue][] = $key;
653  }
654  }
655  return $collatedFiles;
656  }
657 
667  protected static function tryForKey( array $list, $key, $fallback = null ) {
668  if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
669  return $list[$key];
670  } elseif ( is_string( $fallback )
671  && isset( $list[$fallback] )
672  && is_array( $list[$fallback] )
673  ) {
674  return $list[$fallback];
675  }
676  return [];
677  }
678 
686  $files = array_merge(
687  $this->scripts,
688  $this->getLanguageScripts( $context->getLanguage() ),
689  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
690  );
691  if ( $context->getDebug() ) {
692  $files = array_merge( $files, $this->debugScripts );
693  }
694 
695  return array_unique( $files, SORT_REGULAR );
696  }
697 
705  private function getLanguageScripts( $lang ) {
706  $scripts = self::tryForKey( $this->languageScripts, $lang );
707  if ( $scripts ) {
708  return $scripts;
709  }
710  $fallbacks = Language::getFallbacksFor( $lang );
711  foreach ( $fallbacks as $lang ) {
712  $scripts = self::tryForKey( $this->languageScripts, $lang );
713  if ( $scripts ) {
714  return $scripts;
715  }
716  }
717 
718  return [];
719  }
720 
728  return array_merge_recursive(
729  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
730  self::collateFilePathListByOption(
731  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
732  'media',
733  'all'
734  )
735  );
736  }
737 
745  protected function getSkinStyleFiles( $skinName ) {
746  return self::collateFilePathListByOption(
747  self::tryForKey( $this->skinStyles, $skinName ),
748  'media',
749  'all'
750  );
751  }
752 
759  protected function getAllSkinStyleFiles() {
760  $styleFiles = [];
761  $internalSkinNames = array_keys( Skin::getSkinNames() );
762  $internalSkinNames[] = 'default';
763 
764  foreach ( $internalSkinNames as $internalSkinName ) {
765  $styleFiles = array_merge_recursive(
766  $styleFiles,
767  $this->getSkinStyleFiles( $internalSkinName )
768  );
769  }
770 
771  return $styleFiles;
772  }
773 
779  public function getAllStyleFiles() {
780  $collatedStyleFiles = array_merge_recursive(
781  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
782  $this->getAllSkinStyleFiles()
783  );
784 
785  $result = [];
786 
787  foreach ( $collatedStyleFiles as $media => $styleFiles ) {
788  foreach ( $styleFiles as $styleFile ) {
789  $result[] = $this->getLocalPath( $styleFile );
790  }
791  }
792 
793  return $result;
794  }
795 
803  protected function readScriptFiles( array $scripts ) {
804  if ( empty( $scripts ) ) {
805  return '';
806  }
807  $js = '';
808  foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
809  $localPath = $this->getLocalPath( $fileName );
810  if ( !file_exists( $localPath ) ) {
811  throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
812  }
813  $contents = $this->stripBom( file_get_contents( $localPath ) );
814  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
815  // Static files don't really need to be checked as often; unlike
816  // on-wiki module they shouldn't change unexpectedly without
817  // admin interference.
818  $contents = $this->validateScriptFile( $fileName, $contents );
819  }
820  $js .= $contents . "\n";
821  }
822  return $js;
823  }
824 
840  public function readStyleFiles( array $styles, $flip, $context = null ) {
841  if ( $context === null ) {
842  wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' );
844  }
845 
846  if ( empty( $styles ) ) {
847  return [];
848  }
849  foreach ( $styles as $media => $files ) {
850  $uniqueFiles = array_unique( $files, SORT_REGULAR );
851  $styleFiles = [];
852  foreach ( $uniqueFiles as $file ) {
853  $styleFiles[] = $this->readStyleFile( $file, $flip, $context );
854  }
855  $styles[$media] = implode( "\n", $styleFiles );
856  }
857  return $styles;
858  }
859 
872  protected function readStyleFile( $path, $flip, $context ) {
873  $localPath = $this->getLocalPath( $path );
874  $remotePath = $this->getRemotePath( $path );
875  if ( !file_exists( $localPath ) ) {
876  $msg = __METHOD__ . ": style file not found: \"$localPath\"";
877  wfDebugLog( 'resourceloader', $msg );
878  throw new MWException( $msg );
879  }
880 
881  if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
882  $style = $this->compileLessFile( $localPath, $context );
883  $this->hasGeneratedStyles = true;
884  } else {
885  $style = $this->stripBom( file_get_contents( $localPath ) );
886  }
887 
888  if ( $flip ) {
889  $style = CSSJanus::transform( $style, true, false );
890  }
891  $localDir = dirname( $localPath );
892  $remoteDir = dirname( $remotePath );
893  // Get and register local file references
894  $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
895  foreach ( $localFileRefs as $file ) {
896  if ( file_exists( $file ) ) {
897  $this->localFileRefs[] = $file;
898  } else {
899  $this->missingLocalFileRefs[] = $file;
900  }
901  }
902  // Don't cache this call. remap() ensures data URIs embeds are up to date,
903  // and urls contain correct content hashes in their query string. (T128668)
904  return CSSMin::remap( $style, $localDir, $remoteDir, true );
905  }
906 
912  public function getFlip( $context ) {
913  return $context->getDirection() === 'rtl';
914  }
915 
921  public function getTargets() {
922  return $this->targets;
923  }
924 
937  protected function compileLessFile( $fileName, ResourceLoaderContext $context ) {
938  static $cache;
939 
940  if ( !$cache ) {
942  }
943 
944  // Construct a cache key from the LESS file name and a hash digest
945  // of the LESS variables used for compilation.
946  $vars = $this->getLessVars( $context );
947  ksort( $vars );
948  $varsHash = hash( 'md4', serialize( $vars ) );
949  $cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash );
950  $cachedCompile = $cache->get( $cacheKey );
951 
952  // If we got a cached value, we have to validate it by getting a
953  // checksum of all the files that were loaded by the parser and
954  // ensuring it matches the cached entry's.
955  if ( isset( $cachedCompile['hash'] ) ) {
956  $contentHash = FileContentsHasher::getFileContentsHash( $cachedCompile['files'] );
957  if ( $contentHash === $cachedCompile['hash'] ) {
958  $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile['files'] );
959  return $cachedCompile['css'];
960  }
961  }
962 
963  $compiler = $context->getResourceLoader()->getLessCompiler( $vars );
964  $css = $compiler->parseFile( $fileName )->getCss();
965  $files = $compiler->AllParsedFiles();
966  $this->localFileRefs = array_merge( $this->localFileRefs, $files );
967 
968  $cache->set( $cacheKey, [
969  'css' => $css,
970  'files' => $files,
972  ], 60 * 60 * 24 ); // 86400 seconds, or 24 hours.
973 
974  return $css;
975  }
976 
982  public function getTemplates() {
983  $templates = [];
984 
985  foreach ( $this->templates as $alias => $templatePath ) {
986  // Alias is optional
987  if ( is_int( $alias ) ) {
988  $alias = $templatePath;
989  }
990  $localPath = $this->getLocalPath( $templatePath );
991  if ( file_exists( $localPath ) ) {
992  $content = file_get_contents( $localPath );
993  $templates[$alias] = $this->stripBom( $content );
994  } else {
995  $msg = __METHOD__ . ": template file not found: \"$localPath\"";
996  wfDebugLog( 'resourceloader', $msg );
997  throw new MWException( $msg );
998  }
999  }
1000  return $templates;
1001  }
1002 
1012  protected function stripBom( $input ) {
1013  if ( substr_compare( "\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
1014  return substr( $input, 3 );
1015  }
1016  return $input;
1017  }
1018 }
getScriptURLsForDebug(ResourceLoaderContext $context)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
the array() calling protocol came about after MediaWiki 1.4rc1.
string $position
Position on the page to load this module at.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Definition: hooks.txt:2321
$context
Definition: load.php:44
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
array $dependencies
List of modules this module depends on.
$IP
Definition: WebStart.php:58
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
array $skinStyles
List of paths to CSS files to include when using specific skins.
getSkinStyleFiles($skinName)
Gets a list of file paths for all skin styles in the module used by the skin.
getStyleFiles(ResourceLoaderContext $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
if(!isset($args[0])) $lang
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
readStyleFile($path, $flip, $context)
Reads a style file.
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:49
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Definition: hooks.txt:177
$value
getAllStyleFiles()
Returns all style files and all skin style files used by this module.
$files
getSkipFunction()
Get the skip function.
compileLessFile($fileName, ResourceLoaderContext $context)
Compile a LESS file into CSS.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
array $debugScripts
List of paths to JavaScript files to include in debug mode.
The package scripts
Definition: README.txt:1
static getFallbacksFor($code)
Get the ordered list of fallback languages.
Definition: Language.php:4324
getStyles(ResourceLoaderContext $context)
Get all styles for a given context.
getFlip($context)
Get whether CSS for this module should be flipped.
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:Associative array mapping language codes to prefixed links of the form"language:title".&$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':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:1796
array $templates
Saves a list of the templates named by the modules.
static getFileContentsHash($filePaths, $algo= 'md4')
Get a hash of the combined contents of one or more files, either by retrieving a previously-computed ...
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
bool $raw
Whether mw.loader.state() call should be omitted.
stripBom($input)
Takes an input string and removes the UTF-8 BOM character if present.
getFileHashes(ResourceLoaderContext $context)
Helper method to gather file hashes for getDefinitionSummary.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
bool $debugRaw
Link to raw files in debug mode.
static array static getLocalFileReferences($source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
Definition: CSSMin.php:69
$wgStylePath
The URL path of the skins directory.
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
validateScriptFile($fileName, $contents)
Validate a given script file; if valid returns the original source.
enableModuleContentVersion()
Disable module content versioning.
$css
static extractBasePaths($options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information. ...
string $skipFunction
File name containing the body of the skip function.
bool $hasGeneratedStyles
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
static transformResourcePath(Config $config, $path)
Transform path to web-accessible static resource.
getDependencies(ResourceLoaderContext $context=null)
Gets list of names of modules this module depends on.
ResourceLoader module based on local JavaScript/CSS files.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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 as context as context $options
Definition: hooks.txt:1004
readScriptFiles(array $scripts)
Gets the contents of a list of JavaScript files.
$summary
string $group
Name of group to load this module in.
readStyleFiles(array $styles, $flip, $context=null)
Gets the contents of a list of CSS files.
array $localFileRefs
Place where readStyleFile() tracks file dependencies.
string $localBasePath
Local base path, see __construct()
$cache
Definition: mcc.php:33
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
getTemplates()
Takes named templates by the module and returns an array mapping.
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
getGroup()
Gets the name of the group this module should be loaded in.
static remap($source, $local, $remote, $embedData=true)
Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an ...
Definition: CSSMin.php:229
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path...
getMessages()
Gets list of message keys used by this module.
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
getStyleURLsForDebug(ResourceLoaderContext $context)
string $remoteBasePath
Remote base path, see __construct()
$fallback
Definition: MessagesAb.php:11
array $messages
List of message keys used by this module.
getAllSkinStyleFiles()
Gets a list of file paths for all skin style files in the module, for all available skins...
array $scripts
List of paths to JavaScript files to always include.
static getLocalServerInstance($fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist 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:1004
$wgExtensionAssetsPath
The URL path of the extensions directory.
array $languageScripts
List of JavaScript files to include when using a specific language.
getStyleSheetLang($path)
Infer the stylesheet language from a stylesheet file path.
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
const CACHE_ANYTHING
Definition: Defines.php:101
getScript(ResourceLoaderContext $context)
Gets all scripts for a given context concatenated together.
__construct($options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.
array $missingLocalFileRefs
Place where readStyleFile() tracks file dependencies for non-existent files.
getLanguageScripts($lang)
Get the set of language scripts for the given language, possibly using a fallback language...
serialize()
Definition: ApiMessage.php:94
array $styles
List of paths to CSS files to always include.
static collateFilePathListByOption(array $list, $option, $default)
Collates file paths by option (where provided).
array $skinScripts
List of JavaScript files to include when using a specific skin.
getScriptFiles(ResourceLoaderContext $context)
Get a list of file paths for all scripts in this module, in order of proper execution.
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:1996
Object passed around to modules which contains information about the state of a specific loader reque...
static tryForKey(array $list, $key, $fallback=null)
Get a list of element that match a key, optionally using a fallback key.