MediaWiki REL1_37
ResourceLoaderContext Class Reference

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

Inheritance diagram for ResourceLoaderContext:
Collaboration diagram for ResourceLoaderContext:

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 ResourceLoaderImage object.
 
 getLanguage ()
 
 getLogger ()
 
 getModules ()
 
 getOnly ()
 
 getRaw ()
 
 getReqBase ()
 Get the request base parameters, omitting any defaults.
 
 getRequest ()
 
 getResourceLoader ()
 
 getSkin ()
 
 getUser ()
 
 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 ResourceLoaderContext 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
 
 $direction
 
 $format
 
 $hash
 
 $image
 
ResourceLoaderImage false $imageObj
 
 $language
 
 $logger
 
 $modules
 
 $only
 
 $raw
 
 $request
 
 $resourceLoader
 
 $skin
 
 $user
 
 $userObj
 
 $variant
 
 $version
 

Private Attributes

const DEBUG_MAIN = 2
 

Detailed Description

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

Passed around to ResourceLoaderModule methods.

Since
1.17

Definition at line 34 of file ResourceLoaderContext.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoaderContext::__construct ( ResourceLoader  $resourceLoader,
WebRequest  $request 
)

Member Function Documentation

◆ debugFromString()

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

Definition at line 115 of file ResourceLoaderContext.php.

◆ encodeJson()

ResourceLoaderContext::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 432 of file ResourceLoaderContext.php.

Referenced by ResourceLoaderModule\getDeprecationInformation(), ResourceLoaderLanguageDataModule\getScript(), ResourceLoaderUserDefaultsModule\getScript(), ResourceLoaderUserOptionsModule\getScript(), ResourceLoaderClientHtml\makeLoad(), ResourceLoader\makeModuleResponse(), and ResourceLoader\respond().

◆ getConfig()

ResourceLoaderContext::getConfig ( )
Deprecated:
since 1.34 Use ResourceLoaderModule::getConfig instead inside module methods. Use ResourceLoader::getConfig elsewhere.
Returns
Config

Definition at line 160 of file ResourceLoaderContext.php.

References wfDeprecated().

◆ getContentOverrideCallback()

ResourceLoaderContext::getContentOverrideCallback ( )

Return the replaced-content mapping callback.

When editing a page that's used to generate the scripts or styles of a ResourceLoaderWikiModule, 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 DerivativeResourceLoaderContext.

Definition at line 357 of file ResourceLoaderContext.php.

Referenced by ResourceLoaderWikiModule\getContentObj(), ResourceLoaderWikiModule\getTitleInfo(), and ResourceLoaderWikiModule\shouldEmbedModule().

◆ getDebug()

◆ getDirection()

ResourceLoaderContext::getDirection ( )

◆ getFormat()

ResourceLoaderContext::getFormat ( )
Returns
string|null

Definition at line 306 of file ResourceLoaderContext.php.

Referenced by ResourceLoaderImage\getImageData().

◆ getHash()

ResourceLoaderContext::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 reponse output.

Returns
string

Definition at line 384 of file ResourceLoaderContext.php.

Referenced by ResourceLoaderFileModule\expandPackageFiles(), ResourceLoaderModule\getModuleContent(), ResourceLoaderFileModule\getPackageFiles(), ResourceLoaderModule\getVersionHash(), and ResourceFileCache\newFromContext().

◆ getImage()

ResourceLoaderContext::getImage ( )
Returns
string|null

Definition at line 292 of file ResourceLoaderContext.php.

Referenced by ResourceFileCache\newFromContext().

◆ getImageObj()

ResourceLoaderContext::getImageObj ( )

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

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

Definition at line 316 of file ResourceLoaderContext.php.

References $modules.

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

◆ getLanguage()

◆ getLogger()

ResourceLoaderContext::getLogger ( )
Deprecated:
since 1.34 Use ResourceLoaderModule::getLogger instead inside module methods. Use ResourceLoader::getLogger elsewhere.
Since
1.27
Returns
\Psr\Log\LoggerInterface

Definition at line 175 of file ResourceLoaderContext.php.

◆ getModules()

ResourceLoaderContext::getModules ( )

◆ getOnly()

ResourceLoaderContext::getOnly ( )

◆ getRaw()

ResourceLoaderContext::getRaw ( )

Reimplemented in DerivativeResourceLoaderContext.

Definition at line 285 of file ResourceLoaderContext.php.

Referenced by ResourceLoader\makeModuleResponse().

◆ getReqBase()

ResourceLoaderContext::getReqBase ( )

Get the request base parameters, omitting any defaults.

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

Definition at line 410 of file ResourceLoaderContext.php.

◆ getRequest()

◆ getResourceLoader()

◆ getSkin()

◆ getUser()

ResourceLoaderContext::getUser ( )
Returns
string|null

