MediaWiki REL1_37
ResourceLoaderClientHtml Class Reference

Load and configure a ResourceLoader client on an HTML page. More...

Collaboration diagram for ResourceLoaderClientHtml:

Public Member Functions

 __construct (ResourceLoaderContext $context, array $options=[])
 
 getBodyHtml ()
 
 getDocumentAttributes ()
 
 getHeadHtml ( $nojsClass=null)
 The order of elements in the head is as follows:
 
 setConfig (array $vars)
 Set mw.config variables.
 
 setExemptStates (array $states)
 Set state of special modules that are handled by the caller manually.
 
 setModules (array $modules)
 Ensure one or more modules are loaded.
 
 setModuleStyles (array $modules)
 Ensure the styles of one or more modules are loaded.
 

Static Public Member Functions

static makeLoad (ResourceLoaderContext $mainContext, array $modules, $only, array $extraQuery=[], $nonce=null)
 Explicitly load or embed modules on a page.
 

Private Member Functions

 getContext ( $group, $type)
 
 getData ()
 
 getLoad ( $modules, $only, $nonce, array $extraQuery=[])
 

Static Private Member Functions

static makeContext (ResourceLoaderContext $mainContext, $group, $type, array $extraQuery=[])
 

Private Attributes

array< string, mixed > $config = []
 
ResourceLoaderContext $context
 
array $data
 
array< string, string > $exemptStates = []
 
string[] $modules = []
 
string[] $moduleStyles = []
 
array< string, string|null|false > $options
 
ResourceLoader $resourceLoader
 

Detailed Description

Load and configure a ResourceLoader client on an HTML page.

Since
1.28

Definition at line 30 of file ResourceLoaderClientHtml.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoaderClientHtml::__construct ( ResourceLoaderContext  $context,
array  $options = [] 
)
Parameters
ResourceLoaderContext$context
array$options[optional] Array of options

Definition at line 62 of file ResourceLoaderClientHtml.php.

References $context, $options, and ResourceLoaderContext\getResourceLoader().

Member Function Documentation

◆ getBodyHtml()

ResourceLoaderClientHtml::getBodyHtml ( )
Returns
string|WrappedStringList HTML

Definition at line 337 of file ResourceLoaderClientHtml.php.

References ResourceLoader\makeInlineScript().

◆ getContext()

ResourceLoaderClientHtml::getContext (   $group,
  $type 
)
private

Definition at line 352 of file ResourceLoaderClientHtml.php.

◆ getData()

ResourceLoaderClientHtml::getData ( )
private

Definition at line 112 of file ResourceLoaderClientHtml.php.

◆ getDocumentAttributes()

ResourceLoaderClientHtml::getDocumentAttributes ( )
Returns
array<string,string> Attributes pairs for the HTML document element

Definition at line 224 of file ResourceLoaderClientHtml.php.

◆ getHeadHtml()

ResourceLoaderClientHtml::getHeadHtml (   $nojsClass = null)

The order of elements in the head is as follows:

  • Inline scripts.
  • Stylesheets.
  • Async external script-src.

Reasons:

  • Script execution may be blocked on preceding stylesheets.
  • Async scripts are not blocked on stylesheets.
  • Inline scripts can't be asynchronous.
  • For styles, earlier is better.
Parameters
string | null$nojsClassClass name that caller uses on HTML document element
Returns
string|WrappedStringList HTML

Definition at line 243 of file ResourceLoaderClientHtml.php.

References ResourceLoader\filter().

◆ getLoad()

ResourceLoaderClientHtml::getLoad (   $modules,
  $only,
  $nonce,
array  $extraQuery = [] 
)
private

Definition at line 356 of file ResourceLoaderClientHtml.php.

References $modules.

◆ makeContext()

static ResourceLoaderClientHtml::makeContext ( ResourceLoaderContext  $mainContext,
  $group,
  $type,
array  $extraQuery = [] 
)
staticprivate

Definition at line 360 of file ResourceLoaderClientHtml.php.

◆ makeLoad()

static ResourceLoaderClientHtml::makeLoad ( ResourceLoaderContext  $mainContext,
array  $modules,
  $only,
array  $extraQuery = [],
  $nonce = null 
)
static

Explicitly load or embed modules on a page.

Parameters
ResourceLoaderContext$mainContext
string[]$modulesOne or more module names
string$onlyResourceLoaderModule TYPE_ class constant
array$extraQuery[optional] Array with extra query parameters for the request
string | null$nonce[optional] Content-Security-Policy nonce (from OutputPage->getCSP->getNonce())
Returns
string|WrappedStringList HTML

Definition at line 388 of file ResourceLoaderClientHtml.php.

References $modules, $source, ResourceLoaderContext\encodeJson(), ResourceLoaderContext\getDebug(), ResourceLoaderContext\getResourceLoader(), and ResourceLoader\makeInlineScript().

Referenced by OutputPage\makeResourceLoaderLink().

◆ setConfig()

ResourceLoaderClientHtml::setConfig ( array  $vars)

Set mw.config variables.

Parameters
array$varsArray of key/value pairs

Definition at line 77 of file ResourceLoaderClientHtml.php.

Referenced by OutputPage\getRlClient().

◆ setExemptStates()

ResourceLoaderClientHtml::setExemptStates ( array  $states)

Set state of special modules that are handled by the caller manually.

See OutputPage::buildExemptModules() for use cases.

Parameters
array<string,string>$states Module state keyed by module name

Definition at line 108 of file ResourceLoaderClientHtml.php.

◆ setModules()

ResourceLoaderClientHtml::setModules ( array  $modules)

Ensure one or more modules are loaded.

Parameters
string[]$modulesArray of module names

Definition at line 88 of file ResourceLoaderClientHtml.php.

◆ setModuleStyles()

ResourceLoaderClientHtml::setModuleStyles ( array  $modules)

Ensure the styles of one or more modules are loaded.

Parameters
string[]$modulesArray of module names

Definition at line 97 of file ResourceLoaderClientHtml.php.

Member Data Documentation

◆ $config

array<string,mixed> ResourceLoaderClientHtml::$config = []
private

Definition at line 41 of file ResourceLoaderClientHtml.php.

◆ $context

ResourceLoaderContext ResourceLoaderClientHtml::$context
private

Definition at line 32 of file ResourceLoaderClientHtml.php.

Referenced by __construct().

◆ $data

array ResourceLoaderClientHtml::$data
private

Definition at line 53 of file ResourceLoaderClientHtml.php.

◆ $exemptStates

array<string,string> ResourceLoaderClientHtml::$exemptStates = []
private

Definition at line 50 of file ResourceLoaderClientHtml.php.

◆ $modules

string [] ResourceLoaderClientHtml::$modules = []
private

Definition at line 44 of file ResourceLoaderClientHtml.php.

◆ $moduleStyles

string [] ResourceLoaderClientHtml::$moduleStyles = []
private

Definition at line 47 of file ResourceLoaderClientHtml.php.

◆ $options

array<string,string|null|false> ResourceLoaderClientHtml::$options
private

Definition at line 38 of file ResourceLoaderClientHtml.php.

Referenced by __construct().

◆ $resourceLoader

ResourceLoader ResourceLoaderClientHtml::$resourceLoader
private

Definition at line 35 of file ResourceLoaderClientHtml.php.


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