http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72220

Revision: 72220
Author:   tparscal
Date:     2010-09-02 19:58:33 +0000 (Thu, 02 Sep 2010)

Log Message:
-----------
Added more support for preventing loading in incompatible browsers

Modified Paths:
--------------
    branches/resourceloader/phase3/includes/OutputPage.php
    branches/resourceloader/phase3/includes/ResourceLoader.php
    branches/resourceloader/phase3/includes/ResourceLoaderModule.php
    branches/resourceloader/phase3/resources/mediawiki/mediawiki.js

Added Paths:
-----------
    branches/resourceloader/phase3/resources/startup.js

Modified: branches/resourceloader/phase3/includes/OutputPage.php
===================================================================
--- branches/resourceloader/phase3/includes/OutputPage.php      2010-09-02 
19:48:16 UTC (rev 72219)
+++ branches/resourceloader/phase3/includes/OutputPage.php      2010-09-02 
19:58:33 UTC (rev 72220)
@@ -2343,8 +2343,9 @@
                }
                if ( $this->getModules() ) {
                        // Modules - let the client calculate dependencies and 
batch requests as it likes
+                       $modules = FormatJson::encode( $this->getModules() );
                        $scripts .= Html::inlineScript(
-                               'mediaWiki.loader.load( ' . FormatJson::encode( 
$this->getModules() ) . ' );'
+                               "if ( mediaWiki !== undefined ) { 
mediaWiki.loader.load( {$modules} ); }"
                        );
                }
                // TODO: User Scripts should be included using the resource 
loader
@@ -2367,7 +2368,7 @@
                }
                $scripts .= "\n" . $this->mScripts;
                // This should be at the bottom of the body - below ALL other 
scripts
-               $scripts .= Html::inlineScript( "if ( typeof 
mediaWiki.loader.go === 'function' ) { mediaWiki.loader.go(); }" );
+               $scripts .= Html::inlineScript( "if ( mediaWiki !== undefined ) 
{ mediaWiki.loader.go(); }" );
                return $scripts;
        }
 

Modified: branches/resourceloader/phase3/includes/ResourceLoader.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoader.php  2010-09-02 
19:48:16 UTC (rev 72219)
+++ branches/resourceloader/phase3/includes/ResourceLoader.php  2010-09-02 
19:58:33 UTC (rev 72220)
@@ -190,7 +190,7 @@
                        } else {
                                // Support module loader scripts
                                if ( ( $loader = $module->getLoaderScript() ) 
!== false ) {
-                                       $scripts .= "\n" . $loader;
+                                       $scripts .= $loader;
                                }
                                // Automatically register module
                                else {
@@ -206,7 +206,7 @@
                                }
                        }
                }
