$ret .= $item . "\n";
}
- $ret .= $this->getInlineHeadScript();
-
// No newline after buildCssLinks since makeResourceLoaderLink did that already
$ret .= $this->buildCssLinks();
- $ret .= $this->getHeadScripts();
+ $ret .= $this->getHeadScripts() . "\n";
foreach ( $this->mHeadItems as $item ) {
$ret .= $item . "\n";
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[] = ResourceLoader::makeInlineScript(
+ 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[] = ResourceLoader::makeInlineScript(
+ Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
+ );
+ }
+
if ( $this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
$links[] = $this->getScriptsForBottomQueue( true );
}
// This also enforces $.isReady to be true at </body> which fixes the
// mw.loader bug in Firefox with using document.write between </body>
// and the DOMContentReady event (bug 47457).
- $html = Html::inlineScript( 'window.jQuery && jQuery.ready();' );
+ $html = Html::inlineScript( 'if(window.jQuery)jQuery.ready();' );
if ( !$this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
$html .= $this->getScriptsForBottomQueue( false );
if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
return false;
}
+ if ( !$this->getTitle()->isSubpageOf( $this->getUser()->getUserPage() ) ) {
+ // Don't execute another user's CSS or JS on preview (T85855)
+ return false;
+ }
return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
}