Reimplemented in DerivativeResourceLoaderContext.

Definition at line 222 of file ResourceLoaderContext.php.

◆ getUserObj()

ResourceLoaderContext::getUserObj ( )

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

Since
1.25
Returns
User

Reimplemented in DerivativeResourceLoaderContext.

Definition at line 250 of file ResourceLoaderContext.php.

References User\newFromName().

Referenced by ResourceLoaderUserModule\getPages(), ResourceLoaderUserStylesModule\getPages(), and ResourceLoaderUserOptionsModule\getScript().

◆ getVariant()

ResourceLoaderContext::getVariant ( )
Returns
string|null

Definition at line 299 of file ResourceLoaderContext.php.

Referenced by ResourceLoaderImage\getImageData().

◆ getVersion()

ResourceLoaderContext::getVersion ( )

◆ msg()

ResourceLoaderContext::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 235 of file ResourceLoaderContext.php.

Referenced by ChangesListSpecialPage\getChangeTagList().

◆ newDummyContext()

static ResourceLoaderContext::newDummyContext ( )
static

Return a dummy ResourceLoaderContext 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
ResourceLoaderContext

Definition at line 138 of file ResourceLoaderContext.php.

◆ shouldIncludeMessages()

ResourceLoaderContext::shouldIncludeMessages ( )

Definition at line 369 of file ResourceLoaderContext.php.

◆ shouldIncludeScripts()

ResourceLoaderContext::shouldIncludeScripts ( )

◆ shouldIncludeStyles()

ResourceLoaderContext::shouldIncludeStyles ( )

Definition at line 365 of file ResourceLoaderContext.php.

Member Data Documentation

◆ $debug

int ResourceLoaderContext::$debug
protected

Definition at line 52 of file ResourceLoaderContext.php.

◆ $direction

ResourceLoaderContext::$direction
protected

Definition at line 64 of file ResourceLoaderContext.php.

◆ $format

ResourceLoaderContext::$format
protected

Definition at line 62 of file ResourceLoaderContext.php.

◆ $hash

ResourceLoaderContext::$hash
protected

Definition at line 65 of file ResourceLoaderContext.php.

◆ $image

ResourceLoaderContext::$image
protected

Definition at line 60 of file ResourceLoaderContext.php.

◆ $imageObj

ResourceLoaderImage false ResourceLoaderContext::$imageObj
protected

Definition at line 68 of file ResourceLoaderContext.php.

◆ $language

ResourceLoaderContext::$language
protected

Definition at line 50 of file ResourceLoaderContext.php.

◆ $logger

ResourceLoaderContext::$logger
protected

Definition at line 46 of file ResourceLoaderContext.php.

◆ $modules

ResourceLoaderContext::$modules
protected

Definition at line 56 of file ResourceLoaderContext.php.

◆ $only

ResourceLoaderContext::$only
protected

Definition at line 57 of file ResourceLoaderContext.php.

◆ $raw

ResourceLoaderContext::$raw
protected

Definition at line 59 of file ResourceLoaderContext.php.

◆ $request

ResourceLoaderContext::$request
protected

Definition at line 45 of file ResourceLoaderContext.php.

◆ $resourceLoader

ResourceLoaderContext::$resourceLoader
protected

Definition at line 44 of file ResourceLoaderContext.php.

◆ $skin

ResourceLoaderContext::$skin
protected

Definition at line 49 of file ResourceLoaderContext.php.

◆ $user

ResourceLoaderContext::$user
protected

Definition at line 53 of file ResourceLoaderContext.php.

◆ $userObj

ResourceLoaderContext::$userObj
protected

Definition at line 66 of file ResourceLoaderContext.php.

◆ $variant

ResourceLoaderContext::$variant
protected

Definition at line 61 of file ResourceLoaderContext.php.

◆ $version

ResourceLoaderContext::$version
protected

Definition at line 58 of file ResourceLoaderContext.php.

◆ DEBUG_LEGACY

const ResourceLoaderContext::DEBUG_LEGACY = 1
Access: internal
For use in ResourceLoader classes.

Definition at line 41 of file ResourceLoaderContext.php.

◆ DEBUG_MAIN

const ResourceLoaderContext::DEBUG_MAIN = 2
private

Definition at line 42 of file ResourceLoaderContext.php.

◆ DEBUG_OFF

const ResourceLoaderContext::DEBUG_OFF = 0
Access: internal
For use in ResourceLoader classes.

Definition at line 39 of file ResourceLoaderContext.php.

◆ DEFAULT_LANG

const ResourceLoaderContext::DEFAULT_LANG = 'qqx'

Definition at line 35 of file ResourceLoaderContext.php.

◆ DEFAULT_SKIN

const ResourceLoaderContext::DEFAULT_SKIN = 'fallback'

Definition at line 36 of file ResourceLoaderContext.php.


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