r65442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65441‎ | r65442 | r65443 >
Date:20:44, 22 April 2010
Author:dale
Status:deferred
Tags:
Comment:
* some path fixes for better support of relative class names in javascript modules
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
@@ -38,19 +38,20 @@
3939 }
4040 self::$classesLoaded = true;
4141
 42+ $mwEmbedAbsolutePath = ( $wgMwEmbedDirectory == '' )? $IP: $IP .'/' .$wgMwEmbedDirectory;
 43+
4244 // Add the mwEmbed localizations
43 - $wgExtensionMessagesFiles[ 'mwEmbed' ] = $IP . '/' . $wgMwEmbedDirectory . '/languages/mwEmbed.i18n.php';
 45+ $wgExtensionMessagesFiles[ 'mwEmbed' ] = $mwEmbedAbsolutePath . '/languages/mwEmbed.i18n.php';
4446
45 -
4647 // Load javascript classes from mwEmbed.js
47 - if ( !is_file( $wgMwEmbedDirectory . '/loader.js' ) ) {
 48+ if ( !is_file( $mwEmbedAbsolutePath . '/loader.js' ) ) {
4849 // throw error no mwEmbed found
4950 throw new MWException( "mwEmbed loader.js missing check \$wgMwEmbedDirectory path\n" );
5051 return false;
5152 }
5253
5354 // Read the mwEmbed loader file:
54 - $fileContent = file_get_contents( $wgMwEmbedDirectory . '/loader.js' );
 55+ $fileContent = file_get_contents( $mwEmbedAbsolutePath . '/loader.js' );
5556
5657 // Get class paths from mwEmbed.js
5758 self::$directoryContext = $wgMwEmbedDirectory;
@@ -60,19 +61,19 @@
6162 preg_replace_callback(
6263 '/mwCoreComponentList\s*\=\s*\[(.*)\]/siU',
6364 'jsClassLoader::preg_buildComponentList',
64 - $fileContent
 65+ $fileContent
6566 );
6667
6768 // Get the list of enabled modules into $moduleList
6869 preg_replace_callback(
6970 '/mwEnabledModuleList\s*\=\s*\[(.*)\]/siU',
7071 'jsClassLoader::preg_buildModuleList',
71 - $fileContent
 72+ $fileContent
7273 );
7374
7475 // Get all the classes from the enabled mwEmbed modules folder
7576 foreach( self::$moduleList as $na => $moduleName){
76 - self::proccessModulePath( $IP . '/' . $wgMwEmbedDirectory . '/modules/' . $moduleName );
 77+ self::proccessModulePath( $mwEmbedAbsolutePath . '/modules/' . $moduleName );
7778 }
7879
7980 // Get all the extension loader paths registered mwEmbed modules
@@ -201,23 +202,24 @@
202203 * @param String $jsvar Coma delimited list of modules
203204 */
204205 private static function preg_buildModuleList( $jsvar ){
205 - global $wgMwEmbedDirectory;
 206+ global $IP, $wgMwEmbedDirectory;
206207 if(! isset( $jsvar[1] )){
207208 return false;
208209 }
209210 $moduleSet = explode(',', $jsvar[1] );
210211
 212+ $mwEmbedAbsolutePath = ( $wgMwEmbedDirectory == '' )? $IP: $IP .'/' .$wgMwEmbedDirectory;
 213+
211214 foreach( $moduleSet as $na => $moduleName ){
212215 $moduleName = str_replace( array( '../', '\'', '"'), '', trim( $moduleName ));
213216 // Check if there is there are module loader files
214 - if( is_file( $wgMwEmbedDirectory . '/modules/' . $moduleName . '/loader.js' )){
 217+ if( is_file( $mwEmbedAbsolutePath . '/modules/' . $moduleName . '/loader.js' )){
215218 array_push( self::$moduleList, $moduleName );
216219 } else {
217220 // Not valid module ( missing loader.js )
 221+ throw new MWException( "Missing module: $moduleName \n" );
218222 }
219223 }
220 - // Enabled modules is not reused.
221 - return '';
222224 }
223225 /**
224226 * Adds javascript autoloader class names and paths
@@ -232,10 +234,11 @@
233235 }
234236
235237 $jClassSet = FormatJson::decode( '{' . $jsvar[1] . '}', true );
236 - foreach ( $jClassSet as $jClass => $jPath ) {
 238+ foreach ( $jClassSet as $className => $classPath ) {
237239 // Strip $ from class (as they are stripped on URL request parameter input)
238 - $jClass = str_replace( '$', '', $jClass );
239 - $wgScriptLoaderNamedPaths[ $jClass ] = self::$directoryContext . '/' . $jPath;
 240+ $className = str_replace( '$', '', $className );
 241+ $classPath = ( self::$directoryContext == '' )? $classPath : self::$directoryContext . '/' . $classPath;
 242+ $wgScriptLoaderNamedPaths[ $className ] = $classPath;
240243 }
241244 }
242245 }
Index: branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php
@@ -11,6 +11,7 @@
1212 print "This script must be run from the command line\n";
1313 exit();
1414 }
 15+exit( 'This script has been depreciated' );
1516 define( 'MEDIAWIKI', true );
1617 // Get the scriptLoader globals:
1718 require_once( '../../jsScriptLoader.php' );
Index: branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php
@@ -3,6 +3,7 @@
44 print "This script must be run from the command line\n";
55 exit();
66 }
 7+exit( 'This script has been depreciated' );
78 $mwPath = dirname( __FILE__ ) . '/../../languages/mwEmbed.i18n.php' ;
89
910 include( $mwPath );
Index: branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php
@@ -3,6 +3,7 @@
44 print "This script must be run from the command line\n";
55 exit();
66 }
 7+exit( 'This script has been depreciated' );
78 // Merge all the modules msgs into
89
910 // First get the big list of translations
Index: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
@@ -145,10 +145,35 @@
146146 // MWException extends Exception (for noWiki we don't do anything fancy )
147147 class MWException extends Exception {
148148 }
149 -function wfSuppressWarnings(){
150 -};
151 -function wfRestoreWarnings(){
152 -};
 149+
 150+/**
 151+ * Reference-counted warning suppression
 152+ */
 153+function wfSuppressWarnings( $end = false ) {
 154+ static $suppressCount = 0;
 155+ static $originalLevel = false;
 156+
 157+ if ( $end ) {
 158+ if ( $suppressCount ) {
 159+ --$suppressCount;
 160+ if ( !$suppressCount ) {
 161+ error_reporting( $originalLevel );
 162+ }
 163+ }
 164+ } else {
 165+ if ( !$suppressCount ) {
 166+ $originalLevel = error_reporting( E_ALL & ~( E_WARNING | E_NOTICE ) );
 167+ }
 168+ ++$suppressCount;
 169+ }
 170+}
 171+
 172+/**
 173+ * Restore error level to previous value
 174+ */
 175+function wfRestoreWarnings() {
 176+ wfSuppressWarnings( true );
 177+}
153178 class Xml {
154179 public static function escapeJsString( $string ) {
155180 // See ECMA 262 section 7.8.4 for string literal format
Index: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
@@ -100,9 +100,9 @@
101101 // Setup script loader header ( to easy identify file data )
102102 if( $this->outputFormat == 'js' ) {
103103 $this->output .= 'var mwScriptLoaderDate = "' .
104 - xml::escapeJsString( date( 'c' ) ) . '";' . "\n";
 104+ xml::escapeJsString( date( 'c' ) ) . '";' . "\n";
105105 $this->output .= 'var mwScriptLoaderRequestKey = "' .
106 - xml::escapeJsString( $this->requestKey ) . '";' . "\n";
 106+ xml::escapeJsString( $this->requestKey ) . '";' . "\n";
107107 }
108108
109109 // Build the output
@@ -178,7 +178,7 @@
179179 */
180180 static private function getOnDoneCallback( ){
181181 return 'if(mw && mw.loadDone){mw.loadDone(\'' .
182 - htmlspecialchars( self::$rawClassList ) . '\');};';
 182+ htmlspecialchars( self::$rawClassList ) . '\');};';
183183 }
184184 /**
185185 * Get Minified js
@@ -234,7 +234,7 @@
235235 $cmd.= ' --js ' . $jsFileName;
236236
237237 if( $wgClosureCompilerLevel )
238 - $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel );
 238+ $cmd.= ' --compilation_level ' . wfEscapeShellArg( $wgClosureCompilerLevel );
239239
240240 // only output js ( no warnings )
241241 $cmd.= ' --warning_level QUIET';
@@ -332,8 +332,8 @@
333333 }
334334 $fileStr = $a->getContent() . "\n";
335335 $output.= ( $ext == 'css' ) ?
336 - $this->transformCssOutput( $classKey, $fileStr ) :
337 - $fileStr;
 336+ $this->transformCssOutput( $classKey, $fileStr ) :
 337+ $fileStr;
338338 return $output;
339339 }
340340 }
@@ -359,8 +359,8 @@
360360 $output .= "\n/**\n* File: " . xml::escapeJsString( $filePath ) . "\n*/\n";
361361 }
362362 $output.= ( $ext == 'css' ) ?
363 - $this->transformCssOutput( $classKey, $fileStr, $filePath ) :
364 - $fileStr;
 363+ $this->transformCssOutput( $classKey, $fileStr, $filePath ) :
 364+ $fileStr;
365365
366366 return $output;
367367 }else{
@@ -390,10 +390,12 @@
391391 global $wgScriptPath;
392392 $cssOptions[ 'prependRelativePath' ] = $wgScriptPath . '/' . dirname( $path ) . '/';
393393 } else if( strpos( $serverUri, 'jsScriptLoader.php') !== false ){
394 - // We should use an absolute url to jsScriptLoader.php
 394+ // NOTE:: We HAVE to use an absolute url remote jsScriptLoader.php entry point.
 395+ // this is because relative urls won't work when inserted into the DOM head
 396+ // ( ie we package the css with javascript )
395397 $cssOptions[ 'prependRelativePath' ] =
396 - str_replace('jsScriptLoader.php', '', $serverUri)
397 - . dirname( $path ) . '/';
 398+ str_replace('jsScriptLoader.php', '', $serverUri)
 399+ . dirname( $path ) . '/';
398400 }
399401
400402 // We always run minify to update css urls
@@ -408,7 +410,7 @@
409411 // CSS classes should be of form mw.style.{className}
410412 $cssStyleName = str_replace('mw.style.', '', $classKey );
411413 return 'mw.addStyleString("' . Xml::escapeJsString( $cssStyleName )
412 - . '", "' . Xml::escapeJsString( $cssString ) . '");' . "\n";
 414+ . '", "' . Xml::escapeJsString( $cssString ) . '");' . "\n";
413415 }
414416
415417 /**
@@ -505,7 +507,7 @@
506508
507509 // Set debug flag
508510 if ( ( isset( $_GET['debug'] ) && $_GET['debug'] == 'true' )
509 - || ( isset( $wgEnableScriptDebug ) && $wgEnableScriptDebug == true ) ) {
 511+ || ( isset( $wgEnableScriptDebug ) && $wgEnableScriptDebug == true ) ) {
510512 $this->debug = true;
511513 }
512514
@@ -672,7 +674,7 @@
673675
674676 /**
675677 * Check for the commons language hack.
676 - * ( someone had the bright idea to use language keys as message
 678+ * ( someone had the bright idea to use language keys as message
677679 * name-spaces for separate upload forms )
678680 *
679681 * @param {String} $langKey The lang key for the form
@@ -721,7 +723,7 @@
722724 }
723725
724726 /**
725 - * Retrieve the js file into a string, updates errorMsg if not retrivable.
 727+ * Retrieve the js or css file into a string, updates errorMsg if not retrivable.
726728 *
727729 * @param {String} $filePath File to get
728730 * @return {String} of the file contents
@@ -740,7 +742,6 @@
741743 $this->errorMsg .= "\nError file name must not traverse paths: " . htmlspecialchars( $filePath ) . " \n ";
742744 return false;
743745 }
744 -
745746 // Load the file
746747 wfSuppressWarnings();
747748 $str = file_get_contents( realpath( $filePath ) );
@@ -915,8 +916,8 @@
916917 }
917918
918919 /*
919 -* A simple version of HTMLFileCache so that the scriptLoader can operate stand alone
920 -*/
 920+ * A simple version of HTMLFileCache so that the scriptLoader can operate stand alone
 921+ */
921922 class simpleFileCache {
922923 var $mFileCache;
923924 var $filename = null;
@@ -951,7 +952,7 @@
952953
953954 // Check for defined files::
954955 if( is_file( $this->filename ) )
955 - return $this->filename;
 956+ return $this->filename;
956957
957958 // Check for non-config based gzip version already there?
958959 if( is_file( $this->filename . '.gz') ){
@@ -960,7 +961,7 @@
961962 }
962963 //Update the name based on the $wgUseGzip config var
963964 if ( isset($wgUseGzip) && $wgUseGzip )
964 - $this->filename.='.gz';
 965+ $this->filename.='.gz';
965966
966967 return $this->filename;
967968 }

Status & tagging log