r65492 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65491‎ | r65492 | r65493 >
Date:20:48, 23 April 2010
Author:dale
Status:deferred
Tags:
Comment:
* improved localization handling ( speed up by only including the current language msg in the noMediaWiki msg cache )
* style name cleanup
Modified paths:
  • /branches/js2-work/phase3/includes/DefaultSettings.php (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/loader.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)
  • /branches/js2-work/phase3/mwScriptLoader.php (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/includes/DefaultSettings.php
@@ -2863,13 +2863,6 @@
28642864 */
28652865 $wgAutoloadClasses = array();
28662866
2867 -
2868 -/*
2869 - * Array mapping JavaScript class to web path for use by the script loader.
2870 - * This is populated in AutoLoader.php.
2871 - */
2872 -$wgScriptLoaderNamedPaths = array();
2873 -
28742867 /**
28752868 * For defining the location of loader.js files of
28762869 * Extension mwEmbed modules. ( ie modules hosted inside of extensions )
Index: branches/js2-work/phase3/js/mwEmbed/loader.js
@@ -141,9 +141,9 @@
142142 "$j.fn.datePicker" : "jquery/plugins/jquery.datePicker.js",
143143 "$j.ui" : "jquery/jquery.ui/ui/ui.core.js",
144144
145 - "mw.style.redmond" : "jquery/jquery.ui/themes/redmond/jquery-ui-1.7.1.custom.css",
146 - "mw.style.smoothness" : "jquery/jquery.ui/themes/smoothness/jquery-ui-1.7.1.custom.css",
147 - "mw.style.common" : "skins/common/common.css",
 145+ "mw.style.jquery-ui-redmond" : "jquery/jquery.ui/themes/redmond/jquery-ui-1.7.1.custom.css",
 146+ "mw.style.jquery-ui-smoothness" : "jquery/jquery.ui/themes/smoothness/jquery-ui-1.7.1.custom.css",
 147+ "mw.style.mw-common" : "skins/common/common.css",
148148
149149 "mw.testLang" : "tests/testLang.js",
150150
Index: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
@@ -39,7 +39,6 @@
4040 self::$classesLoaded = true;
4141
4242 $mwEmbedAbsolutePath = ( $wgMwEmbedDirectory == '' )? $IP: $IP .'/' .$wgMwEmbedDirectory;
43 -
4443 // Add the mwEmbed localizations
4544 $wgExtensionMessagesFiles[ 'mwEmbed' ] = $mwEmbedAbsolutePath . '/languages/mwEmbed.i18n.php';
4645
@@ -73,7 +72,8 @@
7473
7574 // Get all the classes from the enabled mwEmbed modules folder
7675 foreach( self::$moduleList as $na => $moduleName){
77 - self::proccessModulePath( $mwEmbedAbsolutePath . '/modules/' . $moduleName );
 76+ $relativeSlash = ( $wgMwEmbedDirectory == '' )? '' : '/';
 77+ self::proccessModulePath( $wgMwEmbedDirectory . $relativeSlash . 'modules/' . $moduleName );
7878 }
7979
8080 // Get all the extension loader paths registered mwEmbed modules
@@ -93,7 +93,7 @@
9494 // Get the module name
9595 $moduleName = end( explode('/', $path ) );
9696
97 - // Set the directory context for js defined paths
 97+ // Set the directory context for relative js/css paths
9898 self::$directoryContext = $path;
9999
100100 // Check for the loader.js
@@ -125,7 +125,7 @@
126126 self::$combinedLoadersJs .= $fileContent;
127127
128128 preg_replace_callback(
129 - self::$classReplaceExp,
 129+ self::$classReplaceExp,
130130 'jsClassLoader::preg_classPathLoader',
131131 $fileContent
132132 );
Index: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
@@ -34,6 +34,10 @@
3535
3636 /*Localization:*/
3737 $wgEnableScriptLocalization = true;
 38+// Array to store all loaded msgs
 39+$wgMessageCache = array();
 40+// flag for loading msgs
 41+$wgLoadedMsgKeysFlag = false;
3842
3943 $mwLanguageCode = 'en';
4044 $wgLang = false;
@@ -99,6 +103,8 @@
100104
101105 /**
102106 * Copied from mediaWIki GlobalFunctions.php wfMsgGetKey
 107+ * but we return [] instead of < > since < does not
 108+ * look good in javascript msg strings
103109 *
104110 * Fetch a message string value, but don't replace any keys yet.
105111 * @param $key String
@@ -109,25 +115,40 @@
110116 * @return string
111117 * @private
112118 */
113 -function wfMsgGetKey( $msgKey, $na, $langKey=false ) {
114 - global $messages, $mwLanguageCode;
115 - if(!$langKey){
 119+function wfMsgGetKey( $msgKey, $na, $langKey = false ) {
 120+ global $wgLoadedMsgKeysFlag, $wgMessageCache, $mwLanguageCode;
 121+
 122+ if( !$langKey ){
116123 $langKey = $mwLanguageCode;
117124 }
118 - if ( isset( $messages[$mwLanguageCode] ) && isset( $messages[$langKey][$msgKey] ) ) {
119 - return $messages[$langKey][$msgKey];
 125+
 126+ // Make sure msg Keys are loaded
 127+ if( !$wgLoadedMsgKeysFlag ) {
 128+ wfLoadMsgKeys( $langKey );
 129+ }
 130+
 131+
 132+ if ( isset( $wgMessageCache[$msgKey] ) ) {
 133+ return $wgMessageCache[$msgKey];
120134 } else {
121 - return '<' . $msgKey . '>';
 135+ return '[' . $msgKey . ']';
122136 }
123137 }
124 -$wgLoadedMsgKeysFlag = false;
125 -function loadMsgKeys(){
126 - global $wgLoadedMsgKeysFlag;
127 - if( $wgLoadedMsgKeysFlag ) {
128 - return true;
 138+/**
 139+ * Load all the msg keys into $wgMessageCache
 140+ * @param $langKey String Language key to be used
 141+ */
 142+function wfLoadMsgKeys( $langKey ){
 143+ global $wgExtensionMessagesFiles, $wgMessageCache;
 144+ foreach( $wgExtensionMessagesFiles as $msgFile ){
 145+ if( !is_file( $msgFile ) ) {
 146+ throw new MWException( "Missing msgFile: " . htmlspecialchars( $msgFile ) . "\n" );
 147+ }
 148+ require( $msgFile );
 149+ // Save some time by only including the current language in the cache:
 150+ $wgMessageCache = array_merge( $wgMessageCache, $messages[ $langKey ] );
129151 }
130 - // Get the messages file:
131 - require_once( realpath( dirname( __FILE__ ) ) . '/../languages/mwEmbed.i18n.php' );
 152+ $wgLoadedMsgKeysFlag = true;
132153 }
133154
134155 /**
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -1520,8 +1520,7 @@
15211521 mw.log( 'run setup directly' );
15221522 //DOM is already ready run setup directly ( will run mwOnLoadFunctions on finish )
15231523 mw.setupMwEmbed();
1524 - }
1525 -
 1524+ }
15261525 return ;
15271526 }
15281527 // If mwReadyFlag is already "true" issue the callback directly:
@@ -1534,7 +1533,7 @@
15351534 mw.runReadyHooks = function ( ) {
15361535 // Run all the queued functions:
15371536 while( mwOnLoadFunctions.length ) {
1538 - mwOnLoadFunctions.pop()();
 1537+ mwOnLoadFunctions.shift()();
15391538 }
15401539
15411540 // Sets mwReadyFlag to true so that future addOnLoadHook calls
@@ -1631,7 +1630,7 @@
16321631 * @param {String} cssClassName Name of style sheet that has been defined
16331632 * @param {String} cssString Css Payload to be added to head of document
16341633 */
1635 - mw.addStyleString = function( cssClassName, cssString ) {
 1634+ mw.addStyleString = function( cssClassName, cssString ) {
16361635 if( mw.style[ cssClassName ] ) {
16371636 mw.log(" Style: ( " + cssClassName + ' ) already set' );
16381637 return true;
@@ -1639,8 +1638,8 @@
16401639 // Set the style to true ( to not request it again )
16411640 mw.style[ cssClassName ] = true;
16421641 // Wait for the DOM to be ready before adding in the css:
1643 - mw.ready( function() {
1644 - mw.log('Adding style:' + cssClassName +" to dom");
 1642+ mw.ready( function() {
 1643+ mw.log( 'Adding style:' + cssClassName + " to dom " );
16451644 var styleNode = document.createElement('style');
16461645 styleNode.type = "text/css";
16471646 // Use cssText or createTextNode depending on browser:
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -15,6 +15,7 @@
1616 exit();
1717 }
1818 // No cache hit, load stand alone ScriptLoader config
 19+
1920 // ( if running as a remote, mediaWiki variables are already included as part of mediaWiki
2021 require_once( realpath( dirname( __FILE__ ) ) . '/includes/noMediaWikiConfig.php' );
2122 $myScriptLoader->doScriptLoader();
@@ -22,8 +23,8 @@
2324
2425 class jsScriptLoader {
2526
26 - // The list of javascript files
27 - var $jsFileList = array();
 27+ // The list of named javascript & css files
 28+ var $namedFileList = array();
2829
2930 // The language code for the script-loader request
3031 var $langCode = '';
@@ -107,13 +108,11 @@
108109
109110 // Build the output
110111 // Swap in the appropriate language per js_file
111 - foreach ( $this->jsFileList as $classKey => $filePath ) {
112 -
 112+ foreach ( $this->namedFileList as $classKey => $filePath ) {
113113 // Get the localized script content
114114 $this->output .= $this->getLocalizedScriptText( $classKey );
115115
116 - // If the core mwEmbed class entry point add some
117 - // other "core" files:
 116+ // If the core mwEmbed class request add some other "core" files:
118117 if( $classKey == 'mwEmbed' ){
119118 // Output core components ( parts of mwEmbed that are in different files )
120119 $this->output .= jsClassLoader::getCombinedComponentJs( $this );
@@ -124,12 +123,15 @@
125124 // Output the current language class js
126125 $this->output .= jsClassLoader::getLanguageJs( $this->langCode );
127126
128 - // Output the "common" css file
129 - $this->output .= $this->getScriptText( 'mw.style.common' );
 127+ // Check that mwEmbed required style sheets are part of the request,
 128+ // if not include them here
 129+ // This is so mwEmbed requests gets basic interface css
 130+ foreach( array('mw.style.mw-common', 'mw.style.jquery-ui-redmond' ) as $styleKey ){
 131+ if( !isset( $this->namedFileList[ $styleKey ] ) ) {
 132+ $this->output .= $this->getScriptText( $styleKey );
 133+ }
 134+ }
130135
131 - // Output the jQuery ui theme css
132 - $this->output .= $this->getScriptText( 'mw.style.redmond' );
133 -
134136 // Output special IE comment tag to support special mwEmbed tags.
135137 $this->notMinifiedTopOutput .='/*@cc_on\'video source itext playlist\'.replace(/\w+/g,function(n){document.createElement(n)})@*/'."\n";
136138 }
@@ -545,7 +547,7 @@
546548
547549 // Check for the requested classes
548550 if ( $reqClassList ) {
549 - // sanitize the class list and populate jsFileList
 551+ // sanitize the class list and populate namedFileList
550552 foreach ( $reqClassList as $reqClass ) {
551553 if ( trim( $reqClass ) != '' ) {
552554 if ( substr( $reqClass, 0, 3 ) == 'WT:' ) {
@@ -565,7 +567,7 @@
566568 }
567569 }
568570 if( $doAddWT ){
569 - $this->jsFileList[$reqClass] = true;
 571+ $this->namedFileList[$reqClass] = true;
570572 $this->requestKey .= $reqClass;
571573 $this->jsvarurl = true;
572574 }
@@ -578,7 +580,7 @@
579581 if( !$filePath ){
580582 $this->errorMsg .= 'Requested class: ' . xml::escapeJsString( $reqClass ) . ' not found' . "\n";
581583 }else{
582 - $this->jsFileList[ $reqClass ] = $filePath;
 584+ $this->namedFileList[ $reqClass ] = $filePath;
583585 $this->requestKey .= $reqClass;
584586 }
585587 }
@@ -636,7 +638,7 @@
637639
638640 // Check for the requested classes
639641 if ( $reqClassList && count( $reqClassList ) > 0 ) {
640 - // Clean the class list and populate jsFileList
 642+ // Clean the class list and populate namedFileList
641643 foreach ( $reqClassList as $reqClass ) {
642644 //do some simple checks:
643645 if ( trim( $reqClass ) != '' ){
@@ -710,6 +712,7 @@
711713 global $wgScriptLoaderNamedPaths;
712714 // Make sure the class is loaded:
713715 jsClassLoader::loadClassPaths();
 716+
714717 if ( isset( $wgScriptLoaderNamedPaths[ $reqClass ] ) ) {
715718 return $wgScriptLoaderNamedPaths[ $reqClass ];
716719 } else {
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -4,7 +4,7 @@
55 */
66 var urlparts = getRemoteEmbedPath();
77 var mwEmbedHostPath = urlparts[0];
8 -var mwRemoteVersion = 'r120';
 8+var mwRemoteVersion = 'r121';
99 var mwUseScriptLoader = true;
1010
1111 // Log the mwRemote version ( will determine what version of js we get )
@@ -173,7 +173,6 @@
174174 function mwLoadPlayer( callback ){
175175 // the jsPlayerRequest includes both javascript and style sheets for the embedPlayer
176176 var jsPlayerRequest = [
177 - 'mw.style.common',
178177 'mw.EmbedPlayer',
179178 '$j.ui',
180179 'ctrlBuilder',
@@ -194,7 +193,7 @@
195194 if ( navigator.userAgent && navigator.userAgent.indexOf("Firefox") != -1 ){
196195 jsPlayerRequest.push( 'nativeEmbed' );
197196 }
198 -
 197+
199198 loadMwEmbed( jsPlayerRequest, function() {
200199 callback();
201200 });
Index: branches/js2-work/phase3/mwScriptLoader.php
@@ -24,11 +24,14 @@
2525 * http://www.gnu.org/copyleft/gpl.html
2626 */
2727
 28+// Set a constant so the script-loader knows its not being used in "stand alone mode"
 29+define( 'SCRIPTLOADER_MEDIAWIKI', true);
 30+
2831 //First do a quick static check for the cached file
29 -define('MW_CACHE_SCRIPT_CHECK', true);
3032 require_once( dirname(__FILE__) . '/js/mwEmbed/jsScriptLoader.php');
3133 $myScriptLoader = new jsScriptLoader();
3234 if( $myScriptLoader->outputFromCache() ){
 35+ // We do a simple exit call since we have not touch mediaWiki code yet
3336 exit();
3437 }
3538

Status & tagging log