MediaWiki  master
ResourceLoaderClientHtml Class Reference

Bootstrap a ResourceLoader client on an HTML page. More...

Collaboration diagram for ResourceLoaderClientHtml:

Public Member Functions

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

Static Public Member Functions

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

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 $config = []
 
ResourceLoaderContext $context
 
array $data
 
array $exemptStates = []
 
array $modules = []
 
array $moduleScripts = []
 
array $moduleStyles = []
 
array $options
 
ResourceLoader $resourceLoader
 

Detailed Description

Bootstrap a ResourceLoader client on an HTML page.

Since
1.28

Definition at line 29 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 65 of file ResourceLoaderClientHtml.php.

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

Member Function Documentation

◆ getBodyHtml()

ResourceLoaderClientHtml::getBodyHtml ( )
Returns
string|WrappedStringList HTML

Definition at line 363 of file ResourceLoaderClientHtml.php.

References getData(), ResourceLoader\makeInlineScript(), and options().

◆ getContext()

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

Definition at line 378 of file ResourceLoaderClientHtml.php.

References $type.

Referenced by getData().

◆ getData()

◆ getDocumentAttributes()

ResourceLoaderClientHtml::getDocumentAttributes ( )
Returns
array Attribute key-value pairs for the HTML document element

Definition at line 246 of file ResourceLoaderClientHtml.php.

◆ getHeadHtml()

ResourceLoaderClientHtml::getHeadHtml ( )

The order of elements in the head is as follows:

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

Reasons:

  • Script execution may be blocked on preceeding stylesheets.
  • Async scripts are not blocked on stylesheets.
  • Inline scripts can't be asynchronous.
  • For styles, earlier is better.
Returns
string|WrappedStringList HTML

Definition at line 264 of file ResourceLoaderClientHtml.php.

References as, ResourceLoader\encodeJsonForScript(), getData(), getLoad(), Html\inlineScript(), ResourceLoader\makeConfigSetScript(), ResourceLoader\makeInlineScript(), ResourceLoader\makeLoaderStateScript(), options(), string, ResourceLoaderModule\TYPE_COMBINED, ResourceLoaderModule\TYPE_SCRIPTS, and ResourceLoaderModule\TYPE_STYLES.

◆ getLoad()

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

Definition at line 382 of file ResourceLoaderClientHtml.php.

References array().

Referenced by getHeadHtml().

◆ makeContext()

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

◆ makeLoad()

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

Explicily load or embed modules on a page.

Parameters
ResourceLoaderContext$mainContext
array$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::getCSPNonce)
Returns
string|WrappedStringList HTML

Definition at line 415 of file ResourceLoaderClientHtml.php.

References $name, $source, as, Html\element(), Xml\encodeJsCall(), ResourceLoaderContext\getDebug(), ResourceLoaderContext\getRaw(), ResourceLoaderContext\getResourceLoader(), Html\inlineStyle(), Html\linkedStyle(), list, ResourceLoader\makeInlineScript(), Html\rawElement(), and ResourceLoaderModule\TYPE_STYLES.

Referenced by OutputPage\headElement(), OutputPage\makeResourceLoaderLink(), and ResourceLoaderClientHtmlTest\testMakeLoad().

◆ setConfig()

ResourceLoaderClientHtml::setConfig ( array  $vars)

Set mw.config variables.

Parameters
array$varsArray of key/value pairs

Definition at line 80 of file ResourceLoaderClientHtml.php.

References $value, and as.

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$statesModule state keyed by module name

Definition at line 121 of file ResourceLoaderClientHtml.php.

Referenced by OutputPage\getRlClient().

◆ setModules()

ResourceLoaderClientHtml::setModules ( array  $modules)

Ensure one or more modules are loaded.

Parameters
array$modulesArray of module names

Definition at line 91 of file ResourceLoaderClientHtml.php.

References $modules.

Referenced by OutputPage\getRlClient().

◆ setModuleScripts()

ResourceLoaderClientHtml::setModuleScripts ( array  $modules)

Ensure the scripts of one or more modules are loaded.

Deprecated:
since 1.28
Parameters
array$modulesArray of module names

Definition at line 110 of file ResourceLoaderClientHtml.php.

References $modules.

Referenced by OutputPage\getRlClient().

◆ setModuleStyles()

ResourceLoaderClientHtml::setModuleStyles ( array  $modules)

Ensure the styles of one or more modules are loaded.

Parameters
array$modulesArray of module names

Definition at line 100 of file ResourceLoaderClientHtml.php.

References $modules.

Referenced by OutputPage\getRlClient().

Member Data Documentation

◆ $config

array 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 56 of file ResourceLoaderClientHtml.php.

Referenced by getData().

◆ $exemptStates

array ResourceLoaderClientHtml::$exemptStates = []
private

Definition at line 53 of file ResourceLoaderClientHtml.php.

◆ $modules

array ResourceLoaderClientHtml::$modules = []
private

Definition at line 44 of file ResourceLoaderClientHtml.php.

Referenced by setModules(), setModuleScripts(), and setModuleStyles().

◆ $moduleScripts

array ResourceLoaderClientHtml::$moduleScripts = []
private

Definition at line 50 of file ResourceLoaderClientHtml.php.

◆ $moduleStyles

array ResourceLoaderClientHtml::$moduleStyles = []
private

Definition at line 47 of file ResourceLoaderClientHtml.php.

◆ $options

array ResourceLoaderClientHtml::$options
private

Definition at line 38 of file ResourceLoaderClientHtml.php.

◆ $resourceLoader

ResourceLoader ResourceLoaderClientHtml::$resourceLoader
private

Definition at line 35 of file ResourceLoaderClientHtml.php.

Referenced by getData().


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