r82273 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82272‎ | r82273 | r82274 >
Date:18:25, 16 February 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
Moved Skin::makeGlobalVariablesScript() to OutputPage::getJSVars()
* merged <script> and if ( window.mediaWiki ) block with the one of mediaWiki.loader as stated in the doc
* removed dependency of $wgTitle
* the two only calls to this functions are in SemanticForms, but will not affect current version of MediaWiki:
** specials/SF_UploadWindow.php: this file is only used before 1.16
** specials/SF_UploadWindow2.php: the call is part of the else branch of a "method_exists( $wgOut, 'addModules' )" check, which means it's not called since 1.17
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2535,23 +2535,22 @@
25362536 // Startup - this will immediately load jquery and mediawiki modules
25372537 $scripts = $this->makeResourceLoaderLink( $sk, 'startup', ResourceLoaderModule::TYPE_SCRIPTS, true );
25382538
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 -
25432539 // Script and Messages "only" requests
25442540 $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleScripts( true ), ResourceLoaderModule::TYPE_SCRIPTS );
25452541 $scripts .= $this->makeResourceLoaderLink( $sk, $this->getModuleMessages( true ), ResourceLoaderModule::TYPE_MESSAGES );
25462542
25472543 // Modules requests - let the client calculate dependencies and batch requests as it likes
 2544+ $loader = '';
25482545 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() );
25552548 }
 2549+
 2550+ $scripts .= Html::inlineScript(
 2551+ ResourceLoader::makeLoaderConditionalScript(
 2552+ ResourceLoader::makeConfigSetScript( $this->getJSVars() ) . $loader
 2553+ )
 2554+ );
25562555
25572556 // Legacy Scripts
25582557 $scripts .= "\n" . $this->mScripts;
@@ -2583,6 +2582,53 @@
25842583 }
25852584
25862585 /**
 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+ /**
25872633 * Add default \<meta\> tags
25882634 */
25892635 protected function addDefaultMeta() {
Index: trunk/phase3/includes/Skin.php
@@ -471,52 +471,6 @@
472472 }
473473
474474 /**
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 - /**
521475 * To make it harder for someone to slip a user a fake
522476 * user-JavaScript or user-CSS preview, a random token
523477 * is associated with the login session. If it's not

Follow-up revisions

RevisionCommit summaryAuthorDate
r82791* (bug 27680) Fix for r82273: wgCanonicalSpecialPageName no longer false when...ialex11:48, 25 February 2011
r107595* (bug 32702) Fix for r82273: readded Skin::makeGlobalVariablesScript() for b...ialex20:39, 29 December 2011

Comments

#Comment by Reedy (talk | contribs)   01:46, 29 November 2011

See bug 32702

Breaking interfaces like this is not cool

The function (Skin::makeGlobalVariablesScript) wasn't deprecated in an shape or form, and then it just disappeared between 1.17 and 1.18? :/

Even if it wasn't supposed to be public, it is/was, and was being used in other skins

#Comment by IAlex (talk | contribs)   20:39, 29 December 2011

Done in r107595.

Status & tagging log