MediaWiki  1.31.0
ResourceLoaderFileModule.php
Go to the documentation of this file.
1 <?php
29 
31  protected $localBasePath = '';
32 
34  protected $remoteBasePath = '';
35 
37  protected $templates = [];
38 
46  protected $scripts = [];
47 
55  protected $languageScripts = [];
56 
64  protected $skinScripts = [];
65 
73  protected $debugScripts = [];
74 
82  protected $styles = [];
83 
91  protected $skinStyles = [];
92 
100  protected $dependencies = [];
101 
105  protected $skipFunction = null;
106 
114  protected $messages = [];
115 
117  protected $group;
118 
120  protected $debugRaw = true;
121 
123  protected $raw = false;
124 
125  protected $targets = [ 'desktop' ];
126 
128  protected $noflip = false;
129 
134  protected $hasGeneratedStyles = false;
135 
143  protected $localFileRefs = [];
144 
149  protected $missingLocalFileRefs = [];
150 
208  public function __construct(
209  $options = [],
210  $localBasePath = null,
211  $remoteBasePath = null
212  ) {
213  // Flag to decide whether to automagically add the mediawiki.template module
214  $hasTemplates = false;
215  // localBasePath and remoteBasePath both have unbelievably long fallback chains
216  // and need to be handled separately.
217  list( $this->localBasePath, $this->remoteBasePath ) =
219 
220  // Extract, validate and normalise remaining options
221  foreach ( $options as $member => $option ) {
222  switch ( $member ) {
223  // Lists of file paths
224  case 'scripts':
225  case 'debugScripts':
226  case 'styles':
227  $this->{$member} = (array)$option;
228  break;
229  case 'templates':
230  $hasTemplates = true;
231  $this->{$member} = (array)$option;
232  break;
233  // Collated lists of file paths
234  case 'languageScripts':
235  case 'skinScripts':
236  case 'skinStyles':
237  if ( !is_array( $option ) ) {
238  throw new InvalidArgumentException(
239  "Invalid collated file path list error. " .
240  "'$option' given, array expected."
241  );
242  }
243  foreach ( $option as $key => $value ) {
244  if ( !is_string( $key ) ) {
245  throw new InvalidArgumentException(
246  "Invalid collated file path list key error. " .
247  "'$key' given, string expected."
248  );
249  }
250  $this->{$member}[$key] = (array)$value;
251  }
252  break;
253  case 'deprecated':
254  $this->deprecated = $option;
255  break;
256  // Lists of strings
257  case 'dependencies':
258  case 'messages':
259  case 'targets':
260  // Normalise
261  $option = array_values( array_unique( (array)$option ) );
262  sort( $option );
263 
264  $this->{$member} = $option;
265  break;
266  // Single strings
267  case 'group':
268  case 'skipFunction':
269  $this->{$member} = (string)$option;
270  break;
271  // Single booleans
272  case 'debugRaw':
273  case 'raw':
274  case 'noflip':
275  $this->{$member} = (bool)$option;
276  break;
277  }
278  }
279  if ( $hasTemplates ) {
280  $this->dependencies[] = 'mediawiki.template';
281  // Ensure relevant template compiler module gets loaded
282  foreach ( $this->templates as $alias => $templatePath ) {
283  if ( is_int( $alias ) ) {
284  $alias = $templatePath;
285  }
286  $suffix = explode( '.', $alias );
287  $suffix = end( $suffix );
288  $compilerModule = 'mediawiki.template.' . $suffix;
289  if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies ) ) {
290  $this->dependencies[] = $compilerModule;
291  }
292  }
293  }
294  }
295 
307  public static function extractBasePaths(
308  $options = [],
309  $localBasePath = null,
310  $remoteBasePath = null
311  ) {
313 
314  // The different ways these checks are done, and their ordering, look very silly,
315  // but were preserved for backwards-compatibility just in case. Tread lightly.
316 
317  if ( $localBasePath === null ) {
319  }
320  if ( $remoteBasePath === null ) {
322  }
323 
324  if ( isset( $options['remoteExtPath'] ) ) {
326  $remoteBasePath = $wgExtensionAssetsPath . '/' . $options['remoteExtPath'];
327  }
328 
329  if ( isset( $options['remoteSkinPath'] ) ) {
331  $remoteBasePath = $wgStylePath . '/' . $options['remoteSkinPath'];
332  }
333 
334  if ( array_key_exists( 'localBasePath', $options ) ) {
335  $localBasePath = (string)$options['localBasePath'];
336  }
337 
338  if ( array_key_exists( 'remoteBasePath', $options ) ) {
339  $remoteBasePath = (string)$options['remoteBasePath'];
340  }
341 
342  return [ $localBasePath, $remoteBasePath ];
343  }
344 
352  $files = $this->getScriptFiles( $context );
353  return $this->getDeprecationInformation() . $this->readScriptFiles( $files );
354  }
355 
361  $urls = [];
362  foreach ( $this->getScriptFiles( $context ) as $file ) {
364  $this->getConfig(),
365  $this->getRemotePath( $file )
366  );
367  }
368  return $urls;
369  }
370 
374  public function supportsURLLoading() {
375  return $this->debugRaw;
376  }
377 
385  $styles = $this->readStyleFiles(
386  $this->getStyleFiles( $context ),
387  $this->getFlip( $context ),
388  $context
389  );
390  // Collect referenced files
391  $this->saveFileDependencies( $context, $this->localFileRefs );
392 
393  return $styles;
394  }
395 
401  if ( $this->hasGeneratedStyles ) {
402  // Do the default behaviour of returning a url back to load.php
403  // but with only=styles.
404  return parent::getStyleURLsForDebug( $context );
405  }
406  // Our module consists entirely of real css files,
407  // in debug mode we can load those directly.
408  $urls = [];
409  foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
410  $urls[$mediaType] = [];
411  foreach ( $list as $file ) {
412  $urls[$mediaType][] = OutputPage::transformResourcePath(
413  $this->getConfig(),
414  $this->getRemotePath( $file )
415  );
416  }
417  }
418  return $urls;
419  }
420 
426  public function getMessages() {
427  return $this->messages;
428  }
429 
435  public function getGroup() {
436  return $this->group;
437  }
438 
444  public function getDependencies( ResourceLoaderContext $context = null ) {
445  return $this->dependencies;
446  }
447 
453  public function getSkipFunction() {
454  if ( !$this->skipFunction ) {
455  return null;
456  }
457 
458  $localPath = $this->getLocalPath( $this->skipFunction );
459  if ( !file_exists( $localPath ) ) {
460  throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
461  }
462  $contents = $this->stripBom( file_get_contents( $localPath ) );
463  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
464  $contents = $this->validateScriptFile( $localPath, $contents );
465  }
466  return $contents;
467  }
468 
472  public function isRaw() {
473  return $this->raw;
474  }
475 
484  public function enableModuleContentVersion() {
485  return false;
486  }
487 
499  $files = [];
500 
501  // Flatten style files into $files
502  $styles = self::collateFilePathListByOption( $this->styles, 'media', 'all' );
503  foreach ( $styles as $styleFiles ) {
504  $files = array_merge( $files, $styleFiles );
505  }
506 
508  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
509  'media',
510  'all'
511  );
512  foreach ( $skinFiles as $styleFiles ) {
513  $files = array_merge( $files, $styleFiles );
514  }
515 
516  // Final merge, this should result in a master list of dependent files
517  $files = array_merge(
518  $files,
519  $this->scripts,
520  $this->templates,
521  $context->getDebug() ? $this->debugScripts : [],
522  $this->getLanguageScripts( $context->getLanguage() ),
523  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
524  );
525  if ( $this->skipFunction ) {
526  $files[] = $this->skipFunction;
527  }
528  $files = array_map( [ $this, 'getLocalPath' ], $files );
529  // File deps need to be treated separately because they're already prefixed
530  $files = array_merge( $files, $this->getFileDependencies( $context ) );
531  // Filter out any duplicates from getFileDependencies() and others.
532  // Most commonly introduced by compileLessFile(), which always includes the
533  // entry point Less file we already know about.
534  $files = array_values( array_unique( $files ) );
535 
536  // Don't include keys or file paths here, only the hashes. Including that would needlessly
537  // cause global cache invalidation when files move or if e.g. the MediaWiki path changes.
538  // Any significant ordering is already detected by the definition summary.
539  return array_map( [ __CLASS__, 'safeFileHash' ], $files );
540  }
541 
549  $summary = parent::getDefinitionSummary( $context );
550 
551  $options = [];
552  foreach ( [
553  // The following properties are omitted because they don't affect the module reponse:
554  // - localBasePath (Per T104950; Changes when absolute directory name changes. If
555  // this affects 'scripts' and other file paths, getFileHashes accounts for that.)
556  // - remoteBasePath (Per T104950)
557  // - dependencies (provided via startup module)
558  // - targets
559  // - group (provided via startup module)
560  'scripts',
561  'debugScripts',
562  'styles',
563  'languageScripts',
564  'skinScripts',
565  'skinStyles',
566  'messages',
567  'templates',
568  'skipFunction',
569  'debugRaw',
570  'raw',
571  ] as $member ) {
572  $options[$member] = $this->{$member};
573  };
574 
575  $summary[] = [
576  'options' => $options,
577  'fileHashes' => $this->getFileHashes( $context ),
578  'messageBlob' => $this->getMessageBlob( $context ),
579  ];
580 
581  $lessVars = $this->getLessVars( $context );
582  if ( $lessVars ) {
583  $summary[] = [ 'lessVars' => $lessVars ];
584  }
585 
586  return $summary;
587  }
588 
593  protected function getLocalPath( $path ) {
594  if ( $path instanceof ResourceLoaderFilePath ) {
595  return $path->getLocalPath();
596  }
597 
598  return "{$this->localBasePath}/$path";
599  }
600 
605  protected function getRemotePath( $path ) {
606  if ( $path instanceof ResourceLoaderFilePath ) {
607  return $path->getRemotePath();
608  }
609 
610  return "{$this->remoteBasePath}/$path";
611  }
612 
620  public function getStyleSheetLang( $path ) {
621  return preg_match( '/\.less$/i', $path ) ? 'less' : 'css';
622  }
623 
633  protected static function collateFilePathListByOption( array $list, $option, $default ) {
634  $collatedFiles = [];
635  foreach ( (array)$list as $key => $value ) {
636  if ( is_int( $key ) ) {
637  // File name as the value
638  if ( !isset( $collatedFiles[$default] ) ) {
639  $collatedFiles[$default] = [];
640  }
641  $collatedFiles[$default][] = $value;
642  } elseif ( is_array( $value ) ) {
643  // File name as the key, options array as the value
644  $optionValue = isset( $value[$option] ) ? $value[$option] : $default;
645  if ( !isset( $collatedFiles[$optionValue] ) ) {
646  $collatedFiles[$optionValue] = [];
647  }
648  $collatedFiles[$optionValue][] = $key;
649  }
650  }
651  return $collatedFiles;
652  }
653 
663  protected static function tryForKey( array $list, $key, $fallback = null ) {
664  if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
665  return $list[$key];
666  } elseif ( is_string( $fallback )
667  && isset( $list[$fallback] )
668  && is_array( $list[$fallback] )
669  ) {
670  return $list[$fallback];
671  }
672  return [];
673  }
674 
682  $files = array_merge(
683  $this->scripts,
684  $this->getLanguageScripts( $context->getLanguage() ),
685  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
686  );
687  if ( $context->getDebug() ) {
688  $files = array_merge( $files, $this->debugScripts );
689  }
690 
691  return array_unique( $files, SORT_REGULAR );
692  }
693 
701  private function getLanguageScripts( $lang ) {
702  $scripts = self::tryForKey( $this->languageScripts, $lang );
703  if ( $scripts ) {
704  return $scripts;
705  }
706  $fallbacks = Language::getFallbacksFor( $lang );
707  foreach ( $fallbacks as $lang ) {
708  $scripts = self::tryForKey( $this->languageScripts, $lang );
709  if ( $scripts ) {
710  return $scripts;
711  }
712  }
713 
714  return [];
715  }
716 
724  return array_merge_recursive(
725  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
726  self::collateFilePathListByOption(
727  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
728  'media',
729  'all'
730  )
731  );
732  }
733 
741  protected function getSkinStyleFiles( $skinName ) {
743  self::tryForKey( $this->skinStyles, $skinName ),
744  'media',
745  'all'
746  );
747  }
748 
755  protected function getAllSkinStyleFiles() {
756  $styleFiles = [];
757  $internalSkinNames = array_keys( Skin::getSkinNames() );
758  $internalSkinNames[] = 'default';
759 
760  foreach ( $internalSkinNames as $internalSkinName ) {
761  $styleFiles = array_merge_recursive(
762  $styleFiles,
763  $this->getSkinStyleFiles( $internalSkinName )
764  );
765  }
766 
767  return $styleFiles;
768  }
769 
775  public function getAllStyleFiles() {
776  $collatedStyleFiles = array_merge_recursive(
777  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
778  $this->getAllSkinStyleFiles()
779  );
780 
781  $result = [];
782 
783  foreach ( $collatedStyleFiles as $media => $styleFiles ) {
784  foreach ( $styleFiles as $styleFile ) {
785  $result[] = $this->getLocalPath( $styleFile );
786  }
787  }
788 
789  return $result;
790  }
791 
799  protected function readScriptFiles( array $scripts ) {
800  if ( empty( $scripts ) ) {
801  return '';
802  }
803  $js = '';
804  foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
805  $localPath = $this->getLocalPath( $fileName );
806  if ( !file_exists( $localPath ) ) {
807  throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
808  }
809  $contents = $this->stripBom( file_get_contents( $localPath ) );
810  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
811  // Static files don't really need to be checked as often; unlike
812  // on-wiki module they shouldn't change unexpectedly without
813  // admin interference.
814  $contents = $this->validateScriptFile( $fileName, $contents );
815  }
816  $js .= $contents . "\n";
817  }
818  return $js;
819  }
820 
836  public function readStyleFiles( array $styles, $flip, $context = null ) {
837  if ( $context === null ) {
838  wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' );
840  }
841 
842  if ( empty( $styles ) ) {
843  return [];
844  }
845  foreach ( $styles as $media => $files ) {
846  $uniqueFiles = array_unique( $files, SORT_REGULAR );
847  $styleFiles = [];
848  foreach ( $uniqueFiles as $file ) {
849  $styleFiles[] = $this->readStyleFile( $file, $flip, $context );
850  }
851  $styles[$media] = implode( "\n", $styleFiles );
852  }
853  return $styles;
854  }
855 
868  protected function readStyleFile( $path, $flip, $context ) {
869  $localPath = $this->getLocalPath( $path );
870  $remotePath = $this->getRemotePath( $path );
871  if ( !file_exists( $localPath ) ) {
872  $msg = __METHOD__ . ": style file not found: \"$localPath\"";
873  wfDebugLog( 'resourceloader', $msg );
874  throw new MWException( $msg );
875  }
876 
877  if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
878  $style = $this->compileLessFile( $localPath, $context );
879  $this->hasGeneratedStyles = true;
880  } else {
881  $style = $this->stripBom( file_get_contents( $localPath ) );
882  }
883 
884  if ( $flip ) {
885  $style = CSSJanus::transform( $style, true, false );
886  }
887  $localDir = dirname( $localPath );
888  $remoteDir = dirname( $remotePath );
889  // Get and register local file references
890  $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
891  foreach ( $localFileRefs as $file ) {
892  if ( file_exists( $file ) ) {
893  $this->localFileRefs[] = $file;
894  } else {
895  $this->missingLocalFileRefs[] = $file;
896  }
897  }
898  // Don't cache this call. remap() ensures data URIs embeds are up to date,
899  // and urls contain correct content hashes in their query string. (T128668)
900  return CSSMin::remap( $style, $localDir, $remoteDir, true );
901  }
902 
908  public function getFlip( $context ) {
909  return $context->getDirection() === 'rtl' && !$this->noflip;
910  }
911 
917  public function getTargets() {
918  return $this->targets;
919  }
920 
927  public function getType() {
928  $canBeStylesOnly = !(
929  // All options except 'styles', 'skinStyles' and 'debugRaw'
930  $this->scripts
931  || $this->debugScripts
932  || $this->templates
933  || $this->languageScripts
934  || $this->skinScripts
935  || $this->dependencies
936  || $this->messages
937  || $this->skipFunction
938  || $this->raw
939  );
940  return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
941  }
942 
955  protected function compileLessFile( $fileName, ResourceLoaderContext $context ) {
956  static $cache;
957 
958  if ( !$cache ) {
960  }
961 
962  // Construct a cache key from the LESS file name and a hash digest
963  // of the LESS variables used for compilation.
964  $vars = $this->getLessVars( $context );
965  ksort( $vars );
966  $varsHash = hash( 'md4', serialize( $vars ) );
967  $cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash );
968  $cachedCompile = $cache->get( $cacheKey );
969 
970  // If we got a cached value, we have to validate it by getting a
971  // checksum of all the files that were loaded by the parser and
972  // ensuring it matches the cached entry's.
973  if ( isset( $cachedCompile['hash'] ) ) {
974  $contentHash = FileContentsHasher::getFileContentsHash( $cachedCompile['files'] );
975  if ( $contentHash === $cachedCompile['hash'] ) {
976  $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile['files'] );
977  return $cachedCompile['css'];
978  }
979  }
980 
981  $compiler = $context->getResourceLoader()->getLessCompiler( $vars );
982  $css = $compiler->parseFile( $fileName )->getCss();
983  $files = $compiler->AllParsedFiles();
984  $this->localFileRefs = array_merge( $this->localFileRefs, $files );
985 
986  // Cache for 24 hours (86400 seconds).
987  $cache->set( $cacheKey, [
988  'css' => $css,
989  'files' => $files,
990  'hash' => FileContentsHasher::getFileContentsHash( $files ),
991  ], 3600 * 24 );
992 
993  return $css;
994  }
995 
1001  public function getTemplates() {
1002  $templates = [];
1003 
1004  foreach ( $this->templates as $alias => $templatePath ) {
1005  // Alias is optional
1006  if ( is_int( $alias ) ) {
1007  $alias = $templatePath;
1008  }
1009  $localPath = $this->getLocalPath( $templatePath );
1010  if ( file_exists( $localPath ) ) {
1011  $content = file_get_contents( $localPath );
1012  $templates[$alias] = $this->stripBom( $content );
1013  } else {
1014  $msg = __METHOD__ . ": template file not found: \"$localPath\"";
1015  wfDebugLog( 'resourceloader', $msg );
1016  throw new MWException( $msg );
1017  }
1018  }
1019  return $templates;
1020  }
1021 
1032  protected function stripBom( $input ) {
1033  if ( substr_compare( "\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
1034  return substr( $input, 3 );
1035  }
1036  return $input;
1037  }
1038 }
Language\getFallbacksFor
static getFallbacksFor( $code)
Get the ordered list of fallback languages.
Definition: Language.php:4535
ResourceLoaderModule\LOAD_GENERAL
const LOAD_GENERAL
Definition: ResourceLoaderModule.php:45
ResourceLoaderFileModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderFileModule.php:453
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
ResourceLoaderFileModule\$styles
array $styles
List of paths to CSS files to always include.
Definition: ResourceLoaderFileModule.php:82
ResourceLoaderFileModule\$skinScripts
array $skinScripts
List of JavaScript files to include when using a specific skin.
Definition: ResourceLoaderFileModule.php:64
ResourceLoaderFileModule\$debugScripts
array $debugScripts
List of paths to JavaScript files to include in debug mode.
Definition: ResourceLoaderFileModule.php:73
ResourceLoaderContext\newDummyContext
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
Definition: ResourceLoaderContext.php:138
$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:2604
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
ResourceLoaderFileModule\$templates
array $templates
Saves a list of the templates named by the modules.
Definition: ResourceLoaderFileModule.php:37
ResourceLoaderFileModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all styles for a given context.
Definition: ResourceLoaderFileModule.php:384
$fallback
$fallback
Definition: MessagesAb.php:11
ResourceLoaderFileModule\getFileHashes
getFileHashes(ResourceLoaderContext $context)
Helper method to gather file hashes for getDefinitionSummary.
Definition: ResourceLoaderFileModule.php:498
ResourceLoaderModule\saveFileDependencies
saveFileDependencies(ResourceLoaderContext $context, $localFileRefs)
Set the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:450
$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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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:1985
ResourceLoaderFileModule\$noflip
bool $noflip
Whether CSSJanus flipping should be skipped for this module.
Definition: ResourceLoaderFileModule.php:128
ResourceLoaderFileModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Definition: ResourceLoaderFileModule.php:360
ResourceLoaderFileModule\getFlip
getFlip( $context)
Get whether CSS for this module should be flipped.
Definition: ResourceLoaderFileModule.php:908
ResourceLoaderFilePath
An object to represent a path to a JavaScript/CSS file, along with a remote and local base path,...
Definition: ResourceLoaderFilePath.php:28
ResourceLoaderFileModule\enableModuleContentVersion
enableModuleContentVersion()
Disable module content versioning.
Definition: ResourceLoaderFileModule.php:484
ResourceLoaderFileModule\$debugRaw
bool $debugRaw
Link to raw files in debug mode.
Definition: ResourceLoaderFileModule.php:120
$wgExtensionAssetsPath
$wgExtensionAssetsPath
The URL path of the extensions directory.
Definition: DefaultSettings.php:215
ResourceLoaderFileModule\$hasGeneratedStyles
bool $hasGeneratedStyles
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
Definition: ResourceLoaderFileModule.php:134
serialize
serialize()
Definition: ApiMessage.php:184
ResourceLoaderFileModule\$dependencies
array $dependencies
List of modules this module depends on.
Definition: ResourceLoaderFileModule.php:100
ResourceLoaderFileModule\$skinStyles
array $skinStyles
List of paths to CSS files to include when using specific skins.
Definition: ResourceLoaderFileModule.php:91
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:1075
$wgStylePath
$wgStylePath
The URL path of the skins directory.
Definition: DefaultSettings.php:200
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
ResourceLoaderFileModule\getDefinitionSummary
getDefinitionSummary(ResourceLoaderContext $context)
Get the definition summary for this module.
Definition: ResourceLoaderFileModule.php:548
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
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:55
ResourceLoaderModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Definition: ResourceLoaderModule.php:658
ResourceLoaderFileModule\readStyleFiles
readStyleFiles(array $styles, $flip, $context=null)
Gets the contents of a list of CSS files.
Definition: ResourceLoaderFileModule.php:836
ResourceLoaderFileModule
ResourceLoader module based on local JavaScript/CSS files.
Definition: ResourceLoaderFileModule.php:28
MWException
MediaWiki exception.
Definition: MWException.php:26
ResourceLoaderFileModule\getGroup
getGroup()
Gets the name of the group this module should be loaded in.
Definition: ResourceLoaderFileModule.php:435
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1111
$css
$css
Definition: styleTest.css.php:50
ResourceLoaderFileModule\getSkinStyleFiles
getSkinStyleFiles( $skinName)
Gets a list of file paths for all skin styles in the module used by the skin.
Definition: ResourceLoaderFileModule.php:741
ResourceLoaderFileModule\compileLessFile
compileLessFile( $fileName, ResourceLoaderContext $context)
Compile a LESS file into CSS.
Definition: ResourceLoaderFileModule.php:955
ResourceLoaderFileModule\getAllStyleFiles
getAllStyleFiles()
Returns all style files and all skin style files used by this module.
Definition: ResourceLoaderFileModule.php:775
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
ResourceLoaderModule\$contents
$contents
Definition: ResourceLoaderModule.php:79
$IP
$IP
Definition: update.php:3
ResourceLoaderFileModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Definition: ResourceLoaderFileModule.php:400
ResourceLoaderFileModule\getRemotePath
getRemotePath( $path)
Definition: ResourceLoaderFileModule.php:605
ResourceLoaderFileModule\extractBasePaths
static extractBasePaths( $options=[], $localBasePath=null, $remoteBasePath=null)
Extract a pair of local and remote base paths from module definition information.
Definition: ResourceLoaderFileModule.php:307
ResourceLoaderFileModule\$targets
$targets
Definition: ResourceLoaderFileModule.php:125
ResourceLoaderFileModule\$raw
bool $raw
Whether mw.loader.state() call should be omitted.
Definition: ResourceLoaderFileModule.php:123
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2220
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:177
string
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:175
list
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
ResourceLoaderFileModule\$messages
array $messages
List of message keys used by this module.
Definition: ResourceLoaderFileModule.php:114
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:546
ResourceLoaderFileModule\$languageScripts
array $languageScripts
List of JavaScript files to include when using a specific language.
Definition: ResourceLoaderFileModule.php:55
ResourceLoaderFileModule\stripBom
stripBom( $input)
Takes an input string and removes the UTF-8 BOM character if present.
Definition: ResourceLoaderFileModule.php:1032
ResourceLoaderModule\getDeprecationInformation
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
Definition: ResourceLoaderModule.php:142
ResourceLoaderFileModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Gets list of names of modules this module depends on.
Definition: ResourceLoaderFileModule.php:444
$value
$value
Definition: styleTest.css.php:45
ResourceLoaderFileModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderFileModule.php:917
ResourceLoaderFileModule\$skipFunction
string $skipFunction
File name containing the body of the skip function.
Definition: ResourceLoaderFileModule.php:105
ResourceLoaderFileModule\$group
string $group
Name of group to load this module in.
Definition: ResourceLoaderFileModule.php:117
ResourceLoaderFileModule\readStyleFile
readStyleFile( $path, $flip, $context)
Reads a style file.
Definition: ResourceLoaderFileModule.php:868
ResourceLoaderFileModule\$localFileRefs
array $localFileRefs
Place where readStyleFile() tracks file dependencies.
Definition: ResourceLoaderFileModule.php:143
CACHE_ANYTHING
const CACHE_ANYTHING
Definition: Defines.php:102
ResourceLoaderFileModule\readScriptFiles
readScriptFiles(array $scripts)
Gets the contents of a list of JavaScript files.
Definition: ResourceLoaderFileModule.php:799
ResourceLoaderModule\LOAD_STYLES
const LOAD_STYLES
Definition: ResourceLoaderModule.php:43
ResourceLoaderFileModule\collateFilePathListByOption
static collateFilePathListByOption(array $list, $option, $default)
Collates file paths by option (where provided).
Definition: ResourceLoaderFileModule.php:633
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
Definition: ResourceLoaderModule.php:979
ResourceLoaderFileModule\__construct
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.
Definition: ResourceLoaderFileModule.php:208
ResourceLoaderFileModule\$localBasePath
string $localBasePath
Local base path, see __construct()
Definition: ResourceLoaderFileModule.php:31
$wgResourceBasePath
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
Definition: DefaultSettings.php:3639
scripts
The package scripts
Definition: README.txt:1
ResourceLoaderFileModule\getScriptFiles
getScriptFiles(ResourceLoaderContext $context)
Get a list of file paths for all scripts in this module, in order of proper execution.
Definition: ResourceLoaderFileModule.php:681
ResourceLoaderFileModule\getStyleSheetLang
getStyleSheetLang( $path)
Infer the stylesheet language from a stylesheet file path.
Definition: ResourceLoaderFileModule.php:620
ResourceLoaderFileModule\getLocalPath
getLocalPath( $path)
Definition: ResourceLoaderFileModule.php:593
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:35
$cache
$cache
Definition: mcc.php:33
$options
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 & $options
Definition: hooks.txt:1987
ResourceLoaderFileModule\tryForKey
static tryForKey(array $list, $key, $fallback=null)
Get a list of element that match a key, optionally using a fallback key.
Definition: ResourceLoaderFileModule.php:663
ResourceLoaderFileModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderFileModule.php:1001
$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
messages
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error messages
Definition: hooks.txt:1275
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:403
ResourceLoaderFileModule\$remoteBasePath
string $remoteBasePath
Remote base path, see __construct()
Definition: ResourceLoaderFileModule.php:34
ResourceLoaderFileModule\supportsURLLoading
supportsURLLoading()
Definition: ResourceLoaderFileModule.php:374
ResourceLoaderFileModule\getMessages
getMessages()
Gets list of message keys used by this module.
Definition: ResourceLoaderFileModule.php:426
ResourceLoaderFileModule\getAllSkinStyleFiles
getAllSkinStyleFiles()
Gets a list of file paths for all skin style files in the module, for all available skins.
Definition: ResourceLoaderFileModule.php:755
ResourceLoaderFileModule\getStyleFiles
getStyleFiles(ResourceLoaderContext $context)
Get a list of file paths for all styles in this module, in order of proper inclusion.
Definition: ResourceLoaderFileModule.php:723
ResourceLoaderFileModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderFileModule.php:927
ResourceLoaderFileModule\getScript
getScript(ResourceLoaderContext $context)
Gets all scripts for a given context concatenated together.
Definition: ResourceLoaderFileModule.php:351
ResourceLoaderFileModule\$scripts
array $scripts
List of paths to JavaScript files to always include.
Definition: ResourceLoaderFileModule.php:46
ResourceLoaderFileModule\getLanguageScripts
getLanguageScripts( $lang)
Get the set of language scripts for the given language, possibly using a fallback language.
Definition: ResourceLoaderFileModule.php:701
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:185
ResourceLoaderFileModule\$missingLocalFileRefs
array $missingLocalFileRefs
Place where readStyleFile() tracks file dependencies for non-existent files.
Definition: ResourceLoaderFileModule.php:149
ResourceLoaderFileModule\isRaw
isRaw()
Definition: ResourceLoaderFileModule.php:472
array
the array() calling protocol came about after MediaWiki 1.4rc1.
OutputPage\transformResourcePath
static transformResourcePath(Config $config, $path)
Transform path to web-accessible static resource.
Definition: OutputPage.php:3697
ObjectCache\getLocalServerInstance
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
Definition: ObjectCache.php:288