MediaWiki REL1_28
ResourceLoaderImageModule Class Reference

ResourceLoader module for generated and embedded images. More...

Inheritance diagram for ResourceLoaderImageModule:
Collaboration diagram for ResourceLoaderImageModule:

Public Member Functions

 __construct ( $options=[], $localBasePath=null)
 Constructs a new module from an options array.
 
 getDefinitionSummary (ResourceLoaderContext $context)
 Get the definition summary for this module.
 
 getGlobalVariants (ResourceLoaderContext $context)
 Get list of variants in this module that are 'global', i.e., available for every image regardless of image options.
 
 getImage ( $name, ResourceLoaderContext $context)
 Get a ResourceLoaderImage object for given image.
 
 getImages (ResourceLoaderContext $context)
 Get ResourceLoaderImage objects for all images.
 
 getPosition ()
 
 getPrefix ()
 Get CSS class prefix used by this module.
 
 getSelectors ()
 Get CSS selector templates used by this module.
 
 getStyles (ResourceLoaderContext $context)
 
 getType ()
 
 supportsURLLoading ()
 
- Public Member Functions inherited from ResourceLoaderModule
 enableModuleContentVersion ()
 Whether to generate version hash based on module content.
 
 getConfig ()
 
 getDefinitionMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime().
 
 getDependencies (ResourceLoaderContext $context=null)
 Get a list of modules this module depends on.
 
 getFlip ( $context)
 
 getGroup ()
 Get the group this module is in.
 
 getHashMtime (ResourceLoaderContext $context)
 Back-compat dummy for old subclass implementations of getModifiedTime().
 
 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.
 
 getModuleContent (ResourceLoaderContext $context)
 Get an array of this module's resources.
 
 getName ()
 Get this module's name.
 
 getOrigin ()
 Get this module's origin.
 
 getScript (ResourceLoaderContext $context)
 Get all JS for this module for a given language and skin.
 
 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.
 
 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.
 
 getVersionHash (ResourceLoaderContext $context)
 Get a string identifying the current version of this module in a given context.
 
 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.
 

Static Public Member Functions

static extractLocalBasePath ( $options, $localBasePath=null)
 Extract a local base path from module definition information.
 
- 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.
 

Protected Member Functions

 getCssDeclarations ( $primary, $fallback)
 SVG support using a transparent gradient to guarantee cross-browser compatibility (browsers able to understand gradient syntax support also SVG).
 
 getFileHashes (ResourceLoaderContext $context)
 Helper method for getDefinitionSummary.
 
 loadFromDefinition ()
 Parse definition and external JSON data, if referenced.
 
- Protected Member Functions inherited from ResourceLoaderModule
 buildContent (ResourceLoaderContext $context)
 Bundle all resources attached to this module into an array.
 
 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.
 
 getLessVars (ResourceLoaderContext $context)
 Get module-specific LESS variables, if any.
 
 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.
 

Protected Attributes

 $definition = null
 
 $images = []
 
string $localBasePath = ''
 Local base path, see __construct()
 
 $origin = self::ORIGIN_CORE_SITEWIDE
 
string $position = 'bottom'
 Position on the page to load this module at.
 
 $prefix = null
 
 $selectorWithoutVariant = '.{prefix}-{name}'
 
 $selectorWithVariant = '.{prefix}-{name}-{variant}'
 
 $targets = [ 'desktop', 'mobile' ]
 
 $variants = []
 
- 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

- 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'
 
- 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

ResourceLoader module for generated and embedded images.

Since
1.25

Definition at line 29 of file ResourceLoaderImageModule.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoaderImageModule::__construct (   $options = [],
  $localBasePath = null 
)

Constructs a new module from an options array.

Parameters
array$optionsList of options; if not given or empty, an empty module will be constructed
string$localBasePathBase path to prepend to all local paths in $options. Defaults to $IP

Below is a description for the $options array:

