Index: branches/resourceloader/phase3/includes/OutputPage.php |
— | — | @@ -2343,8 +2343,9 @@ |
2344 | 2344 | } |
2345 | 2345 | if ( $this->getModules() ) { |
2346 | 2346 | // Modules - let the client calculate dependencies and batch requests as it likes |
| 2347 | + $modules = FormatJson::encode( $this->getModules() ); |
2347 | 2348 | $scripts .= Html::inlineScript( |
2348 | | - 'mediaWiki.loader.load( ' . FormatJson::encode( $this->getModules() ) . ' );' |
| 2349 | + "if ( mediaWiki !== undefined ) { mediaWiki.loader.load( {$modules} ); }" |
2349 | 2350 | ); |
2350 | 2351 | } |
2351 | 2352 | // TODO: User Scripts should be included using the resource loader |
— | — | @@ -2367,7 +2368,7 @@ |
2368 | 2369 | } |
2369 | 2370 | $scripts .= "\n" . $this->mScripts; |
2370 | 2371 | // This should be at the bottom of the body - below ALL other scripts |
2371 | | - $scripts .= Html::inlineScript( "if ( typeof mediaWiki.loader.go === 'function' ) { mediaWiki.loader.go(); }" ); |
| 2372 | + $scripts .= Html::inlineScript( "if ( mediaWiki !== undefined ) { mediaWiki.loader.go(); }" ); |
2372 | 2373 | return $scripts; |
2373 | 2374 | } |
2374 | 2375 | |
Index: branches/resourceloader/phase3/includes/ResourceLoader.php |
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | } else { |
192 | 192 | // Support module loader scripts |
193 | 193 | if ( ( $loader = $module->getLoaderScript() ) !== false ) { |
194 | | - $scripts .= "\n" . $loader; |
| 194 | + $scripts .= $loader; |
195 | 195 | } |
196 | 196 | // Automatically register module |
197 | 197 | else { |
— | — | @@ -206,7 +206,7 @@ |
207 | 207 | } |
208 | 208 | } |
209 | 209 | } |
210 | | - return $scripts . "\nmediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );\n"; |
| 210 | + return $scripts . "mediaWiki.loader.register( " . FormatJson::encode( $registrations ) . " );"; |
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
— | — | @@ -327,29 +327,38 @@ |
328 | 328 | ); |
329 | 329 | // Special meta-information for the 'startup' module |
330 | 330 | if ( $name === 'startup' && $parameters['only'] === 'scripts' ) { |
331 | | - $scripts .= self::getModuleRegistrations( |
| 331 | + // Get all module registrations |
| 332 | + $registration = self::getModuleRegistrations( |
332 | 333 | $parameters['lang'], $parameters['skin'], $parameters['debug'] |
333 | 334 | ); |
334 | | - $scripts .= "mediaWiki.config.set( " . |
335 | | - FormatJson::encode( array( 'server' => $server, 'debug' => $parameters['debug'] ) ) . " );\n"; |
336 | | - // Wrap in a closure |
337 | | - $scripts = "window.mediaWikiStartUp = function() {" . $scripts . "};"; |
338 | | - $query = wfArrayToCGI( $parameters + array( 'version' => wfTimestamp( |
339 | | - TS_ISO_8601, |
340 | | - round( |
341 | | - max( |
342 | | - self::$modules['jquery']->getModifiedTime( |
343 | | - $parameters['lang'], $parameters['skin'], $parameters['debug'] |
| 335 | + // Build configuration |
| 336 | + $config = FormatJson::encode( array( 'server' => $server, 'debug' => $parameters['debug'] ) ); |
| 337 | + // Add a well-known start-up function |
| 338 | + $scripts .= "window.startUp = function() { {$registration} mediaWiki.config.set( {$config} ); };"; |
| 339 | + // Build load query for jquery and mediawiki modules |
| 340 | + $query = wfArrayToCGI( $parameters + array( |
| 341 | + 'modules' => implode( '|', array( 'jquery', 'mediawiki' ) ), |
| 342 | + 'version' => wfTimestamp( |
| 343 | + TS_ISO_8601, |
| 344 | + round( |
| 345 | + max( |
| 346 | + self::$modules['jquery']->getModifiedTime( |
| 347 | + $parameters['lang'], $parameters['skin'], $parameters['debug'] |
| 348 | + ), |
| 349 | + self::$modules['mediawiki']->getModifiedTime( |
| 350 | + $parameters['lang'], $parameters['skin'], $parameters['debug'] |
| 351 | + ) |
344 | 352 | ), |
345 | | - self::$modules['mediawiki']->getModifiedTime( |
346 | | - $parameters['lang'], $parameters['skin'], $parameters['debug'] |
347 | | - ) |
348 | | - ), |
349 | | - -2 |
| 353 | + -2 |
| 354 | + ) |
350 | 355 | ) |
351 | | - ) ) ); |
352 | | - $scripts .= "document.write('<script type=\"text/javascript\" " . |
353 | | - "src=\"{$server}?modules=jquery|mediawiki&{$query}\"></script>');"; |
| 356 | + ) ); |
| 357 | + // Build HTML code for loading jquery and mediawiki modules |
| 358 | + $linkedScript = Html::linkedScript( "{$server}?{$query}" ); |
| 359 | + // Add code to add jquery and mediawiki loading code; only if the current client is compatible |
| 360 | + $scripts .= "if ( isCompatible() ) { document.write( '{$linkedScript}' ); }"; |
| 361 | + // Delete the compatible function - it's not needed anymore |
| 362 | + $scripts .= "delete window['isCompatible'];"; |
354 | 363 | } |
355 | 364 | } |
356 | 365 | // Styles |
Index: branches/resourceloader/phase3/includes/ResourceLoaderModule.php |
— | — | @@ -595,7 +595,7 @@ |
596 | 596 | private $modifiedTime = null; |
597 | 597 | |
598 | 598 | public function getScript( $lang, $skin, $debug ) { |
599 | | - return ''; |
| 599 | + return file_get_contents( 'resources/startup.js' ); |
600 | 600 | } |
601 | 601 | |
602 | 602 | public function getModifiedTime( $lang, $skin, $debug ) { |
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -624,6 +624,8 @@ |
625 | 625 | that.work(); |
626 | 626 | } |
627 | 627 | |
| 628 | + /* Cache document ready status */ |
| 629 | + |
628 | 630 | $(document).ready( function() { ready = true; } ); |
629 | 631 | } )(); |
630 | 632 | |
— | — | @@ -634,9 +636,10 @@ |
635 | 637 | |
636 | 638 | } )( jQuery ); |
637 | 639 | |
| 640 | + |
638 | 641 | /* Auto-register from pre-loaded startup scripts */ |
639 | 642 | |
640 | | -if ( typeof mediaWikiStartUp === 'function' ) { |
641 | | - mediaWikiStartUp(); |
642 | | - delete mediaWikiStartUp; |
| 643 | +if ( typeof window['startUp'] === 'function' ) { |
| 644 | + window['startUp'](); |
| 645 | + delete window['startUp']; |
643 | 646 | } |
\ No newline at end of file |
Index: branches/resourceloader/phase3/resources/startup.js |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +/** |
| 3 | + * This script provides a function which is run to evaluate whether or not to continue loading the jquery and mediawiki |
| 4 | + * modules. This code should work on even the most anchient of browsers, so be very careful when editing. |
| 5 | + */ |
| 6 | +/** |
| 7 | + * Returns false when run in a black-listed browser |
| 8 | + * |
| 9 | + * This function will be deleted after it's used, so do not expand it to be generally useful beyond startup |
| 10 | + * |
| 11 | + * jQuery has minimum requirements of: |
| 12 | + * * Firefox 2.0+ |
| 13 | + * * Internet Explorer 6+ |
| 14 | + * * Safari 3+ |
| 15 | + * * Opera 9+ |
| 16 | + * * Chrome 1+ |
| 17 | + */ |
| 18 | +window.isCompatible = function() { |
| 19 | + // IE < 6 |
| 20 | + if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1 && parseFloat( navigator.appVersion.split( 'MSIE' )[1] ) < 6 ) { |
| 21 | + return false; |
| 22 | + } |
| 23 | + // TODO: Firefox < 2 |
| 24 | + // TODO: Safari < 3 |
| 25 | + // TODO: Opera < 9 |
| 26 | + // TODO: Chrome < 1 |
| 27 | + return true; |
| 28 | +}; |
| 29 | +/** |
| 30 | + * The startUp() function will be generated and added here (at the bottom) |
| 31 | + */ |
Property changes on: branches/resourceloader/phase3/resources/startup.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |