http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65442
Revision: 65442
Author: dale
Date: 2010-04-22 20:44:53 +0000 (Thu, 22 Apr 2010)
Log Message:
-----------
* some path fixes for better support of relative class names in javascript
modules
Modified Paths:
--------------
branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php
branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
Modified: branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
2010-04-22 20:21:30 UTC (rev 65441)
+++ branches/js2-work/phase3/js/mwEmbed/includes/jsClassLoader.php
2010-04-22 20:44:53 UTC (rev 65442)
@@ -38,19 +38,20 @@
}
self::$classesLoaded = true;
+ $mwEmbedAbsolutePath = ( $wgMwEmbedDirectory == '' )? $IP: $IP
.'/' .$wgMwEmbedDirectory;
+
// Add the mwEmbed localizations
- $wgExtensionMessagesFiles[ 'mwEmbed' ] = $IP . '/' .
$wgMwEmbedDirectory . '/languages/mwEmbed.i18n.php';
+ $wgExtensionMessagesFiles[ 'mwEmbed' ] = $mwEmbedAbsolutePath .
'/languages/mwEmbed.i18n.php';
-
// Load javascript classes from mwEmbed.js
- if ( !is_file( $wgMwEmbedDirectory . '/loader.js' ) ) {
+ if ( !is_file( $mwEmbedAbsolutePath . '/loader.js' ) ) {
// throw error no mwEmbed found
throw new MWException( "mwEmbed loader.js missing check
\$wgMwEmbedDirectory path\n" );
return false;
}
// Read the mwEmbed loader file:
- $fileContent = file_get_contents( $wgMwEmbedDirectory .
'/loader.js' );
+ $fileContent = file_get_contents( $mwEmbedAbsolutePath .
'/loader.js' );
// Get class paths from mwEmbed.js
self::$directoryContext = $wgMwEmbedDirectory;
@@ -60,19 +61,19 @@
preg_replace_callback(
'/mwCoreComponentList\s*\=\s*\[(.*)\]/siU',
'jsClassLoader::preg_buildComponentList',
- $fileContent
+ $fileContent
);
// Get the list of enabled modules into $moduleList
preg_replace_callback(
'/mwEnabledModuleList\s*\=\s*\[(.*)\]/siU',
'jsClassLoader::preg_buildModuleList',
- $fileContent
+ $fileContent
);
// Get all the classes from the enabled mwEmbed modules folder
foreach( self::$moduleList as $na => $moduleName){
- self::proccessModulePath( $IP . '/' .
$wgMwEmbedDirectory . '/modules/' . $moduleName );
+ self::proccessModulePath( $mwEmbedAbsolutePath .
'/modules/' . $moduleName );
}
// Get all the extension loader paths registered mwEmbed modules
@@ -201,23 +202,24 @@
* @param String $jsvar Coma delimited list of modules
*/
private static function preg_buildModuleList( $jsvar ){
- global $wgMwEmbedDirectory;
+ global $IP, $wgMwEmbedDirectory;
if(! isset( $jsvar[1] )){
return false;
}
$moduleSet = explode(',', $jsvar[1] );
+ $mwEmbedAbsolutePath = ( $wgMwEmbedDirectory == '' )? $IP: $IP
.'/' .$wgMwEmbedDirectory;
+
foreach( $moduleSet as $na => $moduleName ){
$moduleName = str_replace( array( '../', '\'', '"'),
'', trim( $moduleName ));
// Check if there is there are module loader files
- if( is_file( $wgMwEmbedDirectory . '/modules/' .
$moduleName . '/loader.js' )){
+ if( is_file( $mwEmbedAbsolutePath . '/modules/' .
$moduleName . '/loader.js' )){
array_push( self::$moduleList, $moduleName );
} else {
// Not valid module ( missing loader.js )
+ throw new MWException( "Missing module:
$moduleName \n" );
}
}
- // Enabled modules is not reused.
- return '';
}
/**
* Adds javascript autoloader class names and paths
@@ -232,10 +234,11 @@
}
$jClassSet = FormatJson::decode( '{' . $jsvar[1] . '}', true );
- foreach ( $jClassSet as $jClass => $jPath ) {
+ foreach ( $jClassSet as $className => $classPath ) {
// Strip $ from class (as they are stripped on URL
request parameter input)
- $jClass = str_replace( '$', '', $jClass );
- $wgScriptLoaderNamedPaths[ $jClass ] =
self::$directoryContext . '/' . $jPath;
+ $className = str_replace( '$', '', $className );
+ $classPath = ( self::$directoryContext == '' )?
$classPath : self::$directoryContext . '/' . $classPath;
+ $wgScriptLoaderNamedPaths[ $className ] = $classPath;
}
}
}
Modified:
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php
===================================================================
---
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php
2010-04-22 20:21:30 UTC (rev 65441)
+++
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/clearMwEmbedVars.php
2010-04-22 20:44:53 UTC (rev 65442)
@@ -3,6 +3,7 @@
print "This script must be run from the command line\n";
exit();
}
+exit( 'This script has been depreciated' );
$mwPath = dirname( __FILE__ ) . '/../../languages/mwEmbed.i18n.php' ;
include( $mwPath );
Modified:
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php
===================================================================
---
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php
2010-04-22 20:21:30 UTC (rev 65441)
+++
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/mergeJavascriptMsg.php
2010-04-22 20:44:53 UTC (rev 65442)
@@ -11,6 +11,7 @@
print "This script must be run from the command line\n";
exit();
}
+exit( 'This script has been depreciated' );
define( 'MEDIAWIKI', true );
// Get the scriptLoader globals:
require_once( '../../jsScriptLoader.php' );
Modified:
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php
===================================================================
---
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php
2010-04-22 20:21:30 UTC (rev 65441)
+++
branches/js2-work/phase3/js/mwEmbed/includes/maintenance/moveMsgToModule.php
2010-04-22 20:44:53 UTC (rev 65442)
@@ -3,6 +3,7 @@
print "This script must be run from the command line\n";
exit();
}
+exit( 'This script has been depreciated' );
// Merge all the modules msgs into
// First get the big list of translations
Modified: branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
2010-04-22 20:21:30 UTC (rev 65441)
+++ branches/js2-work/phase3/js/mwEmbed/includes/noMediaWikiConfig.php
2010-04-22 20:44:53 UTC (rev 65442)
@@ -145,10 +145,35 @@
// MWException extends Exception (for noWiki we don't do anything fancy )
class MWException extends Exception {
}
-function wfSuppressWarnings(){
-};
-function wfRestoreWarnings(){
-};
+
+/**
+ * Reference-counted warning suppression
+ */
+function wfSuppressWarnings( $end = false ) {
+ static $suppressCount = 0;
+ static $originalLevel = false;
+
+ if ( $end ) {
+ if ( $suppressCount ) {
+ --$suppressCount;
+ if ( !$suppressCount ) {
+ error_reporting( $originalLevel );
+ }
+ }
+ } else {
+ if ( !$suppressCount ) {
+ $originalLevel = error_reporting( E_ALL & ~( E_WARNING
| E_NOTICE ) );
+ }
+ ++$suppressCount;
+ }
+}
+
+/**
+ * Restore error level to previous value
+ */
+function wfRestoreWarnings() {
+ wfSuppressWarnings( true );
+}
class Xml {
public static function escapeJsString( $string ) {
// See ECMA 262 section 7.8.4 for string literal format
Modified: branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php
===================================================================
--- branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php 2010-04-22
20:21:30 UTC (rev 65441)
+++ branches/js2-work/phase3/js/mwEmbed/jsScriptLoader.php 2010-04-22
20:44:53 UTC (rev 65442)
@@ -100,9 +100,9 @@
// Setup script loader header ( to easy identify file data )
if( $this->outputFormat == 'js' ) {
$this->output .= 'var mwScriptLoaderDate = "' .
- xml::escapeJsString( date( 'c' ) ) . '";' .
"\n";
+ xml::escapeJsString( date( 'c' ) ) . '";' . "\n";
$this->output .= 'var mwScriptLoaderRequestKey = "' .
- xml::escapeJsString( $this->requestKey ) . '";'
. "\n";
+ xml::escapeJsString( $this->requestKey ) . '";' . "\n";
}
// Build the output
@@ -178,7 +178,7 @@
*/
static private function getOnDoneCallback( ){
return 'if(mw && mw.loadDone){mw.loadDone(\'' .
- htmlspecialchars(
self::$rawClassList ) . '\');};';
+ htmlspecialchars( self::$rawClassList ) . '\');};';
}
/**
* Get Minified js
@@ -234,7 +234,7 @@
$cmd.= ' --js ' . $jsFileName;
if( $wgClosureCompilerLevel )
- $cmd.= ' --compilation_level ' . wfEscapeShellArg(
$wgClosureCompilerLevel );
+ $cmd.= ' --compilation_level ' . wfEscapeShellArg(
$wgClosureCompilerLevel );
// only output js ( no warnings )
$cmd.= ' --warning_level QUIET';
@@ -332,8 +332,8 @@
}
$fileStr = $a->getContent() . "\n";
$output.= ( $ext == 'css' ) ?
- $this->transformCssOutput(
$classKey, $fileStr ) :
- $fileStr;
+ $this->transformCssOutput( $classKey,
$fileStr ) :
+ $fileStr;
return $output;
}
}
@@ -359,8 +359,8 @@
$output .= "\n/**\n* File: " .
xml::escapeJsString( $filePath ) . "\n*/\n";
}
$output.= ( $ext == 'css' ) ?
- $this->transformCssOutput( $classKey,
$fileStr, $filePath ) :
- $fileStr;
+ $this->transformCssOutput( $classKey, $fileStr,
$filePath ) :
+ $fileStr;
return $output;
}else{
@@ -390,10 +390,12 @@
global $wgScriptPath;
$cssOptions[ 'prependRelativePath' ] = $wgScriptPath .
'/' . dirname( $path ) . '/';
} else if( strpos( $serverUri, 'jsScriptLoader.php') !== false
){
- // We should use an absolute url to jsScriptLoader.php
+ // NOTE:: We HAVE to use an absolute url remote
jsScriptLoader.php entry point.
+ // this is because relative urls won't work when
inserted into the DOM head
+ // ( ie we package the css with javascript )
$cssOptions[ 'prependRelativePath' ] =
- str_replace('jsScriptLoader.php', '',
$serverUri)
- . dirname( $path ) . '/';
+ str_replace('jsScriptLoader.php', '', $serverUri)
+ . dirname( $path ) . '/';
}
// We always run minify to update css urls
@@ -408,7 +410,7 @@
// CSS classes should be of form mw.style.{className}
$cssStyleName = str_replace('mw.style.', '', $classKey );
return 'mw.addStyleString("' . Xml::escapeJsString(
$cssStyleName )
- . '", "' . Xml::escapeJsString(
$cssString ) . '");' . "\n";
+ . '", "' . Xml::escapeJsString( $cssString ) . '");' . "\n";
}
/**
@@ -505,7 +507,7 @@
// Set debug flag
if ( ( isset( $_GET['debug'] ) && $_GET['debug'] == 'true' )
- || ( isset( $wgEnableScriptDebug ) &&
$wgEnableScriptDebug == true ) ) {
+ || ( isset( $wgEnableScriptDebug ) && $wgEnableScriptDebug ==
true ) ) {
$this->debug = true;
}
@@ -672,7 +674,7 @@
/**
* Check for the commons language hack.
- * ( someone had the bright idea to use language keys as message
+ * ( someone had the bright idea to use language keys as message
* name-spaces for separate upload forms )
*
* @param {String} $langKey The lang key for the form
@@ -721,7 +723,7 @@
}
/**
- * Retrieve the js file into a string, updates errorMsg if not
retrivable.
+ * Retrieve the js or css file into a string, updates errorMsg if not
retrivable.
*
* @param {String} $filePath File to get
* @return {String} of the file contents
@@ -740,7 +742,6 @@
$this->errorMsg .= "\nError file name must not traverse
paths: " . htmlspecialchars( $filePath ) . " \n ";
return false;
}
-
// Load the file
wfSuppressWarnings();
$str = file_get_contents( realpath( $filePath ) );
@@ -915,8 +916,8 @@
}
/*
-* A simple version of HTMLFileCache so that the scriptLoader can operate
stand alone
-*/
+ * A simple version of HTMLFileCache so that the scriptLoader can operate
stand alone
+ */
class simpleFileCache {
var $mFileCache;
var $filename = null;
@@ -951,7 +952,7 @@
// Check for defined files::
if( is_file( $this->filename ) )
- return $this->filename;
+ return $this->filename;
// Check for non-config based gzip version already there?
if( is_file( $this->filename . '.gz') ){
@@ -960,7 +961,7 @@
}
//Update the name based on the $wgUseGzip config var
if ( isset($wgUseGzip) && $wgUseGzip )
- $this->filename.='.gz';
+ $this->filename.='.gz';
return $this->filename;
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs