MediaWiki  1.28.0
ResourceLoaderClientHtml Class Reference

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

Collaboration diagram for ResourceLoaderClientHtml:

Public Member Functions

 __construct (ResourceLoaderContext $context, $target=null)
 
 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=[])
 Explicily load or embed modules on a page. More...
 

Private Member Functions

 getContext ($group, $type)
 
 getData ()
 
 getLoad ($modules, $only, 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 = []
 
ResourceLoader $resourceLoader
 
string null $target
 

Detailed Description

Bootstrap a ResourceLoader client on an HTML page.

Since
1.28

Definition at line 28 of file ResourceLoaderClientHtml.php.

Constructor & Destructor Documentation

ResourceLoaderClientHtml::__construct ( ResourceLoaderContext  $context,
  $target = null 
)
Parameters
ResourceLoaderContext$context
aray$target[optional] Custom 'target' parameter for the startup module

Definition at line 61 of file ResourceLoaderClientHtml.php.

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

Member Function Documentation

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

Definition at line 368 of file ResourceLoaderClientHtml.php.

References $type.

Referenced by getData().

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

Definition at line 239 of file ResourceLoaderClientHtml.php.

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

References $target, Xml\encodeJsCall(), getData(), getLoad(), Html\inlineScript(), ResourceLoader\makeConfigSetScript(), ResourceLoader\makeInlineScript(), ResourceLoader\makeLoaderStateScript(), ResourceLoaderModule\TYPE_COMBINED, ResourceLoaderModule\TYPE_SCRIPTS, and ResourceLoaderModule\TYPE_STYLES.

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

Definition at line 372 of file ResourceLoaderClientHtml.php.

References array().

Referenced by getBodyHtml(), and getHeadHtml().

static ResourceLoaderClientHtml::makeContext ( ResourceLoaderContext  $mainContext,
  $group,
  $type,
array  $extraQuery = [] 
)
staticprivate
static ResourceLoaderClientHtml::makeLoad ( ResourceLoaderContext  $mainContext,
array  $modules,
  $only,
array  $extraQuery = [] 
)
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
Returns
string|WrappedStringList HTML

Definition at line 401 of file ResourceLoaderClientHtml.php.

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

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

ResourceLoaderClientHtml::setConfig ( array  $vars)

Set mw.config variables.

Parameters
array$varsArray of key/value pairs

Definition at line 72 of file ResourceLoaderClientHtml.php.

References $value, and as.

Referenced by OutputPage\getRlClient().

ResourceLoaderClientHtml::setExemptStates ( array  $states)

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

See OutputPage::buildExemptModules() for use cases.

Parameters
array$modulesModule state keyed by module name

Definition at line 114 of file ResourceLoaderClientHtml.php.

Referenced by OutputPage\getRlClient().

ResourceLoaderClientHtml::setModules ( array  $modules)

Ensure one or more modules are loaded.

Parameters
array$modulesArray of module names

Definition at line 83 of file ResourceLoaderClientHtml.php.

References $modules.

Referenced by OutputPage\getRlClient().

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

References $modules.

Referenced by OutputPage\getRlClient().

ResourceLoaderClientHtml::setModuleStyles ( array  $modules)

Ensure the styles of one or more modules are loaded.

Deprecated:
since 1.28
Parameters
array$modulesArray of module names

Definition at line 93 of file ResourceLoaderClientHtml.php.

References $modules.

Referenced by OutputPage\getRlClient().

Member Data Documentation

array ResourceLoaderClientHtml::$config = []
private

Definition at line 40 of file ResourceLoaderClientHtml.php.

ResourceLoaderContext ResourceLoaderClientHtml::$context
private

Definition at line 31 of file ResourceLoaderClientHtml.php.

Referenced by __construct().

array ResourceLoaderClientHtml::$data
private

Definition at line 55 of file ResourceLoaderClientHtml.php.

Referenced by getData().

array ResourceLoaderClientHtml::$exemptStates = []
private

Definition at line 52 of file ResourceLoaderClientHtml.php.

array ResourceLoaderClientHtml::$modules = []
private

Definition at line 43 of file ResourceLoaderClientHtml.php.

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

array ResourceLoaderClientHtml::$moduleScripts = []
private

Definition at line 49 of file ResourceLoaderClientHtml.php.

array ResourceLoaderClientHtml::$moduleStyles = []
private

Definition at line 46 of file ResourceLoaderClientHtml.php.

ResourceLoader ResourceLoaderClientHtml::$resourceLoader
private

Definition at line 34 of file ResourceLoaderClientHtml.php.

Referenced by getData().

string null ResourceLoaderClientHtml::$target
private

Definition at line 37 of file ResourceLoaderClientHtml.php.

Referenced by __construct(), and getHeadHtml().


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