MediaWiki master
MediaWiki\ResourceLoader\Context Class Reference

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

Inherits MediaWiki\Language\LocalizationContext.

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 ()
 
 getLanguageCode ()
 Returns the target language for UI localization.
Returns
Bcp47Code

 
 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_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 35 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 139 of file Context.php.

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 464 of file Context.php.

Referenced by 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 388 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 337 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 413 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 329 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 347 of file Context.php.

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

◆ getLanguage()

◆ getLanguageCode()

MediaWiki\ResourceLoader\Context::getLanguageCode ( )

Returns the target language for UI localization.

Returns
Bcp47Code

Implements MediaWiki\Language\LocalizationContext.

Definition at line 211 of file Context.php.

◆ 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 184 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 439 of file Context.php.

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

◆ getRequest()

◆ getResourceLoader()

◆ getSkin()

◆ getUser()

MediaWiki\ResourceLoader\Context::getUser ( )

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

Definition at line 228 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 263 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 285 of file Context.php.

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

◆ getVariant()

MediaWiki\ResourceLoader\Context::getVariant ( )

Definition at line 333 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 313 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.
MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float>...$params See Message::params()
Returns
Message

Implements MediaWiki\Language\MessageLocalizer.

Definition at line 243 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 158 of file Context.php.

◆ shouldIncludeMessages()

MediaWiki\ResourceLoader\Context::shouldIncludeMessages ( )

Definition at line 400 of file Context.php.

◆ shouldIncludeScripts()

MediaWiki\ResourceLoader\Context::shouldIncludeScripts ( )

◆ shouldIncludeStyles()

MediaWiki\ResourceLoader\Context::shouldIncludeStyles ( )

Definition at line 396 of file Context.php.

Member Data Documentation

◆ $debug

int MediaWiki\ResourceLoader\Context::$debug
protected

Definition at line 56 of file Context.php.

◆ $direction

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

Definition at line 79 of file Context.php.

◆ $format

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

Definition at line 76 of file Context.php.

◆ $hash

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

Definition at line 81 of file Context.php.

◆ $image

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

Definition at line 72 of file Context.php.

◆ $imageObj

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

Definition at line 87 of file Context.php.

◆ $language

string MediaWiki\ResourceLoader\Context::$language
protected

Definition at line 54 of file Context.php.

◆ $logger

LoggerInterface MediaWiki\ResourceLoader\Context::$logger
protected

Definition at line 48 of file Context.php.

◆ $modules

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

Definition at line 62 of file Context.php.

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

◆ $only

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

Definition at line 64 of file Context.php.

◆ $raw

bool MediaWiki\ResourceLoader\Context::$raw
protected

Definition at line 68 of file Context.php.

◆ $request

WebRequest MediaWiki\ResourceLoader\Context::$request
protected

Definition at line 46 of file Context.php.

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

◆ $resourceLoader

ResourceLoader MediaWiki\ResourceLoader\Context::$resourceLoader
protected

Definition at line 44 of file Context.php.

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

◆ $skin

string MediaWiki\ResourceLoader\Context::$skin
protected

Definition at line 52 of file Context.php.

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

◆ $sourcemap

bool MediaWiki\ResourceLoader\Context::$sourcemap
protected

Definition at line 70 of file Context.php.

◆ $user

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

Definition at line 58 of file Context.php.

◆ $userIdentity

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

Definition at line 85 of file Context.php.

◆ $userObj

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

Definition at line 83 of file Context.php.

◆ $variant

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

Definition at line 74 of file Context.php.

◆ $version

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

Definition at line 66 of file Context.php.

◆ DEBUG_OFF

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

Definition at line 40 of file Context.php.

◆ DEFAULT_LANG

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

Definition at line 36 of file Context.php.

◆ DEFAULT_SKIN

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

Definition at line 37 of file Context.php.

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


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