Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2535,23 +2535,22 @@ |
2536 | 2536 | // Startup - this will immediately load jquery and mediawiki modules |
2537 | 2537 | $scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true ); |
2538 | 2538 | |
2539 | | - // Configuration -- This could be merged together with the load and go, but |
2540 | | - // makeGlobalVariablesScript returns a whole script tag -- grumble grumble... |
2541 | | - $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n"; |
2542 | | - |
2543 | 2539 | // Script and Messages "only" requests |
2544 | 2540 | $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts( true ), ResourceLoaderModule::TYPE_SCRIPTS ); |
2545 | 2541 | $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true ), ResourceLoaderModule::TYPE_MESSAGES ); |
2546 | 2542 | |
2547 | 2543 | // Modules requests - let the client calculate dependencies and batch requests as it likes |
| 2544 | + $loader = ''; |
2548 | 2545 | if ( $this->getModules( true ) ) { |
2549 | | - $scripts .= Html::inlineScript( |
2550 | | - ResourceLoader::makeLoaderConditionalScript( |
2551 | | - Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules( true ) ) ) . |
2552 | | - Xml::encodeJsCall( 'mediaWiki.loader.go', array() ) |
2553 | | - ) |
2554 | | - ) . "\n"; |
| 2546 | + $loader = Xml::encodeJsCall( 'mediaWiki.loader.load', array( $this->getModules( true ) ) ) . |
| 2547 | + Xml::encodeJsCall( 'mediaWiki.loader.go', array() ); |
2555 | 2548 | } |
| 2549 | + |
| 2550 | + $scripts .= Html::inlineScript( |
| 2551 | + ResourceLoader::makeLoaderConditionalScript( |
| 2552 | + ResourceLoader::makeConfigSetScript( $this->getJSVars() ) . $loader |
| 2553 | + ) |
| 2554 | + ); |
2556 | 2555 | |
2557 | 2556 | // Legacy Scripts |
2558 | 2557 | $scripts .= "\n" . $this->mScripts; |
— | — | @@ -2583,6 +2582,53 @@ |
2584 | 2583 | } |
2585 | 2584 | |
2586 | 2585 | /** |
| 2586 | + * Get an array containing global JS variables |
| 2587 | + * |
| 2588 | + * Do not add things here which can be evaluated in |
| 2589 | + * ResourceLoaderStartupScript - in other words, without state. |
| 2590 | + * You will only be adding bloat to the page and causing page caches to |
| 2591 | + * have to be purged on configuration changes. |
| 2592 | + */ |
| 2593 | + protected function getJSVars() { |
| 2594 | + global $wgUser, $wgRequest, $wgUseAjax, $wgEnableMWSuggest, $wgContLang; |
| 2595 | + |
| 2596 | + $title = $this->getTitle(); |
| 2597 | + $ns = $title->getNamespace(); |
| 2598 | + $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $title->getNsText(); |
| 2599 | + |
| 2600 | + $vars = array( |
| 2601 | + 'wgCanonicalNamespace' => $nsname, |
| 2602 | + 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ? |
| 2603 | + SpecialPage::resolveAlias( $title->getDBkey() ) : false, # bug 21115 |
| 2604 | + 'wgNamespaceNumber' => $title->getNamespace(), |
| 2605 | + 'wgPageName' => $title->getPrefixedDBKey(), |
| 2606 | + 'wgTitle' => $title->getText(), |
| 2607 | + 'wgCurRevisionId' => $title->getLatestRevID(), |
| 2608 | + 'wgArticleId' => $title->getArticleId(), |
| 2609 | + 'wgIsArticle' => $this->isArticle(), |
| 2610 | + 'wgAction' => $wgRequest->getText( 'action', 'view' ), |
| 2611 | + 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(), |
| 2612 | + 'wgUserGroups' => $wgUser->getEffectiveGroups(), |
| 2613 | + 'wgCategories' => $this->getCategories(), |
| 2614 | + 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', |
| 2615 | + ); |
| 2616 | + if ( $wgContLang->hasVariants() ) { |
| 2617 | + $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); |
| 2618 | + } |
| 2619 | + foreach ( $title->getRestrictionTypes() as $type ) { |
| 2620 | + $vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type ); |
| 2621 | + } |
| 2622 | + if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) { |
| 2623 | + $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser ); |
| 2624 | + } |
| 2625 | + |
| 2626 | + // Allow extensions to add their custom variables to the global JS variables |
| 2627 | + wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) ); |
| 2628 | + |
| 2629 | + return $vars; |
| 2630 | + } |
| 2631 | + |
| 2632 | + /** |
2587 | 2633 | * Add default \<meta\> tags |
2588 | 2634 | */ |
2589 | 2635 | protected function addDefaultMeta() { |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -471,52 +471,6 @@ |
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | | - * Make a <script> tag containing global variables |
476 | | - * @param $skinName string Name of the skin |
477 | | - * The odd calling convention is for backwards compatibility |
478 | | - * @todo FIXME: Make this not depend on $wgTitle! |
479 | | - * |
480 | | - * Do not add things here which can be evaluated in ResourceLoaderStartupScript - in other words, without state. |
481 | | - * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes. |
482 | | - */ |
483 | | - static function makeGlobalVariablesScript( $skinName ) { |
484 | | - global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest, $wgContLang; |
485 | | - |
486 | | - $ns = $wgTitle->getNamespace(); |
487 | | - $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText(); |
488 | | - $vars = array( |
489 | | - 'wgCanonicalNamespace' => $nsname, |
490 | | - 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ? |
491 | | - SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115 |
492 | | - 'wgNamespaceNumber' => $wgTitle->getNamespace(), |
493 | | - 'wgPageName' => $wgTitle->getPrefixedDBKey(), |
494 | | - 'wgTitle' => $wgTitle->getText(), |
495 | | - 'wgAction' => $wgRequest->getText( 'action', 'view' ), |
496 | | - 'wgArticleId' => $wgTitle->getArticleId(), |
497 | | - 'wgIsArticle' => $wgOut->isArticle(), |
498 | | - 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(), |
499 | | - 'wgUserGroups' => $wgUser->getEffectiveGroups(), |
500 | | - 'wgCurRevisionId' => $wgTitle->getLatestRevID(), |
501 | | - 'wgCategories' => $wgOut->getCategories(), |
502 | | - 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY', |
503 | | - ); |
504 | | - if ( $wgContLang->hasVariants() ) { |
505 | | - $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); |
506 | | - } |
507 | | - foreach ( $wgTitle->getRestrictionTypes() as $type ) { |
508 | | - $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type ); |
509 | | - } |
510 | | - if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) { |
511 | | - $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser ); |
512 | | - } |
513 | | - |
514 | | - // Allow extensions to add their custom variables to the global JS variables |
515 | | - wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) ); |
516 | | - |
517 | | - return self::makeVariablesScript( $vars ); |
518 | | - } |
519 | | - |
520 | | - /** |
521 | 475 | * To make it harder for someone to slip a user a fake |
522 | 476 | * user-JavaScript or user-CSS preview, a random token |
523 | 477 | * is associated with the login session. If it's not |