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

Revision: 62130
Author:   dale
Date:     2010-02-08 19:41:19 +0000 (Mon, 08 Feb 2010)

Log Message:
-----------
* Updates to script-loader to auto-load javascript language class with mwEmbed 
core

Modified Paths:
--------------
    branches/js2-work/phase3/js/editPage.js
    branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
    branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
    branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
    branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
    branches/js2-work/phase3/js/mwEmbed/tests/testLang.html

Modified: branches/js2-work/phase3/js/editPage.js
===================================================================
--- branches/js2-work/phase3/js/editPage.js     2010-02-08 18:54:08 UTC (rev 
62129)
+++ branches/js2-work/phase3/js/editPage.js     2010-02-08 19:41:19 UTC (rev 
62130)
@@ -1,4 +1,4 @@
-/*
+/**
  * JS2-style replacement for MediaWiki edit.js
  * (right now it just supports the toolbar)
  */
@@ -73,7 +73,7 @@
                                mw.log( 'Failed to bind via build section bind 
via target:' );
                                $j( ".tool[rel='file']" ).attr( 'title', gM( 
'mwe-loading-add-media-wiz' ) );
                                mw.load( 'AddMedia.addMediaWizard', function(){
-                                       if( $j( ".tool[rel='file']" ).length != 
0 ){
+                                       if( $j( ".tool[rel='file']" ).size() != 
0 ){
                                                $j( ".tool[rel='file']" 
).unbind().addMediaWizard( amwConf );
                                        }
                                });

Modified: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php      
2010-02-08 18:54:08 UTC (rev 62129)
+++ branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php      
2010-02-08 19:41:19 UTC (rev 62130)
@@ -103,8 +103,20 @@
                        $fileContent
                );
        }
