MediaWiki REL1_30
CiteDataModule Class Reference
Inheritance diagram for CiteDataModule:
Collaboration diagram for CiteDataModule:

Public Member Functions

 getDefinitionSummary (ResourceLoaderContext $context)
 Get a list of resources that web browsers may preload.
 
 getDependencies (ResourceLoaderContext $context=null)
 Get a list of modules this module depends on.
 
 getScript (ResourceLoaderContext $context)
 Get all JS for this module for a given language and skin.
 
- Public Member Functions inherited from ResourceLoaderModule
 getConfig ()
 
 getDefinitionMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime().
 
 getFlip ( $context)
 
 getGroup ()
 Get the group this module is in.
 
 getHashMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime().
 
 getHeaders (ResourceLoaderContext $context)
 Get headers to send as part of a module web response.
 
 getMessages ()
 Get the messages needed for this module.
 
 getModifiedHash (ResourceLoaderContext $context)
 Helper method for providing a version hash to getVersionHash().
 
 getModifiedTime (ResourceLoaderContext $context)
 Get this module's last modification timestamp for a given context.
 
 getName ()
 Get this module's name.
 
 getOrigin ()
 Get this module's origin.
 
 getPosition ()
 From where in the page HTML should this module be loaded?
 
 getScriptURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's JS in debug mode.
 
 getSkipFunction ()
 Get the skip function.
 
 getSource ()
 Get the origin of this module.
 
 getStyles (ResourceLoaderContext $context)
 Get all CSS for this module for a given skin.
 
 getStyleURLsForDebug (ResourceLoaderContext $context)
 Get the URL or URLs to load for this module's CSS in debug mode.
 
 getTargets ()
 Get target(s) for the module, eg ['desktop'] or ['desktop', 'mobile'].
 
 getTemplates ()
 Takes named templates by the module and returns an array mapping.
 
 getType ()
 Get the module's load type.
 
 isKnownEmpty (ResourceLoaderContext $context)
 Check whether this module is known to be empty.
 
 isRaw ()
 Whether this module's JS expects to work without the client-side ResourceLoader module.
 
 setConfig (Config $config)
 
 setFileDependencies (ResourceLoaderContext $context, $files)
 Set in-object cache for file dependencies.
 
 setLogger (LoggerInterface $logger)
 
 setMessageBlob ( $blob, $lang)
 Set in-object cache for message blobs.
 
 setName ( $name)
 Set this module's name.
 
 shouldEmbedModule (ResourceLoaderContext $context)
 Check whether this module should be embeded rather than linked.
 
 supportsURLLoading ()
 Whether this module supports URL loading.
 

Protected Attributes

 $origin = self::ORIGIN_USER_SITEWIDE
 
 $targets = [ 'desktop', 'mobile' ]
 
- Protected Attributes inherited from ResourceLoaderModule
Config $config
 
 $contents = []
 
array bool $deprecated = false
 
 $fileDeps = []
 
LoggerInterface $logger
 
 $msgBlobs = []
 
 $name = null
 
 $origin = self::ORIGIN_CORE_SITEWIDE
 
 $targets = [ 'desktop' ]
 
 $versionHash = []
 

Additional Inherited Members

- Static Public Member Functions inherited from ResourceLoaderModule
static expandRelativePaths (array $filePaths)
 Expand directories relative to $IP.
 
static getRelativePaths (array $filePaths)
 Make file paths relative to MediaWiki directory.
 
- Public Attributes inherited from ResourceLoaderModule
const LOAD_GENERAL = 'general'
 
const LOAD_STYLES = 'styles'
 
const ORIGIN_ALL = 10
 
const ORIGIN_CORE_INDIVIDUAL = 2
 
const ORIGIN_CORE_SITEWIDE = 1
 
const ORIGIN_USER_INDIVIDUAL = 4
 
const ORIGIN_USER_SITEWIDE = 3
 
const TYPE_COMBINED = 'combined'
 
const TYPE_SCRIPTS = 'scripts'
 
const TYPE_STYLES = 'styles'
 
- Protected Member Functions inherited from ResourceLoaderModule
 getDeprecationInformation ()
 Get JS representing deprecation information for the current module if available.
 
 getFileDependencies (ResourceLoaderContext $context)
 Get the files this module depends on indirectly for a given skin.
 
 getLogger ()
 
 getMessageBlob (ResourceLoaderContext $context)
 Get the hash of the message blob.
 
 saveFileDependencies (ResourceLoaderContext $context, $localFileRefs)
 Set 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.
 
- Static Protected Member Functions inherited from ResourceLoaderModule
static javaScriptParser ()
 
static safeFileHash ( $filePath)
 Compute a non-cryptographic string hash of a file's contents.
 
static safeFilemtime ( $filePath)
 Safe version of filemtime(), which doesn't throw a PHP warning if the file doesn't exist.
 

