MediaWiki master
MediaWiki\ResourceLoader\Context Class Reference

Context object that contains information about the state of a specific ResourceLoader web request. More...

Inherits MessageLocalizer.

Inherited by MediaWiki\ResourceLoader\DerivativeContext.

Collaboration diagram for MediaWiki\ResourceLoader\Context:

Public Member Functions

 __construct (ResourceLoader $resourceLoader, WebRequest $request, $validSkins=null)
 
 encodeJson ( $data)
 Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
 
 getContentOverrideCallback ()
 Return the replaced-content mapping callback.
 
 getDebug ()
 
 getDirection ()
 
 getFormat ()
 
 getHash ()
 All factors that uniquely identify this request, except 'modules'.
 
 getImage ()
 
 getImageObj ()
 If this is a request for an image, get the Image object.
 
 getLanguage ()
 
 getLogger ()
 
 getModules ()
 
 getOnly ()
 
 getRaw ()
 
 getReqBase ()
 Get the request base parameters, omitting any defaults.
 
 getRequest ()
 
 getResourceLoader ()
 
 getSkin ()
 
 getUser ()
 
 getUserIdentity ()
 Get the possibly-cached UserIdentity object for the specified username.
 
 getUserObj ()
 Get the possibly-cached User object for the specified username.
 
 getVariant ()
 
 getVersion ()
 
 isSourceMap ()
 
 msg ( $key,... $params)
 Get a Message object with context set.
 
 shouldIncludeMessages ()
 
 shouldIncludeScripts ()
 
 shouldIncludeStyles ()
 

Static Public Member Functions

static debugFromString (?string $debug)
 
static newDummyContext ()
 Return a dummy Context object suitable for passing into things that don't "really" need a context.
 

Public Attributes

const DEBUG_MAIN = 2
 
const DEBUG_OFF = 0
 
const DEFAULT_LANG = 'qqx'
 
const DEFAULT_SKIN = 'fallback'
 

Protected Attributes

int $debug
 
string null $direction
 
string null $format
 
string null $hash
 
string null $image
 
Image false $imageObj
 
string $language
 
LoggerInterface $logger
 
string[] $modules
 
string null $only
 
bool $raw
 
WebRequest $request
 
ResourceLoader $resourceLoader
 
string $skin
 
bool $sourcemap
 
string null $user
 
UserIdentity null false $userIdentity = false
 
User null $userObj
 
string null $variant
 
string null $version
 

Detailed Description

Context object that contains information about the state of a specific ResourceLoader web request.

Passed around to Module methods.

Since
1.17

Definition at line 46 of file Context.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\ResourceLoader\Context::__construct ( ResourceLoader $resourceLoader,
WebRequest $request,
$validSkins = null )

Member Function Documentation

◆ debugFromString()

static MediaWiki\ResourceLoader\Context::debugFromString ( ?string $debug)
static
Access: internal
For use in ResourceLoader::inDebugMode
Parameters
string | null$debug
Returns
int

Definition at line 151 of file Context.php.

References MediaWiki\ResourceLoader\Context\DEBUG_MAIN.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ encodeJson()

MediaWiki\ResourceLoader\Context::encodeJson ( $data)

Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.

Since
1.34
Parameters
mixed$data
Returns
string|false JSON string, false on error

Definition at line 475 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Module\getDeprecationInformation(), MediaWiki\ResourceLoader\StartUpModule\getScript(), MediaWiki\ResourceLoader\UserOptionsModule\getScript(), MediaWiki\ResourceLoader\ClientHtml\makeLoad(), MediaWiki\ResourceLoader\ResourceLoader\makeModuleResponse(), and MediaWiki\ResourceLoader\ResourceLoader\respond().

◆ getContentOverrideCallback()

MediaWiki\ResourceLoader\Context::getContentOverrideCallback ( )

Return the replaced-content mapping callback.

When editing a page that's used to generate the scripts or styles of a WikiModule, a preview should use the to-be-saved version of the page rather than the current version in the database. A context supporting such previews should return a callback to return these mappings here.

Since
1.32
Returns
callable|null Signature is Content|null func( Title $t )

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 399 of file Context.php.