-
        /**
+        * Get the language file javascript
+        * @param String $languageJs The language file javascript
+        */
+       public static function getLanguageJs( $langKey = 'en' ){
+               global $wgMwEmbedDirectory;
+               $path =  $wgMwEmbedDirectory . 
'includes/languages/classes/Language' . ucfirst( $langKey ) . '.js';
+               if( is_file( $path ) ){
+                       $languageJs = file_get_contents( $path );
+                       return $languageJs;
+               }
+               return '';
+       }
+       /**
         * Get the combined loader javascript
         *
         * @return the combined loader jss

Modified: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php  
2010-02-08 18:54:08 UTC (rev 62129)
+++ branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php  
2010-02-08 19:41:19 UTC (rev 62130)
@@ -17,7 +17,7 @@
 
 $IP = realpath( dirname( __FILE__ ) . '/../' );
 
-// $wgMwEmbedDirectory becomes the root $IP
+// $wgMwEmbedDirectory becomes the root file system:
 $wgMwEmbedDirectory = '';
 
 $wgUseFileCache = true;

Modified: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php      2010-02-08 
18:54:08 UTC (rev 62129)
+++ branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php      2010-02-08 
19:41:19 UTC (rev 62130)
@@ -58,9 +58,10 @@
                // Setup file cache object
                $this->sFileCache = new simpleFileCache( $this->requestKey );
                if ( $this->sFileCache->isFileCached() ) {
-                       // Just output headers so we can use PHP's @readfile::
+                       // Output headers
                        $this->outputJsHeaders();
-                       $this->sFileCache->loadFromFileCache();
+                       // Output cached file
+                       $this->sFileCache->outputFile();
                        return true;
                }
                return false;
@@ -111,7 +112,10 @@
 
                        // If the core mwEmbed class entry point include all 
the loader js
                        if( $classKey == 'mwEmbed' ){
+                               // Output the loaders:
                                $this->jsout .= 
jsClassLoader::getCombinedLoaderJs();
+                               // Output the current language class js
+                               $this->jsout .= jsClassLoader::getLanguageJs( 
$this->langCode );
                        }
                }
 
@@ -146,12 +150,12 @@
                }
        }
        /**
-        * Get the onDone javascript callback for a given class list
+        * Get the loadDone javascript callback for a given class list
         *
         * Enables a done loading callback for browsers like safari
         * that don't consistently support the <script>.onload call
         *
-        * @return String
+        * @return String javascript to tell mwEmbed that the requested class 
set is loaded
         */
        static private function getOnDoneCallback( ){
                return 'if(mw && mw.loadDone){mw.loadDone(\'' .
@@ -184,6 +188,7 @@
         * Optional function to use the google closer compiler to minify js
         * @param {String} $js_string Javascript string to be minified
         * @param {String} $requestKey request key used for temporary name in 
closure compile
+        * @return minified js, or false if minification failed.
         */
        static function getClosureMinifiedJs( & $js_string, $requestKey=''){
                if( !is_file( $wgJavaPath ) || ! is_file( 
$wgClosureCompilerPath ) ){
@@ -797,9 +802,9 @@
        }
 
        /**
-        * Loads and outputs the file from file cache
+        * Loads and outputs the file from the file cache
         */
-       public function loadFromFileCache() {
+       public function outputFile() {
                if ( jsScriptLoader::clientAcceptsGzip() && substr( 
$this->filename, -3 ) == '.gz'  ) {
                        header( 'Content-Encoding: gzip' );
                        readfile( $this->filename );

Modified: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/mwEmbed.js      2010-02-08 18:54:08 UTC 
(rev 62129)
+++ branches/js2-work/phase3/js/mwEmbed/mwEmbed.js      2010-02-08 19:41:19 UTC 
(rev 62130)
@@ -76,6 +76,7 @@
        'debug' : false,
        
        // Valid language codes ( has a file in 
/includes/languages/classes/Language{code}.js )
+       // TODO: mirror the mw language "fallback" system
        'languageCodeList': ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 
'bh',
                'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 
'hi',
                'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 
'mt',
@@ -83,7 +84,7 @@
                'sr_ec', 'sr_el', 'sr', 'ti', 'tl', 'uk', 'wa'
        ],
        
-       // Default user language is "en" Can be overwiteen by: 
+       // Default user language is "en" Can be overwritten by: 
        //      "uselang" url param 
        //      wgUserLang global  
        'userLanguage' : 'en',
@@ -364,7 +365,7 @@
                        if ( tObj.param.length == 0 ) { 
                                return ''; 
                        }
-                       // Restore the count ( if it got converted earlier )
+                       // Restore the count into a Number ( if it got 
converted earlier )
                        var count = mw.lang.convertNumber( tObj.arg, true );
                        
                        // Do convertPlural call 
@@ -400,9 +401,9 @@
        /** 
         * Convert a number using the digitTransformTable 
         * @param Number number to be converted
-        * @param Bollean latin if we should return the latin type 0-10
+        * @param Bollean typeInt if we should return a number of type int 
         */
-       mw.lang.convertNumber = function( number, latin ) {
+       mw.lang.convertNumber = function( number, typeInt ) {
                if( !mw.lang.digitTransformTable )
                        return number;
                
@@ -410,7 +411,7 @@
                var transformTable = mw.lang.digitTransformTable;
                
                // Check if the "restore" to latin number flag is set: 
-               if( latin ){                    
+               if( typeInt ){                  
                        if( parseInt( number ) == number )      
                                return number;
                        var tmp = [];
@@ -429,7 +430,7 @@
                                convertedNumber += numberString[i];
                        }
                }
-               return ( latin )? parseInt( convertedNumber) : convertedNumber;
+               return ( typeInt )? parseInt( convertedNumber) : 
convertedNumber;
        }
        
        /**

Modified: branches/js2-work/phase3/js/mwEmbed/tests/testLang.html
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/tests/testLang.html     2010-02-08 
18:54:08 UTC (rev 62129)
+++ branches/js2-work/phase3/js/mwEmbed/tests/testLang.html     2010-02-08 
19:41:19 UTC (rev 62130)
@@ -10,10 +10,10 @@
 <script type="text/javascript" >
 var scriptLoaderURID = 't17';
 //for just setting one or two to test at a time for debug
-//var langKeyDebug = [ 'en', 'ar'  ]; //pl
+var langKeyDebug = [ 'ar'  ]; //pl
 //var langKeyDebug = [ 'az', 'da', 'pt', 'fr', 'lv', 'en'];
 //var langKeyDebug = ['en','az', 'da', 'pt', 'fr', 'lv', 
'ga','hr','cy','mk','mt','pl','sl'];
-var langKeyDebug = mw.getConfig( 'languageCodeList' );
+//var langKeyDebug = mw.getConfig( 'languageCodeList' );
 
 mw.ready( function(){
        //do mauall script loaders calls to test multiple languages:



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to