Detailed Description

Definition at line 13 of file CiteDataModule.php.

Member Function Documentation

◆ getDefinitionSummary()

CiteDataModule::getDefinitionSummary ( ResourceLoaderContext $context)

Get a list of resources that web browsers may preload.

Behaviour of rel=preload link is specified at https://www.w3.org/TR/preload/.

Use case for ResourceLoader originally part of T164299.

Example
protected function getPreloadLinks() {
return [
'https://example.org/script.js' => [ 'as' => 'script' ],
'https://example.org/image.png' => [ 'as' => 'image' ],
];
}
@encode
@par Example using HiDPI image variants
@code
protected function getPreloadLinks() {
return [
'https://example.org/logo.png' => [
'as' => 'image',
'media' => 'not all and (min-resolution: 2dppx)',
],
'https://example.org/logo@2x.png' => [
'as' => 'image',
'media' => '(min-resolution: 2dppx)',
],
];
}
@encode
@since 1.30
@return array Keyed by url, values must be an array containing
at least an 'as' key. Optionally a 'media' key as well.
/
protected function getPreloadLinks( ResourceLoaderContext $context ) {
return [];
}
protected function getLessVars( ResourceLoaderContext $context ) {
return [];
}
public function getModuleContent( ResourceLoaderContext $context ) {
$contextHash = $context->getHash();
// Cache this expensive operation. This calls builds the scripts, styles, and messages
// content which typically involves filesystem and/or database access.
if ( !array_key_exists( $contextHash, $this->contents ) ) {
$this->contents[$contextHash] = $this->buildContent( $context );
}
return $this->contents[$contextHash];
}
final protected function buildContent( ResourceLoaderContext $context ) {
$rl = $context->getResourceLoader();
$stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
$statStart = microtime( true );
// Only include properties that are relevant to this context (e.g. only=scripts)
// and that are non-empty (e.g. don't include "templates" for modules without
// templates). This helps prevent invalidating cache for all modules when new
// optional properties are introduced.
$content = [];
// Scripts
if ( $context->shouldIncludeScripts() ) {
// If we are in debug mode, we'll want to return an array of URLs if possible
// However, we can't do this if the module doesn't support it
// We also can't do this if there is an only= parameter, because we have to give
// the module a way to return a load.php URL without causing an infinite loop
if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
$scripts = $this->getScriptURLsForDebug( $context );
} else {
$scripts = $this->getScript( $context );
// Make the script safe to concatenate by making sure there is at least one
// trailing new line at the end of the content. Previously, this looked for
// a semi-colon instead, but that breaks concatenation if the semicolon
// is inside a comment like "// foo();". Instead, simply use a
// line break as separator which matches JavaScript native logic for implicitly
// ending statements even if a semi-colon is missing.
// Bugs: T29054, T162719.
if ( is_string( $scripts )
&& strlen( $scripts )
&& substr( $scripts, -1 ) !== "\n"
) {
$scripts .= "\n";
}
}
$content['scripts'] = $scripts;
}
// Styles
if ( $context->shouldIncludeStyles() ) {
$styles = [];
// Don't create empty stylesheets like [ '' => '' ] for modules
// that don't *have* any stylesheets (T40024).
$stylePairs = $this->getStyles( $context );
if ( count( $stylePairs ) ) {
// If we are in debug mode without &only= set, we'll want to return an array of URLs
// See comment near shouldIncludeScripts() for more details
if ( $context->getDebug() && !$context->getOnly() && $this->supportsURLLoading() ) {
$styles = [
'url' => $this->getStyleURLsForDebug( $context )
];
} else {
// Minify CSS before embedding in mw.loader.implement call
// (unless in debug mode)
if ( !$context->getDebug() ) {
foreach ( $stylePairs as $media => $style ) {
// Can be either a string or an array of strings.
if ( is_array( $style ) ) {
$stylePairs[$media] = [];
foreach ( $style as $cssText ) {
if ( is_string( $cssText ) ) {
$stylePairs[$media][] =
ResourceLoader::filter( 'minify-css', $cssText );
}
}
} elseif ( is_string( $style ) ) {
$stylePairs[$media] = ResourceLoader::filter( 'minify-css', $style );
}
}
}
// Wrap styles into @media groups as needed and flatten into a numerical array
$styles = [
'css' => $rl->makeCombinedStyles( $stylePairs )
];
}
}
$content['styles'] = $styles;
}
// Messages
$blob = $this->getMessageBlob( $context );
if ( $blob ) {
$content['messagesBlob'] = $blob;
}
$templates = $this->getTemplates();
if ( $templates ) {
$content['templates'] = $templates;
}
$headers = $this->getHeaders( $context );
if ( $headers ) {
$content['headers'] = $headers;
}
$statTiming = microtime( true ) - $statStart;
$statName = strtr( $this->getName(), '.', '_' );
$stats->timing( "resourceloader_build.all", 1000 * $statTiming );
$stats->timing( "resourceloader_build.$statName", 1000 * $statTiming );
return $content;
}
public function getVersionHash( ResourceLoaderContext $context ) {
// The startup module produces a manifest with versions representing the entire module.
// Typically, the request for the startup module itself has only=scripts. That must apply
// only to the startup module content, and not to the module version computed here.
$context->setModules( [] );
// Version hash must cover all resources, regardless of startup request itself.
$context->setOnly( null );
// Compute version hash based on content, not debug urls.
$context->setDebug( false );
// Cache this somewhat expensive operation. Especially because some classes
// (e.g. startup module) iterate more than once over all modules to get versions.
$contextHash = $context->getHash();
if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
if ( $this->enableModuleContentVersion() ) {
// Detect changes directly
$str = json_encode( $this->getModuleContent( $context ) );
} else {
// Infer changes based on definition and other metrics
$summary = $this->getDefinitionSummary( $context );
if ( !isset( $summary['_cacheEpoch'] ) ) {
throw new LogicException( 'getDefinitionSummary must call parent method' );
}
$str = json_encode( $summary );
$mtime = $this->getModifiedTime( $context );
if ( $mtime !== null ) {
// Support: MediaWiki 1.25 and earlier
$str .= strval( $mtime );
}
$mhash = $this->getModifiedHash( $context );
if ( $mhash !== null ) {
// Support: MediaWiki 1.25 and earlier
$str .= strval( $mhash );
}
}
$this->versionHash[$contextHash] = ResourceLoader::makeHash( $str );
}
return $this->versionHash[$contextHash];
}
public function enableModuleContentVersion() {
return false;
}
getDefinitionSummary(ResourceLoaderContext $context)
Get a list of resources that web browsers may preload.
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
Allows changing specific properties of a context object, without changing the main one.
Object passed around to modules which contains information about the state of a specific loader reque...
getModifiedHash(ResourceLoaderContext $context)
Helper method for providing a version hash to getVersionHash().
getMessageBlob(ResourceLoaderContext $context)
Get the hash of the message blob.
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
getScriptURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's JS in debug mode.
getStyleURLsForDebug(ResourceLoaderContext $context)
Get the URL or URLs to load for this module's CSS in debug mode.
getModifiedTime(ResourceLoaderContext $context)
Get this module's last modification timestamp for a given context.
getName()
Get this module's name.
getHeaders(ResourceLoaderContext $context)
Get headers to send as part of a module web response.
getTemplates()
Takes named templates by the module and returns an array mapping.
static makeHash( $value)
static filter( $filter, $data, array $options=[])
Run JavaScript or CSS data through a filter, caching the filtered result for future calls.
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their contents
Definition database.txt:9
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition design.txt:26
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition hooks.txt:179
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:2780
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory Example