Referenced by MediaWiki\ResourceLoader\WikiModule\getContentObj(), MediaWiki\ResourceLoader\WikiModule\getTitleInfo(), and MediaWiki\ResourceLoader\WikiModule\shouldEmbedModule().

◆ getDebug()

◆ getDirection()

MediaWiki\ResourceLoader\Context::getDirection ( )

◆ getFormat()

MediaWiki\ResourceLoader\Context::getFormat ( )

Definition at line 348 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Image\getImageData().

◆ getHash()

MediaWiki\ResourceLoader\Context::getHash ( )

All factors that uniquely identify this request, except 'modules'.

The list of modules is excluded here for legacy reasons as most callers already split up handling of individual modules. Including it here would massively fragment the cache and decrease its usefulness.

E.g. Used by RequestFileCache to form a cache key for storing the response output.

Definition at line 424 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Module\getModuleContent(), MediaWiki\ResourceLoader\FileModule\getPackageFiles(), and MediaWiki\ResourceLoader\Module\getVersionHash().

◆ getImage()

MediaWiki\ResourceLoader\Context::getImage ( )

Definition at line 340 of file Context.php.

Referenced by MediaWiki\ResourceLoader\ResourceLoader\respond().

◆ getImageObj()

MediaWiki\ResourceLoader\Context::getImageObj ( )

If this is a request for an image, get the Image object.

Since
1.25
Returns
Image|false false if a valid object cannot be created

Definition at line 358 of file Context.php.

Referenced by MediaWiki\ResourceLoader\ResourceLoader\makeModuleResponse(), and MediaWiki\ResourceLoader\ResourceLoader\respond().

◆ getLanguage()

◆ getLogger()

MediaWiki\ResourceLoader\Context::getLogger ( )
Deprecated
since 1.34 Use Module::getLogger instead inside module methods. Use ResourceLoader::getLogger elsewhere.
Since
1.27
Returns
LoggerInterface

Definition at line 195 of file Context.php.

◆ getModules()

MediaWiki\ResourceLoader\Context::getModules ( )

◆ getOnly()

◆ getRaw()

MediaWiki\ResourceLoader\Context::getRaw ( )

◆ getReqBase()

MediaWiki\ResourceLoader\Context::getReqBase ( )

Get the request base parameters, omitting any defaults.

Access: internal
For use by StartUpModule only
Returns
string[]

Definition at line 450 of file Context.php.

Referenced by MediaWiki\ResourceLoader\StartUpModule\getScript().

◆ getRequest()

MediaWiki\ResourceLoader\Context::getRequest ( )

◆ getResourceLoader()

◆ getSkin()

◆ getUser()

MediaWiki\ResourceLoader\Context::getUser ( )

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 239 of file Context.php.

◆ getUserIdentity()

MediaWiki\ResourceLoader\Context::getUserIdentity ( )

Get the possibly-cached UserIdentity object for the specified username.

This will be null on most requests, except for load.php requests that have a 'user' parameter set.

Since
1.38
Returns
UserIdentity|null

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 274 of file Context.php.

Referenced by MediaWiki\ResourceLoader\UserModule\getPages(), and MediaWiki\ResourceLoader\UserStylesModule\getPages().

◆ getUserObj()

MediaWiki\ResourceLoader\Context::getUserObj ( )

Get the possibly-cached User object for the specified username.

Since
1.25
Returns
User

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 296 of file Context.php.

Referenced by MediaWiki\ResourceLoader\UserOptionsModule\getScript().

◆ getVariant()

MediaWiki\ResourceLoader\Context::getVariant ( )

Definition at line 344 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Image\getImageData().

◆ getVersion()

MediaWiki\ResourceLoader\Context::getVersion ( )
See also
Module::getVersionHash
ClientHtml::makeLoad
Returns
string|null

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 324 of file Context.php.

Referenced by MediaWiki\ResourceLoader\ResourceLoader\respond().

◆ isSourceMap()

MediaWiki\ResourceLoader\Context::isSourceMap ( )

◆ msg()

MediaWiki\ResourceLoader\Context::msg ( $key,
$params )

Get a Message object with context set.

See wfMessage for parameters.

Since
1.27
Parameters
string | string[] | MessageSpecifier$keyMessage key, or array of keys, or a MessageSpecifier. @phpcs:ignore Generic.Files.LineLength
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params See Message::params()
Returns
Message

