r72121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72120‎ | r72121 | r72122 >
Date:17:35, 1 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Got startup script working
Modified paths:
  • /branches/resourceloader/phase3/includes/OutputPage.php (modified) (history)
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/includes/ResourceLoaderModule.php (modified) (history)
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /branches/resourceloader/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/skins/common/wikibits.js
@@ -65,10 +65,6 @@
6666 }
6767 }
6868
69 -window.hookEvent = function( hookName, hookFunct ) {
70 - addHandler( window, hookName, hookFunct );
71 -}
72 -
7369 window.importScript = function( page ) {
7470 // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
7571 var uri = wgScript + '?title=' +
@@ -133,7 +129,7 @@
134130 }
135131
136132
137 -if ( wgBreakFrames ) {
 133+if ( 'wgBreakFrames' in window && window.wgBreakFrames ) {
138134 // Un-trap us from framesets
139135 if ( window.top != window ) {
140136 window.top.location = window.location;
@@ -1063,6 +1059,10 @@
10641060 }
10651061 }
10661062
 1063+window.hookEvent = function( hookName, hookFunct ) {
 1064+ addHandler( window, hookName, hookFunct );
 1065+}
 1066+
10671067 /**
10681068 * Add a click event handler to an element
10691069 *
Index: branches/resourceloader/phase3/includes/OutputPage.php
@@ -1604,13 +1604,13 @@
16051605 $sk = $wgUser->getSkin();
16061606
16071607 // Add base resources
1608 - $this->addModuleScripts( array( 'jquery', 'mediawiki' ) );
 1608+ $this->addModuleScripts( array( 'startup' ) );
16091609 $this->addModules( array( 'mediawiki.legacy.wikibits' ) );
16101610
16111611 // Add site JS if enabled
16121612 global $wgUseSiteJs;
16131613 if ( $wgUseSiteJs ) {
1614 - $this->addModules( 'sitejs' );
 1614+ $this->addModuleScripts( 'sitejs' );
16151615 }
16161616
16171617 // Add various resources if required
@@ -2316,35 +2316,44 @@
23172317 $scripts = '';
23182318 // Support individual script requests in debug mode
23192319 if ( $wgRequest->getBool( 'debug' ) && $wgRequest->getVal( 'debug' ) !== 'false' ) {
 2320+ // Styles
23202321 foreach ( $this->getModuleStyles() as $name ) {
23212322 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'styles' );
23222323 }
 2324+ // Scripts
23232325 foreach ( $this->getModuleScripts() as $name ) {
23242326 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'scripts' );
23252327 }
 2328+ // Configuration
 2329+ $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
 2330+ // Messages
23262331 foreach ( $this->getModuleMessages() as $name ) {
23272332 $scripts .= self::makeResourceLoaderLink( $sk, $name, 'messages' );
23282333 }
 2334+ // Modules
23292335 foreach ( $this->getModules() as $name ) {
23302336 $scripts .= self::makeResourceLoaderLink( $sk, $name );
23312337 }
23322338 } else {
 2339+ // Styles
23332340 if ( count( $this->getModuleStyles() ) ) {
23342341 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleStyles(), 'styles' );
23352342 }
 2343+ // Scripts
23362344 if ( count( $this->getModuleScripts() ) ) {
23372345 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleScripts(), 'scripts' );
23382346 }
 2347+ // Configuration
 2348+ $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
 2349+ // Messages
23392350 if ( count( $this->getModuleMessages() ) ) {
23402351 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModuleMessages(), 'messages' );
23412352 }
 2353+ // Modules
23422354 if ( count( $this->getModules() ) ) {
23432355 $scripts .= self::makeResourceLoaderLink( $sk, $this->getModules() );
23442356 }
23452357 }
2346 - // Configure page
2347 - $scripts .= Skin::makeGlobalVariablesScript( $sk->getSkinName() ) . "\n";
2348 -
23492358 // add user JS if enabled
23502359 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
23512360 $action = $wgRequest->getVal( 'action', 'view' );
Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -185,7 +185,9 @@
186186 $scripts = '';
187187 $registrations = array();
188188 foreach ( self::$modules as $name => $module ) {
189 - if ( !in_array( $name, self::$preRegisteredModules ) ) {
 189+ if ( in_array( $name, self::$preRegisteredModules ) ) {
 190+ $registrations[] = array( $name, $module->getModifiedTime( $lang, $skin, $debug ), array(), 'ready' );
 191+ } else {
190192 // Support module loader scripts
191193 if ( ( $loader = $module->getLoaderScript() ) !== false ) {
192194 $scripts .= "\n" . $loader;
@@ -204,8 +206,7 @@
205207 }
206208 }
207209 }
208 - $scripts .= "\nmediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n";
209 - return "window.mediaWikiStartUp = function() {" . $scripts . "};";
 210+ return $scripts . "\nmediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n";
210211 }
211212
212213 /**
@@ -324,11 +325,18 @@
325326 $scripts .= self::$modules[$name]->getScript(
326327 $parameters['lang'], $parameters['skin'], $parameters['debug']
327328 );
328 - // Special meta-information for the 'mediawiki' module
329 - if ( $name === 'mediawiki' && $parameters['only'] === 'scripts' ) {
 329+ // Special meta-information for the 'startup' module
 330+ if ( $name === 'startup' && $parameters['only'] === 'scripts' ) {
 331+ $scripts .= self::getModuleRegistrations(
 332+ $parameters['lang'], $parameters['skin'], $parameters['debug']
 333+ );
330334 $scripts .= "mediaWiki.config.set( " .
331335 FormatJson::encode( array( 'server' => $server, 'debug' => $parameters['debug'] ) ) . " );\n";
332 - $scripts .= self::getModuleRegistrations( $parameters['lang'], $parameters['skin'], $parameters['debug'] );
 336+ // Wrap in a closure
 337+ $scripts = "window.mediaWikiStartUp = function() {" . $scripts . "};";
 338+ $query = wfArrayToCGI( $parameters );
 339+ $scripts .= "document.write('<script type=\"text/javascript\" " .
 340+ "src=\"{$server}?modules=jquery|mediawiki&{$query}\"></script>');";
333341 }
334342 }
335343 // Styles
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php
@@ -585,7 +585,7 @@
586586 private $modifiedTime = null;
587587
588588 public function getScript( $lang, $skin, $debug ) {
589 - return ResourceLoader::getModuleRegistrations( $lang, $skin, $debug );
 589+ return '';
590590 }
591591
592592 public function getModifiedTime( $lang, $skin, $debug ) {
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -624,10 +624,11 @@
625625 this.util = {};
626626 this.legacy = {};
627627
628 - /* Auto-register from pre-loaded startup scripts */
629 -
630 - if ( typeof window['mediaWikiStartUp'] === 'function' ) {
631 - window['mediaWikiStartUp']();
632 - delete window['mediaWikiStartUp'];
633 - }
634628 } )( jQuery );
 629+
 630+/* Auto-register from pre-loaded startup scripts */
 631+
 632+if ( typeof mediaWikiStartUp === 'function' ) {
 633+ mediaWikiStartUp();
 634+ delete mediaWikiStartUp;
 635+}
\ No newline at end of file

Status & tagging log