21 use Wikimedia\WrappedString;
22 use Wikimedia\WrappedStringList;
78 foreach ( $vars
as $key =>
$value ) {
79 $this->config[$key] =
$value;
109 $this->exemptStates = $states;
135 'styleDeprecations' => [],
138 foreach ( $this->modules
as $name ) {
139 $module = $rl->getModule(
$name );
144 $group = $module->getGroup();
146 if ( $module->isKnownEmpty(
$context ) ) {
152 if ( $group ===
'user' || $module->shouldEmbedModule( $this->context ) ) {
169 foreach ( $this->moduleStyles
as $name ) {
170 $module = $rl->getModule(
$name );
176 $logger = $rl->getLogger();
177 $logger->error(
'Unexpected general module "{module}" in styles queue.', [
188 $group = $module->getGroup();
191 if ( !$module->isKnownEmpty(
$context ) ) {
192 if ( $module->shouldEmbedModule( $this->context ) ) {
200 $deprecation = $module->getDeprecationInformation();
201 if ( $deprecation ) {
202 $data[
'styleDeprecations'][] = $deprecation;
213 return [
'class' =>
'client-nojs' ];
231 $nonce = $this->
options[
'nonce'];
238 $chunks[] = Html::inlineScript(
239 'document.documentElement.className = document.documentElement.className'
240 .
'.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );',
245 if ( $this->config ) {
246 $chunks[] = ResourceLoader::makeInlineScript(
247 ResourceLoader::makeConfigSetScript( $this->config ),
253 $states = array_merge( $this->exemptStates,
$data[
'states'] );
255 $chunks[] = ResourceLoader::makeInlineScript(
256 ResourceLoader::makeLoaderStateScript( $states ),
262 if (
$data[
'embed'][
'general'] ) {
264 $data[
'embed'][
'general'],
271 if (
$data[
'general'] ) {
272 $chunks[] = ResourceLoader::makeInlineScript(
274 . ResourceLoader::encodeJsonForScript(
$data[
'general'] )
276 .
'mw.loader.load(RLPAGEMODULES);',
282 if (
$data[
'styles'] ) {
291 if (
$data[
'embed'][
'styles'] ) {
293 $data[
'embed'][
'styles'],
302 foreach ( [
'target',
'safemode' ]
as $param ) {
303 if ( $this->
options[$param] !==
null ) {
314 return WrappedString::join(
"\n", $chunks );
325 if (
$data[
'styleDeprecations'] ) {
326 $chunks[] = ResourceLoader::makeInlineScript(
327 implode(
'',
$data[
'styleDeprecations'] ),
332 return WrappedString::join(
"\n", $chunks );
344 array $extraQuery = []
351 if ( $group !==
'user' && $group !==
'private' ) {
352 $req->setVal(
'user',
null );
373 array $extraQuery = [], $nonce =
null
387 return new WrappedStringList(
"\n", $chunks );
393 $module = $rl->getModule(
$name );
395 $rl->getLogger()->warning(
'Unknown module "{module}"', [
'module' =>
$name ] );
398 $sortedModules[$module->getSource()][$module->getGroup()][
$name] = $module;
401 foreach ( $sortedModules
as $source => $groups ) {
402 foreach ( $groups
as $group => $grpModules ) {
408 foreach ( $grpModules
as $name => $module ) {
409 $shouldEmbed = $module->shouldEmbedModule(
$context );
410 if ( !$moduleSets || $moduleSets[$idx][0] !== $shouldEmbed ) {
411 $moduleSets[++$idx] = [ $shouldEmbed, [] ];
413 $moduleSets[$idx][1][
$name] = $module;
417 foreach ( $moduleSets
as list( $embed, $moduleSet ) ) {
418 $context->setModules( array_keys( $moduleSet ) );
422 $chunks[] = Html::inlineStyle(
423 $rl->makeModuleResponse(
$context, $moduleSet )
426 $chunks[] = ResourceLoader::makeInlineScript(
427 $rl->makeModuleResponse(
$context, $moduleSet ),
434 foreach ( $moduleSet
as $key => $module ) {
435 $isRaw |= $module->isRaw();
443 if ( $group ===
'user' ) {
452 $chunk = Html::linkedStyle( $url );
454 $chunk = Html::element(
'script', [
456 'async' => !isset( $extraQuery[
'sync'] ),
460 $chunk = ResourceLoader::makeInlineScript(
466 if ( $group ==
'noscript' ) {
467 $chunks[] = Html::rawElement(
'noscript', [], $chunk );
476 return new WrappedStringList(
"\n", $chunks );