Implements MessageLocalizer.

Definition at line 254 of file Context.php.

◆ newDummyContext()

static MediaWiki\ResourceLoader\Context::newDummyContext ( )
static

Return a dummy Context object suitable for passing into things that don't "really" need a context.

Use cases:

  • Unit tests (deprecated, create empty instance directly or use RLTestCase).

Definition at line 169 of file Context.php.

◆ shouldIncludeMessages()

MediaWiki\ResourceLoader\Context::shouldIncludeMessages ( )

Definition at line 411 of file Context.php.

◆ shouldIncludeScripts()

MediaWiki\ResourceLoader\Context::shouldIncludeScripts ( )

◆ shouldIncludeStyles()

MediaWiki\ResourceLoader\Context::shouldIncludeStyles ( )

Definition at line 407 of file Context.php.

Member Data Documentation

◆ $debug

int MediaWiki\ResourceLoader\Context::$debug
protected

Definition at line 68 of file Context.php.

◆ $direction

string null MediaWiki\ResourceLoader\Context::$direction
protected

Definition at line 91 of file Context.php.

◆ $format

string null MediaWiki\ResourceLoader\Context::$format
protected

Definition at line 88 of file Context.php.

◆ $hash

string null MediaWiki\ResourceLoader\Context::$hash
protected

Definition at line 93 of file Context.php.

◆ $image

string null MediaWiki\ResourceLoader\Context::$image
protected

Definition at line 84 of file Context.php.

◆ $imageObj

Image false MediaWiki\ResourceLoader\Context::$imageObj
protected

Definition at line 99 of file Context.php.

◆ $language

string MediaWiki\ResourceLoader\Context::$language
protected

Definition at line 66 of file Context.php.

◆ $logger

LoggerInterface MediaWiki\ResourceLoader\Context::$logger
protected

Definition at line 60 of file Context.php.

◆ $modules

string [] MediaWiki\ResourceLoader\Context::$modules
protected

Definition at line 74 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ $only

string null MediaWiki\ResourceLoader\Context::$only
protected

Definition at line 76 of file Context.php.

◆ $raw

bool MediaWiki\ResourceLoader\Context::$raw
protected

Definition at line 80 of file Context.php.

◆ $request

WebRequest MediaWiki\ResourceLoader\Context::$request
protected

Definition at line 58 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ $resourceLoader

ResourceLoader MediaWiki\ResourceLoader\Context::$resourceLoader
protected

Definition at line 56 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ $skin

string MediaWiki\ResourceLoader\Context::$skin
protected

Definition at line 64 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().

◆ $sourcemap

bool MediaWiki\ResourceLoader\Context::$sourcemap
protected

Definition at line 82 of file Context.php.

◆ $user

string null MediaWiki\ResourceLoader\Context::$user
protected

Definition at line 70 of file Context.php.

◆ $userIdentity

UserIdentity null false MediaWiki\ResourceLoader\Context::$userIdentity = false
protected

Definition at line 97 of file Context.php.

◆ $userObj

User null MediaWiki\ResourceLoader\Context::$userObj
protected

Definition at line 95 of file Context.php.

◆ $variant

string null MediaWiki\ResourceLoader\Context::$variant
protected

Definition at line 86 of file Context.php.

◆ $version

string null MediaWiki\ResourceLoader\Context::$version
protected

Definition at line 78 of file Context.php.

◆ DEBUG_MAIN

const MediaWiki\ResourceLoader\Context::DEBUG_MAIN = 2
Access: internal
For use in SpecialJavaScriptTest.

Definition at line 53 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\debugFromString().

◆ DEBUG_OFF

const MediaWiki\ResourceLoader\Context::DEBUG_OFF = 0
Access: internal
For use in ResourceLoader classes.

Definition at line 51 of file Context.php.

◆ DEFAULT_LANG

const MediaWiki\ResourceLoader\Context::DEFAULT_LANG = 'qqx'

Definition at line 47 of file Context.php.

◆ DEFAULT_SKIN

const MediaWiki\ResourceLoader\Context::DEFAULT_SKIN = 'fallback'

Definition at line 48 of file Context.php.

Referenced by MediaWiki\ResourceLoader\Context\__construct().


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