Construction options:
[
// Base path to prepend to all local paths in $options. Defaults to $IP
'localBasePath' => [base path],
// Path to JSON file that contains any of the settings below
'data' => [file path string]
// CSS class prefix to use in all style rules
'prefix' => [CSS class prefix],
// Alternatively: Format of CSS selector to use in all style rules
'selector' => [CSS selector template, variables: {prefix} {name} {variant}],
// Alternatively: When using variants
'selectorWithoutVariant' => [CSS selector template, variables: {prefix} {name}],
'selectorWithVariant' => [CSS selector template, variables: {prefix} {name} {variant}],
// List of variants that may be used for the image files
'variants' => [
[theme name] => [
[variant name] => [
'color' => [color string, e.g. '#ffff00'],
'global' => [boolean, if true, this variant is available
for all images of this type],
],
...
],
...
],
// List of image files and their options
'images' => [
[theme name] => [
[icon name] => [
'file' => [file path string or array whose values are file path strings
and whose keys are 'default', 'ltr', 'rtl', a single
language code like 'en', or a list of language codes like
'en,de,ar'],
'variants' => [array of variant name strings, variants
available for this image],
],
...
],
...
],
]
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
in the sidebar</td >< td > font color
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types are
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
For a write use something like
Definition database.txt:28
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
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition design.txt:12
it sets a lot of them automatically from query strings
Definition design.txt:93
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
database rows
Definition globals.txt:10
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of or an object and a method hook function The function part of a third party developers and local administrators to define code that will be run at certain points in the mainline code
Definition hooks.txt:28
the array() calling protocol came about after MediaWiki 1.4rc1.
in this case you re responsible for computing and outputting the entire conflict i e
Definition hooks.txt:1379
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:181
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:183
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
Definition hooks.txt:108
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN boolean columns are always mapped to as the code does not always treat the column as a boolean(which is limited to accepting true, false, 0, 1, t, or f) *The default data type for all VARCHAR
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36
Exceptions
InvalidArgumentException

Definition at line 105 of file ResourceLoaderImageModule.php.

References $localBasePath, $options, definition, and extractLocalBasePath().

Member Function Documentation

◆ extractLocalBasePath()

static ResourceLoaderImageModule::extractLocalBasePath (   $options,
  $localBasePath = null 
)
static

Extract a local base path from module definition information.

Parameters
array$optionsModule definition
string$localBasePathPath to use if not provided in module definition. Defaults to $IP
Returns
string Local base path

Definition at line 437 of file ResourceLoaderImageModule.php.

References $IP, $localBasePath, $options, global, and string.

Referenced by __construct().

◆ getCssDeclarations()

ResourceLoaderImageModule::getCssDeclarations (   $primary,
  $fallback 
)
protected

SVG support using a transparent gradient to guarantee cross-browser compatibility (browsers able to understand gradient syntax support also SVG).

http://pauginer.tumblr.com/post/36614680636/invisible-gradient-technique

Keep synchronized with the .background-image-svg LESS mixin in /resources/src/mediawiki.less/mediawiki.mixins.less.

Parameters
string$primaryPrimary URI
string$fallbackFallback URI
Returns
string[] CSS declarations to use given URIs as background-image

Reimplemented in ResourceLoaderImageModuleTestable.

Definition at line 371 of file ResourceLoaderImageModule.php.

Referenced by getStyles().

◆ getDefinitionSummary()

ResourceLoaderImageModule::getDefinitionSummary ( ResourceLoaderContext  $context)

Get the definition summary for this module.

Parameters
ResourceLoaderContext$context
Returns
array

Reimplemented from ResourceLoaderModule.

Definition at line 393 of file ResourceLoaderImageModule.php.

References $context, $options, $summary, as, getFileHashes(), and loadFromDefinition().

◆ getFileHashes()

ResourceLoaderImageModule::getFileHashes ( ResourceLoaderContext  $context)
protected

Helper method for getDefinitionSummary.

Definition at line 419 of file ResourceLoaderImageModule.php.

References $context, $files, $image, ResourceLoaderModule\$name, as, getImages(), and loadFromDefinition().

Referenced by getDefinitionSummary().

◆ getGlobalVariants()

ResourceLoaderImageModule::getGlobalVariants ( ResourceLoaderContext  $context)

Get list of variants in this module that are 'global', i.e., available for every image regardless of image options.

Parameters
ResourceLoaderContext$context
Returns
string[]

Definition at line 286 of file ResourceLoaderImageModule.php.

References ResourceLoaderModule\$config, $context, ResourceLoaderModule\$name, $skin, as, and loadFromDefinition().

Referenced by getImages().

◆ getImage()

