MediaWiki REL1_39
MediaWiki\ResourceLoader\Context Class Reference

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

Inheritance diagram for MediaWiki\ResourceLoader\Context:
Collaboration diagram for MediaWiki\ResourceLoader\Context:

Public Member Functions

 __construct (ResourceLoader $resourceLoader, WebRequest $request)
 
 encodeJson ( $data)
 Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
 
 getConfig ()
 
 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 ()
 
 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_LEGACY = 1
 
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
 
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()

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

References MediaWiki\ResourceLoader\Context\DEBUG_LEGACY.

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

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

◆ getConfig()

MediaWiki\ResourceLoader\Context::getConfig ( )
Deprecated
since 1.34 Use Module::getConfig instead inside module methods. Use ResourceLoader::getConfig elsewhere.
Returns
Config

Definition at line 190 of file Context.php.

References wfDeprecated().

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

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

◆ getDebug()

◆ getDirection()

◆ getFormat()

MediaWiki\ResourceLoader\Context::getFormat ( )
Returns
string|null

Definition at line 364 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.

Returns
string

Definition at line 442 of file Context.php.

References getUser().

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

◆ getImage()

MediaWiki\ResourceLoader\Context::getImage ( )
Returns
string|null

Definition at line 350 of file Context.php.

◆ getImageObj()

MediaWiki\ResourceLoader\Context::getImageObj ( )

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

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

Definition at line 374 of file Context.php.

References $modules.

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

◆ getModules()

MediaWiki\ResourceLoader\Context::getModules ( )

◆ getOnly()

MediaWiki\ResourceLoader\Context::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 468 of file Context.php.

◆ getRequest()

MediaWiki\ResourceLoader\Context::getRequest ( )

◆ getResourceLoader()

◆ getSkin()

◆ getUser()

MediaWiki\ResourceLoader\Context::getUser ( )
Returns
string|null

Reimplemented in MediaWiki\ResourceLoader\DerivativeContext.

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

References getUser().

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

References getUser(), and User\newFromName().

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

◆ getVariant()

MediaWiki\ResourceLoader\Context::getVariant ( )
Returns
string|null

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

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

◆ 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.
mixed...$params
Returns
Message

Implements MessageLocalizer.

Definition at line 266 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).
Returns
Context

Definition at line 168 of file Context.php.

◆ shouldIncludeMessages()

MediaWiki\ResourceLoader\Context::shouldIncludeMessages ( )

Definition at line 427 of file Context.php.

◆ shouldIncludeScripts()

MediaWiki\ResourceLoader\Context::shouldIncludeScripts ( )

◆ shouldIncludeStyles()

MediaWiki\ResourceLoader\Context::shouldIncludeStyles ( )

Definition at line 423 of file Context.php.

Member Data Documentation

◆ $debug

int MediaWiki\ResourceLoader\Context::$debug
protected

Definition at line 69 of file Context.php.

◆ $direction

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

Definition at line 90 of file Context.php.

◆ $format

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

Definition at line 87 of file Context.php.

◆ $hash

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

Definition at line 92 of file Context.php.

◆ $image

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

Definition at line 83 of file Context.php.

◆ $imageObj

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

Definition at line 98 of file Context.php.

◆ $language

string MediaWiki\ResourceLoader\Context::$language
protected

Definition at line 67 of file Context.php.

◆ $logger

LoggerInterface MediaWiki\ResourceLoader\Context::$logger
protected

Definition at line 61 of file Context.php.

◆ $modules

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

Definition at line 75 of file Context.php.

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

◆ $only

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

Definition at line 77 of file Context.php.

◆ $raw

bool MediaWiki\ResourceLoader\Context::$raw
protected

Definition at line 81 of file Context.php.

◆ $request

WebRequest MediaWiki\ResourceLoader\Context::$request
protected

Definition at line 59 of file Context.php.

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

◆ $resourceLoader

ResourceLoader MediaWiki\ResourceLoader\Context::$resourceLoader
protected

Definition at line 57 of file Context.php.

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

◆ $skin

string MediaWiki\ResourceLoader\Context::$skin
protected

Definition at line 65 of file Context.php.

◆ $user

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

Definition at line 71 of file Context.php.

◆ $userIdentity

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

Definition at line 96 of file Context.php.

◆ $userObj

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

Definition at line 94 of file Context.php.

◆ $variant

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

Definition at line 85 of file Context.php.

◆ $version

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

Definition at line 79 of file Context.php.

◆ DEBUG_LEGACY

const MediaWiki\ResourceLoader\Context::DEBUG_LEGACY = 1
Access: internal
For use in ResourceLoader classes.

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: