MediaWiki  master
MediaWiki\ResourceLoader\ClientHtml Class Reference

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

Public Member Functions

 __construct (Context $context, array $options=[])
 
 getBodyHtml ()
 
 getDocumentAttributes ()
 
 getHeadHtml ( $nojsClass=null)
 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...
 
 setModuleStyles (array $modules)
 Ensure the styles of one or more modules are loaded. More...
 

Static Public Member Functions

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

Detailed Description

Load and configure a ResourceLoader client on an HTML page.

Since
1.28

Definition at line 33 of file ClientHtml.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\ResourceLoader\ClientHtml::__construct ( Context  $context,
array  $options = [] 
)
Parameters
Context$context
array$options[optional] Array of options
  • 'target': Parameter for modules=startup request, see StartUpModule.
  • 'safemode': Parameter for modules=startup request, see StartUpModule.
  • 'nonce': From OutputPage->getCSP->getNonce().

Definition at line 65 of file ClientHtml.php.

References MediaWiki\ResourceLoader\Context\getResourceLoader().

Member Function Documentation

◆ getBodyHtml()

MediaWiki\ResourceLoader\ClientHtml::getBodyHtml ( )
Returns
string|WrappedStringList HTML

Definition at line 346 of file ClientHtml.php.

◆ getDocumentAttributes()

MediaWiki\ResourceLoader\ClientHtml::getDocumentAttributes ( )
Returns
array<string,string> Attributes pairs for the HTML document element

Definition at line 233 of file ClientHtml.php.

◆ getHeadHtml()

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

References Html\inlineScript().

◆ makeLoad()

static MediaWiki\ResourceLoader\ClientHtml::makeLoad ( Context  $mainContext,
array  $modules,
  $only,
array  $extraQuery = [],
  $nonce = null 
)
static

Explicitly load or embed modules on a page.

Parameters
Context$mainContext
string[]$modulesOne or more module names
string$onlyModule 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 397 of file ClientHtml.php.

References $modules, $source, Html\element(), MediaWiki\ResourceLoader\Context\encodeJson(), MediaWiki\ResourceLoader\Context\getDebug(), MediaWiki\ResourceLoader\Context\getResourceLoader(), Html\inlineStyle(), Html\linkedStyle(), and Html\rawElement().

Referenced by OutputPage\makeResourceLoaderLink().

◆ setConfig()

MediaWiki\ResourceLoader\ClientHtml::setConfig ( array  $vars)

Set mw.config variables.

Parameters
array$varsArray of key/value pairs

Definition at line 80 of file ClientHtml.php.

◆ setExemptStates()

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

◆ setModules()

MediaWiki\ResourceLoader\ClientHtml::setModules ( array  $modules)

Ensure one or more modules are loaded.

Parameters
string[]$modulesArray of module names

Definition at line 91 of file ClientHtml.php.

References $modules.

◆ setModuleStyles()

MediaWiki\ResourceLoader\ClientHtml::setModuleStyles ( array  $modules)

Ensure the styles of one or more modules are loaded.

Parameters
string[]$modulesArray of module names

Definition at line 100 of file ClientHtml.php.


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