Return an array containing values from all significant properties of this module's definition.

Be careful not to normalise too much. Especially preserve the order of things that carry significance in getScript and getStyles (T39812).

Avoid including things that are insiginificant (e.g. order of message keys is insignificant and should be sorted to avoid unnecessary cache invalidation).

This data structure must exclusively contain arrays and scalars as values (avoid object instances) to allow simple serialisation using json_encode.

If modules have a hash or timestamp from another source, that may be incuded as-is.

A number of utility methods are available to help you gather data. These are not called by default and must be included by the subclass' getDefinitionSummary().

Since
1.23
Parameters
ResourceLoaderContext$context
Returns
array|null

Reimplemented from ResourceLoaderModule.

Definition at line 64 of file CiteDataModule.php.

References $context, and getScript().

◆ getDependencies()

CiteDataModule::getDependencies ( ResourceLoaderContext $context = null)

Get a list of modules this module depends on.

Dependency information is taken into account when loading a module on the client side.

Note: It is expected that $context will be made non-optional in the near future.

Parameters
ResourceLoaderContext$context
Returns
array List of module names as strings

Reimplemented from ResourceLoaderModule.

Definition at line 57 of file CiteDataModule.php.

◆ getScript()

CiteDataModule::getScript ( ResourceLoaderContext $context)

Get all JS for this module for a given language and skin.

Includes all relevant JS except loader scripts.

Parameters
ResourceLoaderContext$context
Returns
string JavaScript code

Reimplemented from ResourceLoaderModule.

Definition at line 22 of file CiteDataModule.php.

References $context, and ResourceLoader\inDebugMode().

Referenced by getDefinitionSummary().

Member Data Documentation

◆ $origin

CiteDataModule::$origin = self::ORIGIN_USER_SITEWIDE
protected

Definition at line 17 of file CiteDataModule.php.

◆ $targets

CiteDataModule::$targets = [ 'desktop', 'mobile' ]
protected

Definition at line 18 of file CiteDataModule.php.


The documentation for this class was generated from the following file: