21use Wikimedia\WrappedString;
22use Wikimedia\WrappedStringList;
81 foreach ( $vars as $key =>
$value ) {
82 $this->config[$key] =
$value;
122 $this->exemptStates = $states;
149 'styleDeprecations' => [],
152 foreach ( $this->modules as $name ) {
158 $group = $module->getGroup();
160 if ( $module->isKnownEmpty(
$context ) ) {
166 if ( $group ===
'user' || $module->shouldEmbedModule( $this->context ) ) {
183 foreach ( $this->moduleStyles as $name ) {
184 $module = $rl->getModule( $name );
190 $logger = $rl->getLogger();
191 $logger->error(
'Unexpected general module "{module}" in styles queue.', [
202 $group = $module->getGroup();
205 if ( !$module->isKnownEmpty(
$context ) ) {
206 if ( $module->shouldEmbedModule( $this->context ) ) {
214 $deprecation = $module->getDeprecationInformation();
215 if ( $deprecation ) {
216 $data[
'styleDeprecations'][] = $deprecation;
220 foreach ( $this->moduleScripts as $name ) {
221 $module = $rl->getModule( $name );
226 $group = $module->getGroup();
228 if ( $module->isKnownEmpty(
$context ) ) {
247 return [
'class' =>
'client-nojs' ];
265 $nonce = $this->
options[
'nonce'];
272 $chunks[] = Html::inlineScript(
273 'document.documentElement.className = document.documentElement.className'
274 .
'.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );',
279 if ( $this->config ) {
287 $states = array_merge( $this->exemptStates,
$data[
'states'] );
296 if (
$data[
'embed'][
'general'] ) {
298 $data[
'embed'][
'general'],
305 if (
$data[
'general'] ) {
310 .
'mw.loader.load(RLPAGEMODULES);',
316 if (
$data[
'scripts'] ) {
325 if (
$data[
'styles'] ) {
334 if (
$data[
'embed'][
'styles'] ) {
336 $data[
'embed'][
'styles'],
345 foreach ( [
'target',
'safemode' ] as $param ) {
346 if ( $this->
options[$param] !==
null ) {
357 return WrappedString::join(
"\n", $chunks );
368 if (
$data[
'styleDeprecations'] ) {
370 implode(
'',
$data[
'styleDeprecations'] ),
375 return WrappedString::join(
"\n", $chunks );
387 array $extraQuery = []
390 $req =
new FauxRequest( array_merge( $mainContext->getRequest()->getValues(), $extraQuery ) );
394 if ( $group !==
'user' && $group !==
'private' ) {
395 $req->setVal(
'user',
null );
400 $ret->setContentOverrideCallback( $mainContext->getContentOverrideCallback() );
416 array $extraQuery = [], $nonce =
null
418 $rl = $mainContext->getResourceLoader();
424 if ( $mainContext->getDebug() && count(
$modules ) > 1 ) {
428 $chunks[] =
self::makeLoad( $mainContext, [ $name ], $only, $extraQuery, $nonce );
430 return new WrappedStringList(
"\n", $chunks );
436 $module = $rl->getModule( $name );
438 $rl->getLogger()->warning(
'Unknown module "{module}"', [
'module' => $name ] );
441 $sortedModules[$module->getSource()][$module->getGroup()][
$name] = $module;
444 foreach ( $sortedModules as
$source => $groups ) {
445 foreach ( $groups as $group => $grpModules ) {
451 foreach ( $grpModules as $name => $module ) {
452 $shouldEmbed = $module->shouldEmbedModule(
$context );
453 if ( !$moduleSets || $moduleSets[$idx][0] !== $shouldEmbed ) {
454 $moduleSets[++$idx] = [ $shouldEmbed, [] ];
456 $moduleSets[$idx][1][
$name] = $module;
460 foreach ( $moduleSets as
list( $embed, $moduleSet ) ) {
461 $context->setModules( array_keys( $moduleSet ) );
465 $chunks[] = Html::inlineStyle(
466 $rl->makeModuleResponse(
$context, $moduleSet )
470 $rl->makeModuleResponse(
$context, $moduleSet ),
477 foreach ( $moduleSet as $key => $module ) {
478 $isRaw |= $module->isRaw();
486 if ( $group ===
'user' ) {
495 $chunk = Html::linkedStyle( $url );
498 $chunk = Html::element(
'script', [
500 'async' => !isset( $extraQuery[
'sync'] ),
505 Xml::encodeJsCall(
'mw.loader.load', [ $url ] ),
511 if ( $group ==
'noscript' ) {
512 $chunks[] = Html::rawElement(
'noscript', [], $chunk );
521 return new WrappedStringList(
"\n", $chunks );
Allows changing specific properties of a context object, without changing the main one.
WebRequest clone which takes values from a provided array.
Bootstrap a ResourceLoader client on an HTML page.
getLoad( $modules, $only, $nonce, array $extraQuery=[])
setModules(array $modules)
Ensure one or more modules are loaded.
ResourceLoader $resourceLoader
static makeLoad(ResourceLoaderContext $mainContext, array $modules, $only, array $extraQuery=[], $nonce=null)
Explicily load or embed modules on a page.
setModuleScripts(array $modules)
Ensure the scripts of one or more modules are loaded.
__construct(ResourceLoaderContext $context, array $options=[])
getHeadHtml()
The order of elements in the head is as follows:
getContext( $group, $type)
setConfig(array $vars)
Set mw.config variables.
ResourceLoaderContext $context
setExemptStates(array $states)
Set state of special modules that are handled by the caller manually.
static makeContext(ResourceLoaderContext $mainContext, $group, $type, array $extraQuery=[])
setModuleStyles(array $modules)
Ensure the styles of one or more modules are loaded.
Object passed around to modules which contains information about the state of a specific loader reque...
Dynamic JavaScript and CSS resource loading system.
static makeInlineScript( $script, $nonce=null)
Returns an HTML script tag that runs given JS code after startup and base modules.
static makeLoaderStateScript( $states, $state=null)
Returns a JS call to mw.loader.state, which sets the state of one ore more modules to a given value.
static makeConfigSetScript(array $configuration)
Returns JS code which will set the MediaWiki configuration array to the given value.
getModule( $name)
Get the ResourceLoaderModule object for a given module name.
static encodeJsonForScript( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only $req
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going and make changes or fix bugs In we can take all the code that deals with the little used title reversing options(say) and put it in one place. Instead of having little title-reversing if-blocks spread all over the codebase in showAnArticle
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Allows to change the fields on the form that will be generated $name
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))