-               return $scripts . "\nmediaWiki.loader.register( " . 
FormatJson::encode( $registrations ) . " );\n";
+               return $scripts . "mediaWiki.loader.register( " . 
FormatJson::encode( $registrations ) . " );";
        }
        
        /**
@@ -327,29 +327,38 @@
                                );
                                // Special meta-information for the 'startup' 
module
                                if ( $name === 'startup' && $parameters['only'] 
=== 'scripts' ) {
-                                       $scripts .= 
self::getModuleRegistrations(
+                                       // Get all module registrations
+                                       $registration = 
self::getModuleRegistrations(
                                                $parameters['lang'], 
$parameters['skin'], $parameters['debug']
                                        );
-                                       $scripts .= "mediaWiki.config.set( " .
-                                               FormatJson::encode( array( 
'server' => $server, 'debug' => $parameters['debug'] ) ) . " );\n";
-                                       // Wrap in a closure
-                                       $scripts = "window.mediaWikiStartUp = 
function() {" . $scripts . "};";
-                                       $query = wfArrayToCGI( $parameters + 
array( 'version' => wfTimestamp(
-                                               TS_ISO_8601,
-                                               round(
-                                                       max(
-                                                               
self::$modules['jquery']->getModifiedTime(
-                                                                       
$parameters['lang'], $parameters['skin'], $parameters['debug']
+                                       // Build configuration
+                                       $config = FormatJson::encode( array( 
'server' => $server, 'debug' => $parameters['debug'] ) );
+                                       // Add a well-known start-up function
+                                       $scripts .= "window.startUp = 
function() { {$registration} mediaWiki.config.set( {$config} ); };";
+                                       // Build load query for jquery and 
mediawiki modules
+                                       $query = wfArrayToCGI( $parameters + 
array(
+                                               'modules' => implode( '|', 
array( 'jquery', 'mediawiki' ) ),
+                                               'version' => wfTimestamp(
+                                                       TS_ISO_8601,
+                                                       round(
+                                                               max(
+                                                                       
self::$modules['jquery']->getModifiedTime(
+                                                                               
$parameters['lang'], $parameters['skin'], $parameters['debug']
+                                                                       ),
+                                                                       
self::$modules['mediawiki']->getModifiedTime(
+                                                                               
$parameters['lang'], $parameters['skin'], $parameters['debug']
+                                                                       )
                                                                ),
-                                                               
self::$modules['mediawiki']->getModifiedTime(
-                                                                       
$parameters['lang'], $parameters['skin'], $parameters['debug']
-                                                               )
-                                                       ),
-                                                       -2
+                                                               -2
+                                                       )
                                                )
-                                       ) ) );
-                                       $scripts .= "document.write('<script 
type=\"text/javascript\" " .
-                                               
"src=\"{$server}?modules=jquery|mediawiki&{$query}\"></script>');";
+                                       ) );
+                                       // Build HTML code for loading jquery 
and mediawiki modules
+                                       $linkedScript = Html::linkedScript( 
"{$server}?{$query}" );
+                                       // Add code to add jquery and mediawiki 
loading code; only if the current client is compatible
+                                       $scripts .= "if ( isCompatible() ) { 
document.write( '{$linkedScript}' ); }";
+                                       // Delete the compatible function - 
it's not needed anymore
+                                       $scripts .= "delete 
window['isCompatible'];";
                                }
                        }
                        // Styles

Modified: branches/resourceloader/phase3/includes/ResourceLoaderModule.php
===================================================================
--- branches/resourceloader/phase3/includes/ResourceLoaderModule.php    
2010-09-02 19:48:16 UTC (rev 72219)
+++ branches/resourceloader/phase3/includes/ResourceLoaderModule.php    
2010-09-02 19:58:33 UTC (rev 72220)
@@ -595,7 +595,7 @@
        private $modifiedTime = null;
        
        public function getScript( $lang, $skin, $debug ) {
-               return '';
+               return file_get_contents( 'resources/startup.js' );
        }
        
        public function getModifiedTime( $lang, $skin, $debug ) {

Modified: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- branches/resourceloader/phase3/resources/mediawiki/mediawiki.js     
2010-09-02 19:48:16 UTC (rev 72219)
+++ branches/resourceloader/phase3/resources/mediawiki/mediawiki.js     
2010-09-02 19:58:33 UTC (rev 72220)
@@ -624,6 +624,8 @@
                        that.work();
                }
                
+               /* Cache document ready status */
+               
                $(document).ready( function() { ready = true; } );
        } )();
        
@@ -634,9 +636,10 @@
        
 } )( jQuery );
 
+
 /* Auto-register from pre-loaded startup scripts */
 
-if ( typeof mediaWikiStartUp === 'function' ) {
-       mediaWikiStartUp();
-       delete mediaWikiStartUp;
+if ( typeof window['startUp'] === 'function' ) {
+       window['startUp']();
+       delete window['startUp'];
 }
\ No newline at end of file

Added: branches/resourceloader/phase3/resources/startup.js
===================================================================
--- branches/resourceloader/phase3/resources/startup.js                         
(rev 0)
+++ branches/resourceloader/phase3/resources/startup.js 2010-09-02 19:58:33 UTC 
(rev 72220)
@@ -0,0 +1,30 @@
+/**
+ * This script provides a function which is run to evaluate whether or not to 
continue loading the jquery and mediawiki
+ * modules. This code should work on even the most anchient of browsers, so be 
very careful when editing.
+ */
+/**
+ * Returns false when run in a black-listed browser
+ * 
+ * This function will be deleted after it's used, so do not expand it to be 
generally useful beyond startup
+ * 
+ * jQuery has minimum requirements of:
+ * * Firefox 2.0+
+ * * Internet Explorer 6+
+ * * Safari 3+
+ * * Opera 9+
+ * * Chrome 1+
+ */
+window.isCompatible = function() {
+       // IE < 6
+       if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1 && parseFloat( 
navigator.appVersion.split( 'MSIE' )[1] ) < 6 ) {
+               return false;
+       }
+       // TODO: Firefox < 2
+       // TODO: Safari < 3
+       // TODO: Opera < 9
+       // TODO: Chrome < 1
+       return true;
+};
+/**
+ * The startUp() function will be generated and added here (at the bottom)
+ */


Property changes on: branches/resourceloader/phase3/resources/startup.js
___________________________________________________________________
Added: svn:eol-style
   + native



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to