ResourceLoaderImageModule::getImage (   $name,
ResourceLoaderContext  $context 
)

Get a ResourceLoaderImage object for given image.

Parameters
string$nameImage name
ResourceLoaderContext$context
Returns
ResourceLoaderImage|null

Definition at line 226 of file ResourceLoaderImageModule.php.

References $images, ResourceLoaderModule\$name, getImages(), and loadFromDefinition().

◆ getImages()

ResourceLoaderImageModule::getImages ( ResourceLoaderContext  $context)

Get ResourceLoaderImage objects for all images.

Parameters
ResourceLoaderContext$context
Returns
ResourceLoaderImage[] Array keyed by image name

Definition at line 237 of file ResourceLoaderImageModule.php.

References $context, $image, ResourceLoaderModule\$name, $options, $skin, as, getGlobalVariants(), ResourceLoaderModule\getName(), and loadFromDefinition().

Referenced by getFileHashes(), getImage(), and getStyles().

◆ getPosition()

ResourceLoaderImageModule::getPosition ( )
Returns
string

Reimplemented from ResourceLoaderModule.

Definition at line 454 of file ResourceLoaderImageModule.php.

References $position, and loadFromDefinition().

◆ getPrefix()

ResourceLoaderImageModule::getPrefix ( )

Get CSS class prefix used by this module.

Returns
string

Definition at line 203 of file ResourceLoaderImageModule.php.

References $prefix, and loadFromDefinition().

Referenced by getStyles().

◆ getSelectors()

ResourceLoaderImageModule::getSelectors ( )

Get CSS selector templates used by this module.

Returns
string

Definition at line 212 of file ResourceLoaderImageModule.php.

References $selectorWithoutVariant, $selectorWithVariant, and loadFromDefinition().

Referenced by getStyles().

◆ getStyles()

ResourceLoaderImageModule::getStyles ( ResourceLoaderContext  $context)

◆ getType()

ResourceLoaderImageModule::getType ( )
Returns
string

Reimplemented from ResourceLoaderModule.

Definition at line 462 of file ResourceLoaderImageModule.php.

References ResourceLoaderModule\LOAD_STYLES.

◆ loadFromDefinition()

ResourceLoaderImageModule::loadFromDefinition ( )
protected

◆ supportsURLLoading()

ResourceLoaderImageModule::supportsURLLoading ( )
Returns
bool

Reimplemented from ResourceLoaderModule.

Definition at line 383 of file ResourceLoaderImageModule.php.

Member Data Documentation

◆ $definition

ResourceLoaderImageModule::$definition = null
protected

◆ $images

ResourceLoaderImageModule::$images = []
protected

Definition at line 41 of file ResourceLoaderImageModule.php.

Referenced by getImage().

◆ $localBasePath

string ResourceLoaderImageModule::$localBasePath = ''
protected

Local base path, see __construct()

Definition at line 37 of file ResourceLoaderImageModule.php.

Referenced by __construct(), and extractLocalBasePath().

◆ $origin

ResourceLoaderImageModule::$origin = self::ORIGIN_CORE_SITEWIDE
protected

Definition at line 39 of file ResourceLoaderImageModule.php.

◆ $position

string ResourceLoaderImageModule::$position = 'bottom'
protected

Position on the page to load this module at.

Definition at line 49 of file ResourceLoaderImageModule.php.

Referenced by getPosition().

◆ $prefix

ResourceLoaderImageModule::$prefix = null
protected

Definition at line 43 of file ResourceLoaderImageModule.php.

Referenced by getPrefix(), and loadFromDefinition().

◆ $selectorWithoutVariant

ResourceLoaderImageModule::$selectorWithoutVariant = '.{prefix}-{name}'
protected

Definition at line 44 of file ResourceLoaderImageModule.php.

Referenced by getSelectors(), and loadFromDefinition().

◆ $selectorWithVariant

ResourceLoaderImageModule::$selectorWithVariant = '.{prefix}-{name}-{variant}'
protected

Definition at line 45 of file ResourceLoaderImageModule.php.

Referenced by getSelectors(), and loadFromDefinition().

◆ $targets

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

Definition at line 46 of file ResourceLoaderImageModule.php.

◆ $variants

ResourceLoaderImageModule::$variants = []
protected

Definition at line 42 of file ResourceLoaderImageModule.php.


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