if ( $overrideBaseUrl ) {
$helpUrl = $to;
} else {
- $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$to";
+ $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
+ $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
}
$link = Html::rawElement(
'a',
$ret .= $item . "\n";
}
+ $ret .= $this->getInlineHeadScript();
+
// No newline after buildCssLinks since makeResourceLoaderLink did that already
$ret .= $this->buildCssLinks();
- $ret .= $this->getHeadScripts() . "\n";
+ $ret .= $this->getHeadScripts();
foreach ( $this->mHeadItems as $item ) {
$ret .= $item . "\n";
$resourceLoader->makeModuleResponse( $context, $grpModules )
);
} else {
- $links['html'] .= Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- $resourceLoader->makeModuleResponse( $context, $grpModules )
- )
+ $links['html'] .= ResourceLoader::makeInlineScript(
+ $resourceLoader->makeModuleResponse( $context, $grpModules )
);
}
$links['html'] .= "\n";
if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
$link = Html::linkedStyle( $url );
} elseif ( $loadCall ) {
- $link = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
- )
+ $link = ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
);
} else {
$link = Html::linkedScript( $url );
- if ( $context->getOnly() === 'scripts' && !$context->getRaw() && !$isRaw ) {
- // Wrap only=script requests in a conditional as browsers not supported
- // by the startup module would unconditionally execute this module.
- // Otherwise users will get "ReferenceError: mw is undefined" or
- // "jQuery is undefined" from e.g. a "site" module.
- $link = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- Xml::encodeJsCall( 'document.write', array( $link ) )
- )
+ if ( !$context->getRaw() && !$isRaw ) {
+ // Wrap only=script / only=combined requests in a conditional as
+ // browsers not supported by the startup module would unconditionally
+ // execute this module. Otherwise users will get "ReferenceError: mw is
+ // undefined" or "jQuery is undefined" from e.g. a "site" module.
+ $link = ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'document.write', array( $link ) )
);
}
}
if ( count( $states ) ) {
- $html = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- ResourceLoader::makeLoaderStateScript( $states )
- )
+ $html = ResourceLoader::makeInlineScript(
+ ResourceLoader::makeLoaderStateScript( $states )
) . "\n" . $html;
}
return $html;
}
+ /**
+ * Get <script> tags for <head> whose source is inline.
+ *
+ * @since 1.25
+ * @return string HTML fragment
+ */
+ public function getInlineHeadScript() {
+ // Load config before anything else.
+ $html = ResourceLoader::makeInlineScript(
+ ResourceLoader::makeConfigSetScript( $this->getJSVars() )
+ );
+
+ // Load embeddable private modules before any loader links.
+ $inlineModulesLink = $this->makeResourceLoaderLink(
+ array( 'user.options', 'user.tokens' ), ResourceLoaderModule::TYPE_COMBINED
+ );
+ $html .= "\n" . self::getHtmlFromLoaderLinks( array( $inlineModulesLink ) );
+
+ // Construct mw.loader.load() call for top-loaded modules.
+ // Client-side code will request these modules and their dependencies.
+ $topModules = $this->getModules( true, 'top' );
+ if ( $topModules ) {
+ $html .= ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'mw.loader.load', array( $topModules ) )
+ ) . "\n";
+ }
+
+ return $html;
+ }
+
/**
* JS stuff to put in the "<head>". This is the startup module, config
* vars and modules marked with position 'top'
$links = array();
$links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
- // Load config before anything else
- $links[] = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- ResourceLoader::makeConfigSetScript( $this->getJSVars() )
- )
- );
-
- // Load embeddable private modules before any loader links
- // This needs to be TYPE_COMBINED so these modules are properly wrapped
- // in mw.loader.implement() calls and deferred until mw.user is available
- $embedScripts = array( 'user.options', 'user.tokens' );
- $links[] = $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
-
// Scripts and messages "only" requests marked for top inclusion
// Messages should go first
$links[] = $this->makeResourceLoaderLink(
ResourceLoaderModule::TYPE_SCRIPTS
);
- // Modules requests - let the client calculate dependencies and batch requests as it likes
- // Only load modules that have marked themselves for loading at the top
- $modules = $this->getModules( true, 'top' );
- if ( $modules ) {
- $links[] = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
- )
- );
- }
-
if ( $this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
$links[] = $this->getScriptsForBottomQueue( true );
}
// Only load modules that have marked themselves for loading at the bottom
$modules = $this->getModules( true, 'bottom' );
if ( $modules ) {
- $links[] = Html::inlineScript(
- ResourceLoader::makeLoaderConditionalScript(
- Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
- )
+ $links[] = ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'mw.loader.load', array( $modules, null, true ) )
);
}