r62130 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62129‎ | r62130 | r62131 >
Date:19:41, 8 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* Updates to script-loader to auto-load javascript language class with mwEmbed core
Modified paths:
  • /branches/js2-work/phase3/js/editPage.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/tests/testLang.html (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/testLang.html
@@ -10,10 +10,10 @@
1111 <script type="text/javascript" >
1212 var scriptLoaderURID = 't17';
1313 //for just setting one or two to test at a time for debug
14 -//var langKeyDebug = [ 'en', 'ar' ]; //pl
 14+var langKeyDebug = [ 'ar' ]; //pl
1515 //var langKeyDebug = [ 'az', 'da', 'pt', 'fr', 'lv', 'en'];
1616 //var langKeyDebug = ['en','az', 'da', 'pt', 'fr', 'lv', 'ga','hr','cy','mk','mt','pl','sl'];
17 -var langKeyDebug = mw.getConfig( 'languageCodeList' );
 17+//var langKeyDebug = mw.getConfig( 'languageCodeList' );
1818
1919 mw.ready( function(){
2020 //do mauall script loaders calls to test multiple languages:
Index: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
@@ -103,8 +103,20 @@
104104 $fileContent
105105 );
106106 }
107 -
108107 /**
 108+ * Get the language file javascript
 109+ * @param String $languageJs The language file javascript
 110+ */
 111+ public static function getLanguageJs( $langKey = 'en' ){
 112+ global $wgMwEmbedDirectory;
 113+ $path = $wgMwEmbedDirectory . 'includes/languages/classes/Language' . ucfirst( $langKey ) . '.js';
 114+ if( is_file( $path ) ){
 115+ $languageJs = file_get_contents( $path );
 116+ return $languageJs;
 117+ }
 118+ return '';
 119+ }
 120+ /**
109121 * Get the combined loader javascript
110122 *
111123 * @return the combined loader jss
Index: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
@@ -17,7 +17,7 @@
1818
1919 $IP = realpath( dirname( __FILE__ ) . '/../' );
2020
21 -// $wgMwEmbedDirectory becomes the root $IP
 21+// $wgMwEmbedDirectory becomes the root file system:
2222 $wgMwEmbedDirectory = '';
2323
2424 $wgUseFileCache = true;
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -76,6 +76,7 @@
7777 'debug' : false,
7878
7979 // Valid language codes ( has a file in /includes/languages/classes/Language{code}.js )
 80+ // TODO: mirror the mw language "fallback" system
8081 'languageCodeList': ['en', 'am', 'ar', 'bat_smg', 'be_tarak', 'be', 'bh',
8182 'bs', 'cs', 'cu', 'cy', 'dsb', 'fr', 'ga', 'gd', 'gv', 'he', 'hi',
8283 'hr', 'hsb', 'hy', 'ksh', 'ln', 'lt', 'lv', 'mg', 'mk', 'mo', 'mt',
@@ -83,7 +84,7 @@
8485 'sr_ec', 'sr_el', 'sr', 'ti', 'tl', 'uk', 'wa'
8586 ],
8687
87 - // Default user language is "en" Can be overwiteen by:
 88+ // Default user language is "en" Can be overwritten by:
8889 // "uselang" url param
8990 // wgUserLang global
9091 'userLanguage' : 'en',
@@ -364,7 +365,7 @@
365366 if ( tObj.param.length == 0 ) {
366367 return '';
367368 }
368 - // Restore the count ( if it got converted earlier )
 369+ // Restore the count into a Number ( if it got converted earlier )
369370 var count = mw.lang.convertNumber( tObj.arg, true );
370371
371372 // Do convertPlural call
@@ -400,9 +401,9 @@
401402 /**
402403 * Convert a number using the digitTransformTable
403404 * @param Number number to be converted
404 - * @param Bollean latin if we should return the latin type 0-10
 405+ * @param Bollean typeInt if we should return a number of type int
405406 */
406 - mw.lang.convertNumber = function( number, latin ) {
 407+ mw.lang.convertNumber = function( number, typeInt ) {
407408 if( !mw.lang.digitTransformTable )
408409 return number;
409410
@@ -410,7 +411,7 @@
411412 var transformTable = mw.lang.digitTransformTable;
412413
413414 // Check if the "restore" to latin number flag is set:
414 - if( latin ){
 415+ if( typeInt ){
415416 if( parseInt( number ) == number )
416417 return number;
417418 var tmp = [];
@@ -429,7 +430,7 @@
430431 convertedNumber += numberString[i];
431432 }
432433 }
433 - return ( latin )? parseInt( convertedNumber) : convertedNumber;
 434+ return ( typeInt )? parseInt( convertedNumber) : convertedNumber;
434435 }
435436
436437 /**
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -58,9 +58,10 @@
5959 // Setup file cache object
6060 $this->sFileCache = new simpleFileCache( $this->requestKey );
6161 if ( $this->sFileCache->isFileCached() ) {
62 - // Just output headers so we can use PHP's @readfile::
 62+ // Output headers
6363 $this->outputJsHeaders();
64 - $this->sFileCache->loadFromFileCache();
 64+ // Output cached file
 65+ $this->sFileCache->outputFile();
6566 return true;
6667 }
6768 return false;
@@ -111,7 +112,10 @@
112113
113114 // If the core mwEmbed class entry point include all the loader js
114115 if( $classKey == 'mwEmbed' ){
 116+ // Output the loaders:
115117 $this->jsout .= jsClassLoader::getCombinedLoaderJs();
 118+ // Output the current language class js
 119+ $this->jsout .= jsClassLoader::getLanguageJs( $this->langCode );
116120 }
117121 }
118122
@@ -146,12 +150,12 @@
147151 }
148152 }
149153 /**
150 - * Get the onDone javascript callback for a given class list
 154+ * Get the loadDone javascript callback for a given class list
151155 *
152156 * Enables a done loading callback for browsers like safari
153157 * that don't consistently support the <script>.onload call
154158 *
155 - * @return String
 159+ * @return String javascript to tell mwEmbed that the requested class set is loaded
156160 */
157161 static private function getOnDoneCallback( ){
158162 return 'if(mw && mw.loadDone){mw.loadDone(\'' .
@@ -184,6 +188,7 @@
185189 * Optional function to use the google closer compiler to minify js
186190 * @param {String} $js_string Javascript string to be minified
187191 * @param {String} $requestKey request key used for temporary name in closure compile
 192+ * @return minified js, or false if minification failed.
188193 */
189194 static function getClosureMinifiedJs( & $js_string, $requestKey=''){
190195 if( !is_file( $wgJavaPath ) || ! is_file( $wgClosureCompilerPath ) ){
@@ -797,9 +802,9 @@
798803 }
799804
800805 /**
801 - * Loads and outputs the file from file cache
 806+ * Loads and outputs the file from the file cache
802807 */
803 - public function loadFromFileCache() {
 808+ public function outputFile() {
804809 if ( jsScriptLoader::clientAcceptsGzip() && substr( $this->filename, -3 ) == '.gz' ) {
805810 header( 'Content-Encoding: gzip' );
806811 readfile( $this->filename );
Index: branches/js2-work/phase3/js/editPage.js
@@ -1,4 +1,4 @@
2 -/*
 2+/**
33 * JS2-style replacement for MediaWiki edit.js
44 * (right now it just supports the toolbar)
55 */
@@ -73,7 +73,7 @@
7474 mw.log( 'Failed to bind via build section bind via target:' );
7575 $j( ".tool[rel='file']" ).attr( 'title', gM( 'mwe-loading-add-media-wiz' ) );
7676 mw.load( 'AddMedia.addMediaWizard', function(){
77 - if( $j( ".tool[rel='file']" ).length != 0 ){
 77+ if( $j( ".tool[rel='file']" ).size() != 0 ){
7878 $j( ".tool[rel='file']" ).unbind().addMediaWizard( amwConf );
7979 }
8080 });

Status & tagging log