MediaWiki  1.29.1
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 $debugRaw = true;
122 
124  protected $raw = false;
125 
126  protected $targets = [ 'desktop' ];
127 
129  protected $noflip = false;
130 
135  protected $hasGeneratedStyles = false;
136 
144  protected $localFileRefs = [];
145 
150  protected $missingLocalFileRefs = [];
151 
152  /* Methods */
153 
211  public function __construct(
212  $options = [],
213  $localBasePath = null,
214  $remoteBasePath = null
215  ) {
216  // Flag to decide whether to automagically add the mediawiki.template module
217  $hasTemplates = false;
218  // localBasePath and remoteBasePath both have unbelievably long fallback chains
219  // and need to be handled separately.
220  list( $this->localBasePath, $this->remoteBasePath ) =
222 
223  // Extract, validate and normalise remaining options
224  foreach ( $options as $member => $option ) {
225  switch ( $member ) {
226  // Lists of file paths
227  case 'scripts':
228  case 'debugScripts':
229  case 'styles':
230  $this->{$member} = (array)$option;
231  break;
232  case 'templates':
233  $hasTemplates = true;
234  $this->{$member} = (array)$option;
235  break;
236  // Collated lists of file paths
237  case 'languageScripts':
238  case 'skinScripts':
239  case 'skinStyles':
240  if ( !is_array( $option ) ) {
241  throw new InvalidArgumentException(
242  "Invalid collated file path list error. " .
243  "'$option' given, array expected."
244  );
245  }
246  foreach ( $option as $key => $value ) {
247  if ( !is_string( $key ) ) {
248  throw new InvalidArgumentException(
249  "Invalid collated file path list key error. " .
250  "'$key' given, string expected."
251  );
252  }
253  $this->{$member}[$key] = (array)$value;
254  }
255  break;
256  case 'deprecated':
257  $this->deprecated = $option;
258  break;
259  // Lists of strings
260  case 'dependencies':
261  case 'messages':
262  case 'targets':
263  // Normalise
264  $option = array_values( array_unique( (array)$option ) );
265  sort( $option );
266 
267  $this->{$member} = $option;
268  break;
269  // Single strings
270  case 'group':
271  case 'skipFunction':
272  $this->{$member} = (string)$option;
273  break;
274  // Single booleans
275  case 'debugRaw':
276  case 'raw':
277  case 'noflip':
278  $this->{$member} = (bool)$option;
279  break;
280  }
281  }
282  if ( $hasTemplates ) {
283  $this->dependencies[] = 'mediawiki.template';
284  // Ensure relevant template compiler module gets loaded
285  foreach ( $this->templates as $alias => $templatePath ) {
286  if ( is_int( $alias ) ) {
287  $alias = $templatePath;
288  }
289  $suffix = explode( '.', $alias );
290  $suffix = end( $suffix );
291  $compilerModule = 'mediawiki.template.' . $suffix;
292  if ( $suffix !== 'html' && !in_array( $compilerModule, $this->dependencies ) ) {
293  $this->dependencies[] = $compilerModule;
294  }
295  }
296  }
297  }
298 
310  public static function extractBasePaths(
311  $options = [],
312  $localBasePath = null,
313  $remoteBasePath = null
314  ) {
315  global $IP, $wgResourceBasePath;
316 
317  // The different ways these checks are done, and their ordering, look very silly,
318  // but were preserved for backwards-compatibility just in case. Tread lightly.
319 
320  if ( $localBasePath === null ) {
322  }
323  if ( $remoteBasePath === null ) {
324  $remoteBasePath = $wgResourceBasePath;
325  }
326 
327  if ( isset( $options['remoteExtPath'] ) ) {
329  $remoteBasePath = $wgExtensionAssetsPath . '/' . $options['remoteExtPath'];
330  }
331 
332  if ( isset( $options['remoteSkinPath'] ) ) {
334  $remoteBasePath = $wgStylePath . '/' . $options['remoteSkinPath'];
335  }
336 
337  if ( array_key_exists( 'localBasePath', $options ) ) {
338  $localBasePath = (string)$options['localBasePath'];
339  }
340 
341  if ( array_key_exists( 'remoteBasePath', $options ) ) {
342  $remoteBasePath = (string)$options['remoteBasePath'];
343  }
344 
345  return [ $localBasePath, $remoteBasePath ];
346  }
347 
355  $files = $this->getScriptFiles( $context );
356  return $this->getDeprecationInformation() . $this->readScriptFiles( $files );
357  }
358 
364  $urls = [];
365  foreach ( $this->getScriptFiles( $context ) as $file ) {
367  $this->getConfig(),
368  $this->getRemotePath( $file )
369  );
370  }
371  return $urls;
372  }
373 
377  public function supportsURLLoading() {
378  return $this->debugRaw;
379  }
380 
388  $styles = $this->readStyleFiles(
389  $this->getStyleFiles( $context ),
390  $this->getFlip( $context ),
391  $context
392  );
393  // Collect referenced files
394  $this->saveFileDependencies( $context, $this->localFileRefs );
395 
396  return $styles;
397  }
398 
404  if ( $this->hasGeneratedStyles ) {
405  // Do the default behaviour of returning a url back to load.php
406  // but with only=styles.
407  return parent::getStyleURLsForDebug( $context );
408  }
409  // Our module consists entirely of real css files,
410  // in debug mode we can load those directly.
411  $urls = [];
412  foreach ( $this->getStyleFiles( $context ) as $mediaType => $list ) {
413  $urls[$mediaType] = [];
414  foreach ( $list as $file ) {
415  $urls[$mediaType][] = OutputPage::transformResourcePath(
416  $this->getConfig(),
417  $this->getRemotePath( $file )
418  );
419  }
420  }
421  return $urls;
422  }
423 
429  public function getMessages() {
430  return $this->messages;
431  }
432 
438  public function getGroup() {
439  return $this->group;
440  }
441 
447  public function getDependencies( ResourceLoaderContext $context = null ) {
448  return $this->dependencies;
449  }
450 
456  public function getSkipFunction() {
457  if ( !$this->skipFunction ) {
458  return null;
459  }
460 
461  $localPath = $this->getLocalPath( $this->skipFunction );
462  if ( !file_exists( $localPath ) ) {
463  throw new MWException( __METHOD__ . ": skip function file not found: \"$localPath\"" );
464  }
465  $contents = $this->stripBom( file_get_contents( $localPath ) );
466  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
467  $contents = $this->validateScriptFile( $localPath, $contents );
468  }
469  return $contents;
470  }
471 
475  public function isRaw() {
476  return $this->raw;
477  }
478 
487  public function enableModuleContentVersion() {
488  return false;
489  }
490 
502  $files = [];
503 
504  // Flatten style files into $files
505  $styles = self::collateFilePathListByOption( $this->styles, 'media', 'all' );
506  foreach ( $styles as $styleFiles ) {
507  $files = array_merge( $files, $styleFiles );
508  }
509 
511  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
512  'media',
513  'all'
514  );
515  foreach ( $skinFiles as $styleFiles ) {
516  $files = array_merge( $files, $styleFiles );
517  }
518 
519  // Final merge, this should result in a master list of dependent files
520  $files = array_merge(
521  $files,
522  $this->scripts,
523  $this->templates,
524  $context->getDebug() ? $this->debugScripts : [],
525  $this->getLanguageScripts( $context->getLanguage() ),
526  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
527  );
528  if ( $this->skipFunction ) {
529  $files[] = $this->skipFunction;
530  }
531  $files = array_map( [ $this, 'getLocalPath' ], $files );
532  // File deps need to be treated separately because they're already prefixed
533  $files = array_merge( $files, $this->getFileDependencies( $context ) );
534  // Filter out any duplicates from getFileDependencies() and others.
535  // Most commonly introduced by compileLessFile(), which always includes the
536  // entry point Less file we already know about.
537  $files = array_values( array_unique( $files ) );
538 
539  // Don't include keys or file paths here, only the hashes. Including that would needlessly
540  // cause global cache invalidation when files move or if e.g. the MediaWiki path changes.
541  // Any significant ordering is already detected by the definition summary.
542  return array_map( [ __CLASS__, 'safeFileHash' ], $files );
543  }
544 
552  $summary = parent::getDefinitionSummary( $context );
553 
554  $options = [];
555  foreach ( [
556  // The following properties are omitted because they don't affect the module reponse:
557  // - localBasePath (Per T104950; Changes when absolute directory name changes. If
558  // this affects 'scripts' and other file paths, getFileHashes accounts for that.)
559  // - remoteBasePath (Per T104950)
560  // - dependencies (provided via startup module)
561  // - targets
562  // - group (provided via startup module)
563  'scripts',
564  'debugScripts',
565  'styles',
566  'languageScripts',
567  'skinScripts',
568  'skinStyles',
569  'messages',
570  'templates',
571  'skipFunction',
572  'debugRaw',
573  'raw',
574  ] as $member ) {
575  $options[$member] = $this->{$member};
576  };
577 
578  $summary[] = [
579  'options' => $options,
580  'fileHashes' => $this->getFileHashes( $context ),
581  'messageBlob' => $this->getMessageBlob( $context ),
582  ];
583  return $summary;
584  }
585 
590  protected function getLocalPath( $path ) {
591  if ( $path instanceof ResourceLoaderFilePath ) {
592  return $path->getLocalPath();
593  }
594 
595  return "{$this->localBasePath}/$path";
596  }
597 
602  protected function getRemotePath( $path ) {
603  if ( $path instanceof ResourceLoaderFilePath ) {
604  return $path->getRemotePath();
605  }
606 
607  return "{$this->remoteBasePath}/$path";
608  }
609 
617  public function getStyleSheetLang( $path ) {
618  return preg_match( '/\.less$/i', $path ) ? 'less' : 'css';
619  }
620 
630  protected static function collateFilePathListByOption( array $list, $option, $default ) {
631  $collatedFiles = [];
632  foreach ( (array)$list as $key => $value ) {
633  if ( is_int( $key ) ) {
634  // File name as the value
635  if ( !isset( $collatedFiles[$default] ) ) {
636  $collatedFiles[$default] = [];
637  }
638  $collatedFiles[$default][] = $value;
639  } elseif ( is_array( $value ) ) {
640  // File name as the key, options array as the value
641  $optionValue = isset( $value[$option] ) ? $value[$option] : $default;
642  if ( !isset( $collatedFiles[$optionValue] ) ) {
643  $collatedFiles[$optionValue] = [];
644  }
645  $collatedFiles[$optionValue][] = $key;
646  }
647  }
648  return $collatedFiles;
649  }
650 
660  protected static function tryForKey( array $list, $key, $fallback = null ) {
661  if ( isset( $list[$key] ) && is_array( $list[$key] ) ) {
662  return $list[$key];
663  } elseif ( is_string( $fallback )
664  && isset( $list[$fallback] )
665  && is_array( $list[$fallback] )
666  ) {
667  return $list[$fallback];
668  }
669  return [];
670  }
671 
679  $files = array_merge(
680  $this->scripts,
681  $this->getLanguageScripts( $context->getLanguage() ),
682  self::tryForKey( $this->skinScripts, $context->getSkin(), 'default' )
683  );
684  if ( $context->getDebug() ) {
685  $files = array_merge( $files, $this->debugScripts );
686  }
687 
688  return array_unique( $files, SORT_REGULAR );
689  }
690 
698  private function getLanguageScripts( $lang ) {
699  $scripts = self::tryForKey( $this->languageScripts, $lang );
700  if ( $scripts ) {
701  return $scripts;
702  }
703  $fallbacks = Language::getFallbacksFor( $lang );
704  foreach ( $fallbacks as $lang ) {
705  $scripts = self::tryForKey( $this->languageScripts, $lang );
706  if ( $scripts ) {
707  return $scripts;
708  }
709  }
710 
711  return [];
712  }
713 
721  return array_merge_recursive(
722  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
723  self::collateFilePathListByOption(
724  self::tryForKey( $this->skinStyles, $context->getSkin(), 'default' ),
725  'media',
726  'all'
727  )
728  );
729  }
730 
738  protected function getSkinStyleFiles( $skinName ) {
740  self::tryForKey( $this->skinStyles, $skinName ),
741  'media',
742  'all'
743  );
744  }
745 
752  protected function getAllSkinStyleFiles() {
753  $styleFiles = [];
754  $internalSkinNames = array_keys( Skin::getSkinNames() );
755  $internalSkinNames[] = 'default';
756 
757  foreach ( $internalSkinNames as $internalSkinName ) {
758  $styleFiles = array_merge_recursive(
759  $styleFiles,
760  $this->getSkinStyleFiles( $internalSkinName )
761  );
762  }
763 
764  return $styleFiles;
765  }
766 
772  public function getAllStyleFiles() {
773  $collatedStyleFiles = array_merge_recursive(
774  self::collateFilePathListByOption( $this->styles, 'media', 'all' ),
775  $this->getAllSkinStyleFiles()
776  );
777 
778  $result = [];
779 
780  foreach ( $collatedStyleFiles as $media => $styleFiles ) {
781  foreach ( $styleFiles as $styleFile ) {
782  $result[] = $this->getLocalPath( $styleFile );
783  }
784  }
785 
786  return $result;
787  }
788 
796  protected function readScriptFiles( array $scripts ) {
797  if ( empty( $scripts ) ) {
798  return '';
799  }
800  $js = '';
801  foreach ( array_unique( $scripts, SORT_REGULAR ) as $fileName ) {
802  $localPath = $this->getLocalPath( $fileName );
803  if ( !file_exists( $localPath ) ) {
804  throw new MWException( __METHOD__ . ": script file not found: \"$localPath\"" );
805  }
806  $contents = $this->stripBom( file_get_contents( $localPath ) );
807  if ( $this->getConfig()->get( 'ResourceLoaderValidateStaticJS' ) ) {
808  // Static files don't really need to be checked as often; unlike
809  // on-wiki module they shouldn't change unexpectedly without
810  // admin interference.
811  $contents = $this->validateScriptFile( $fileName, $contents );
812  }
813  $js .= $contents . "\n";
814  }
815  return $js;
816  }
817 
833  public function readStyleFiles( array $styles, $flip, $context = null ) {
834  if ( $context === null ) {
835  wfDeprecated( __METHOD__ . ' without a ResourceLoader context', '1.27' );
837  }
838 
839  if ( empty( $styles ) ) {
840  return [];
841  }
842  foreach ( $styles as $media => $files ) {
843  $uniqueFiles = array_unique( $files, SORT_REGULAR );
844  $styleFiles = [];
845  foreach ( $uniqueFiles as $file ) {
846  $styleFiles[] = $this->readStyleFile( $file, $flip, $context );
847  }
848  $styles[$media] = implode( "\n", $styleFiles );
849  }
850  return $styles;
851  }
852 
865  protected function readStyleFile( $path, $flip, $context ) {
866  $localPath = $this->getLocalPath( $path );
867  $remotePath = $this->getRemotePath( $path );
868  if ( !file_exists( $localPath ) ) {
869  $msg = __METHOD__ . ": style file not found: \"$localPath\"";
870  wfDebugLog( 'resourceloader', $msg );
871  throw new MWException( $msg );
872  }
873 
874  if ( $this->getStyleSheetLang( $localPath ) === 'less' ) {
875  $style = $this->compileLessFile( $localPath, $context );
876  $this->hasGeneratedStyles = true;
877  } else {
878  $style = $this->stripBom( file_get_contents( $localPath ) );
879  }
880 
881  if ( $flip ) {
882  $style = CSSJanus::transform( $style, true, false );
883  }
884  $localDir = dirname( $localPath );
885  $remoteDir = dirname( $remotePath );
886  // Get and register local file references
887  $localFileRefs = CSSMin::getLocalFileReferences( $style, $localDir );
888  foreach ( $localFileRefs as $file ) {
889  if ( file_exists( $file ) ) {
890  $this->localFileRefs[] = $file;
891  } else {
892  $this->missingLocalFileRefs[] = $file;
893  }
894  }
895  // Don't cache this call. remap() ensures data URIs embeds are up to date,
896  // and urls contain correct content hashes in their query string. (T128668)
897  return CSSMin::remap( $style, $localDir, $remoteDir, true );
898  }
899 
905  public function getFlip( $context ) {
906  return $context->getDirection() === 'rtl' && !$this->noflip;
907  }
908 
914  public function getTargets() {
915  return $this->targets;
916  }
917 
924  public function getType() {
925  $canBeStylesOnly = !(
926  // All options except 'styles', 'skinStyles' and 'debugRaw'
927  $this->scripts
928  || $this->debugScripts
929  || $this->templates
930  || $this->languageScripts
931  || $this->skinScripts
932  || $this->dependencies
933  || $this->messages
934  || $this->skipFunction
935  || $this->raw
936  );
937  return $canBeStylesOnly ? self::LOAD_STYLES : self::LOAD_GENERAL;
938  }
939 
952  protected function compileLessFile( $fileName, ResourceLoaderContext $context ) {
953  static $cache;
954 
955  if ( !$cache ) {
957  }
958 
959  // Construct a cache key from the LESS file name and a hash digest
960  // of the LESS variables used for compilation.
961  $vars = $this->getLessVars( $context );
962  ksort( $vars );
963  $varsHash = hash( 'md4', serialize( $vars ) );
964  $cacheKey = $cache->makeGlobalKey( 'LESS', $fileName, $varsHash );
965  $cachedCompile = $cache->get( $cacheKey );
966 
967  // If we got a cached value, we have to validate it by getting a
968  // checksum of all the files that were loaded by the parser and
969  // ensuring it matches the cached entry's.
970  if ( isset( $cachedCompile['hash'] ) ) {
971  $contentHash = FileContentsHasher::getFileContentsHash( $cachedCompile['files'] );
972  if ( $contentHash === $cachedCompile['hash'] ) {
973  $this->localFileRefs = array_merge( $this->localFileRefs, $cachedCompile['files'] );
974  return $cachedCompile['css'];
975  }
976  }
977 
978  $compiler = $context->getResourceLoader()->getLessCompiler( $vars );
979  $css = $compiler->parseFile( $fileName )->getCss();
980  $files = $compiler->AllParsedFiles();
981  $this->localFileRefs = array_merge( $this->localFileRefs, $files );
982 
983  $cache->set( $cacheKey, [
984  'css' => $css,
985  'files' => $files,
986  'hash' => FileContentsHasher::getFileContentsHash( $files ),
987  ], 60 * 60 * 24 ); // 86400 seconds, or 24 hours.
988 
989  return $css;
990  }
991 
997  public function getTemplates() {
998  $templates = [];
999 
1000  foreach ( $this->templates as $alias => $templatePath ) {
1001  // Alias is optional
1002  if ( is_int( $alias ) ) {
1003  $alias = $templatePath;
1004  }
1005  $localPath = $this->getLocalPath( $templatePath );
1006  if ( file_exists( $localPath ) ) {
1007  $content = file_get_contents( $localPath );
1008  $templates[$alias] = $this->stripBom( $content );
1009  } else {
1010  $msg = __METHOD__ . ": template file not found: \"$localPath\"";
1011  wfDebugLog( 'resourceloader', $msg );
1012  throw new MWException( $msg );
1013  }
1014  }
1015  return $templates;
1016  }
1017 
1027  protected function stripBom( $input ) {
1028  if ( substr_compare( "\xef\xbb\xbf", $input, 0, 3 ) === 0 ) {
1029  return substr( $input, 3 );
1030  }
1031  return $input;
1032  }
1033 }
Language\getFallbacksFor
static getFallbacksFor( $code)
Get the ordered list of fallback languages.
Definition: Language.php:4416
ResourceLoaderModule\LOAD_GENERAL
const LOAD_GENERAL
Definition: ResourceLoaderModule.php:44
ResourceLoaderFileModule\getSkipFunction
getSkipFunction()
Get the skip function.
Definition: ResourceLoaderFileModule.php:456
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:83
$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
ResourceLoaderFileModule\$skinScripts
array $skinScripts
List of JavaScript files to include when using a specific skin.
Definition: ResourceLoaderFileModule.php:65
ResourceLoaderFileModule\$debugScripts
array $debugScripts
List of paths to JavaScript files to include in debug mode.
Definition: ResourceLoaderFileModule.php:74
ResourceLoaderContext\newDummyContext
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
Definition: ResourceLoaderContext.php:139
$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:38
CSSMin\remap
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
ResourceLoaderFileModule\getStyles
getStyles(ResourceLoaderContext $context)
Get all styles for a given context.
Definition: ResourceLoaderFileModule.php:387
$fallback
$fallback
Definition: MessagesAb.php:11
ResourceLoaderFileModule\getFileHashes
getFileHashes(ResourceLoaderContext $context)
Helper method to gather file hashes for getDefinitionSummary.
Definition: ResourceLoaderFileModule.php:501
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
ResourceLoaderFileModule\$noflip
bool $noflip
Whether CSSJanus flipping should be skipped for this module.
Definition: ResourceLoaderFileModule.php:129
ResourceLoaderFileModule\getScriptURLsForDebug
getScriptURLsForDebug(ResourceLoaderContext $context)
Definition: ResourceLoaderFileModule.php:363
ResourceLoaderFileModule\getFlip
getFlip( $context)
Get whether CSS for this module should be flipped.
Definition: ResourceLoaderFileModule.php:905
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:487
ResourceLoaderFileModule\$debugRaw
bool $debugRaw
Link to raw files in debug mode.
Definition: ResourceLoaderFileModule.php:121
$wgExtensionAssetsPath
$wgExtensionAssetsPath
The URL path of the extensions directory.
Definition: DefaultSettings.php:232
ResourceLoaderFileModule\$hasGeneratedStyles
bool $hasGeneratedStyles
Whether getStyleURLsForDebug should return raw file paths, or return load.php urls.
Definition: ResourceLoaderFileModule.php:135
serialize
serialize()
Definition: ApiMessage.php:177
ResourceLoaderFileModule\$dependencies
array $dependencies
List of modules this module depends on.
Definition: ResourceLoaderFileModule.php:101
ResourceLoaderFileModule\$skinStyles
array $skinStyles
List of paths to CSS files to include when using specific skins.
Definition: ResourceLoaderFileModule.php:92
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
$wgStylePath
$wgStylePath
The URL path of the skins directory.
Definition: DefaultSettings.php:217
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:551
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
Skin\getSkinNames
static getSkinNames()
Fetch the set of available skins.
Definition: Skin.php:49
ResourceLoaderModule\getLessVars
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Definition: ResourceLoaderModule.php:597
ResourceLoaderFileModule\readStyleFiles
readStyleFiles(array $styles, $flip, $context=null)
Gets the contents of a list of CSS files.
Definition: ResourceLoaderFileModule.php:833
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:438
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1128
$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:738
ResourceLoaderFileModule\compileLessFile
compileLessFile( $fileName, ResourceLoaderContext $context)
Compile a LESS file into CSS.
Definition: ResourceLoaderFileModule.php:952
ResourceLoaderFileModule\getAllStyleFiles
getAllStyleFiles()
Returns all style files and all skin style files used by this module.
Definition: ResourceLoaderFileModule.php:772
$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
$input
if(is_array( $mode)) switch( $mode) $input
Definition: postprocess-phan.php:141
ResourceLoaderModule\$contents
$contents
Definition: ResourceLoaderModule.php:80
$IP
$IP
Definition: update.php:3
ContextSource\getSkin
getSkin()
Get the Skin object.
Definition: ContextSource.php:153
ResourceLoaderFileModule\getStyleURLsForDebug
getStyleURLsForDebug(ResourceLoaderContext $context)
Definition: ResourceLoaderFileModule.php:403
ResourceLoaderFileModule\getRemotePath
getRemotePath( $path)
Definition: ResourceLoaderFileModule.php:602
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:310
ResourceLoaderFileModule\$targets
$targets
Definition: ResourceLoaderFileModule.php:126
ResourceLoaderFileModule\$raw
bool $raw
Whether mw.loader.state() call should be omitted.
Definition: ResourceLoaderFileModule.php:124
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:2179
ResourceLoaderContext\getLanguage
getLanguage()
Definition: ResourceLoaderContext.php:178
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:177
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:115
ResourceLoaderModule\getMessageBlob
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
Definition: ResourceLoaderModule.php:560
ResourceLoaderFileModule\$languageScripts
array $languageScripts
List of JavaScript files to include when using a specific language.
Definition: ResourceLoaderFileModule.php:56
ResourceLoaderFileModule\stripBom
stripBom( $input)
Takes an input string and removes the UTF-8 BOM character if present.
Definition: ResourceLoaderFileModule.php:1027
ResourceLoaderModule\getDeprecationInformation
getDeprecationInformation()
Get JS representing deprecation information for the current module if available.
Definition: ResourceLoaderModule.php:145
ResourceLoaderFileModule\getDependencies
getDependencies(ResourceLoaderContext $context=null)
Gets list of names of modules this module depends on.
Definition: ResourceLoaderFileModule.php:447
$value
$value
Definition: styleTest.css.php:45
CSSMin\getLocalFileReferences
static getLocalFileReferences( $source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
Definition: CSSMin.php:69
ResourceLoaderFileModule\getTargets
getTargets()
Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
Definition: ResourceLoaderFileModule.php:914
ResourceLoaderFileModule\$skipFunction
string $skipFunction
File name containing the body of the skip function.
Definition: ResourceLoaderFileModule.php:106
ResourceLoaderFileModule\$group
string $group
Name of group to load this module in.
Definition: ResourceLoaderFileModule.php:118
ResourceLoaderFileModule\readStyleFile
readStyleFile( $path, $flip, $context)
Reads a style file.
Definition: ResourceLoaderFileModule.php:865
ResourceLoaderFileModule\$localFileRefs
array $localFileRefs
Place where readStyleFile() tracks file dependencies.
Definition: ResourceLoaderFileModule.php:144
CACHE_ANYTHING
const CACHE_ANYTHING
Definition: Defines.php:99
ResourceLoaderFileModule\readScriptFiles
readScriptFiles(array $scripts)
Gets the contents of a list of JavaScript files.
Definition: ResourceLoaderFileModule.php:796
ResourceLoaderModule\LOAD_STYLES
const LOAD_STYLES
Definition: ResourceLoaderModule.php:42
ResourceLoaderFileModule\collateFilePathListByOption
static collateFilePathListByOption(array $list, $option, $default)
Collates file paths by option (where provided).
Definition: ResourceLoaderFileModule.php:630
ResourceLoaderModule\validateScriptFile
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
Definition: ResourceLoaderModule.php:933
ResourceLoaderFileModule\__construct
__construct( $options=[], $localBasePath=null, $remoteBasePath=null)
Constructs a new module from an options array.
Definition: ResourceLoaderFileModule.php:211
ResourceLoaderFileModule\$localBasePath
string $localBasePath
Local base path, see __construct()
Definition: ResourceLoaderFileModule.php:32
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:678
ResourceLoaderFileModule\getStyleSheetLang
getStyleSheetLang( $path)
Infer the stylesheet language from a stylesheet file path.
Definition: ResourceLoaderFileModule.php:617
ResourceLoaderFileModule\getLocalPath
getLocalPath( $path)
Definition: ResourceLoaderFileModule.php:590
ResourceLoaderModule
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition: ResourceLoaderModule.php:34
$cache
$cache
Definition: mcc.php:33
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:660
ResourceLoaderFileModule\getTemplates
getTemplates()
Takes named templates by the module and returns an array mapping.
Definition: ResourceLoaderFileModule.php:997
$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
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:1252
ResourceLoaderModule\getFileDependencies
getFileDependencies(ResourceLoaderContext $context)
Get the files this module depends on indirectly for a given skin.
Definition: ResourceLoaderModule.php:416
ResourceLoaderFileModule\$remoteBasePath
string $remoteBasePath
Remote base path, see __construct()
Definition: ResourceLoaderFileModule.php:35
ResourceLoaderFileModule\supportsURLLoading
supportsURLLoading()
Definition: ResourceLoaderFileModule.php:377
ResourceLoaderFileModule\getMessages
getMessages()
Gets list of message keys used by this module.
Definition: ResourceLoaderFileModule.php:429
ResourceLoaderFileModule\getAllSkinStyleFiles
getAllSkinStyleFiles()
Gets a list of file paths for all skin style files in the module, for all available skins.
Definition: ResourceLoaderFileModule.php:752
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:720
ResourceLoaderFileModule\getType
getType()
Get the module's load type.
Definition: ResourceLoaderFileModule.php:924
ResourceLoaderFileModule\getScript
getScript(ResourceLoaderContext $context)
Gets all scripts for a given context concatenated together.
Definition: ResourceLoaderFileModule.php:354
ResourceLoaderFileModule\$scripts
array $scripts
List of paths to JavaScript files to always include.
Definition: ResourceLoaderFileModule.php:47
ResourceLoaderFileModule\getLanguageScripts
getLanguageScripts( $lang)
Get the set of language scripts for the given language, possibly using a fallback language.
Definition: ResourceLoaderFileModule.php:698
$options
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 as context as context $options
Definition: hooks.txt:1049
ResourceLoaderModule\getConfig
getConfig()
Definition: ResourceLoaderModule.php:188
ResourceLoaderFileModule\$missingLocalFileRefs
array $missingLocalFileRefs
Place where readStyleFile() tracks file dependencies for non-existent files.
Definition: ResourceLoaderFileModule.php:150
ResourceLoaderFileModule\isRaw
isRaw()
Definition: ResourceLoaderFileModule.php:475
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:3759
ObjectCache\getLocalServerInstance
static getLocalServerInstance( $fallback=CACHE_NONE)
Factory function for CACHE_ACCEL (referenced from DefaultSettings.php)
Definition: ObjectCache.php:288