http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70234
Revision: 70234 Author: dale Date: 2010-07-31 20:15:33 +0000 (Sat, 31 Jul 2010) Log Message: ----------- * improved mw.log removal ( supports basic tokeniser to avoid broken mw.log removal ) * minor log clean up for swarmTransport Modified Paths: -------------- branches/MwEmbedStandAlone/ResourceLoader.php branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js Modified: branches/MwEmbedStandAlone/ResourceLoader.php =================================================================== --- branches/MwEmbedStandAlone/ResourceLoader.php 2010-07-31 20:04:25 UTC (rev 70233) +++ branches/MwEmbedStandAlone/ResourceLoader.php 2010-07-31 20:15:33 UTC (rev 70234) @@ -27,6 +27,7 @@ $myResourceLoader->doResourceLoader(); } + class ResourceLoader { // The list of named javascript & css files @@ -811,7 +812,7 @@ global $wgEnableScriptLocalization; // Strip out mw.log debug lines (if not in debug mode) if( !$this->debug ){ - $scriptText = preg_replace( '/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $scriptText ); + $scriptText = $this->removeLogStatments( $scriptText ); } // Do language swap by index: @@ -854,6 +855,63 @@ // Return the javascript str unmodified if we did not transform with the localisation return $scriptText; } + /** + * Remove all occurances of mw.log( 'some js string or expresion' ); + * @param {string} $jsString + */ + static function removeLogStatments( $jsString ){ + $outputJs = ''; + for ( $i = 0; $i < strlen( $jsString ); $i++ ) { + // find next occurance of + preg_match( '/[\n;]\s*mw\.log\s*/', $jsString, $matches, PREG_OFFSET_CAPTURE, $i ); + // check if any matches are left: + if( count( $matches ) == 0){ + $outputJs .= substr( $jsString, $i ); + break; + } + if( count( $matches ) > 0 ){ + $startOfLogIndex = strlen( $matches[0][0] ) + $matches[0][1]; + // append everytnig up to this point: + $outputJs .= substr( $jsString, $i, ( $startOfLogIndex - strlen( $matches[0][0] ) )-$i ); + + // Increment i to position of closing ) not inside quotes + $parenthesesDepth = 0; + $ignorenext = false; + $inquote = false; + for ( $i = $startOfLogIndex; $i < strlen( $jsString ); $i++ ) { + $char = $jsString[$i]; + if ( $ignorenext ) { + $ignorenext = false; + } else { + // Search for a close ) that is not in quotes + switch( $char ) { + case '"': + $inquote = !$inquote; + break; + case '(': + if( ! $inquote){ + $parenthesesDepth++; + } + break; + case ')': + if( ! $inquote ){ + $parenthesesDepth--; + } + break; + case '\\': + if ( $inquote ) $ignorenext = true; + break; + } + // done with close parentheses search for next mw.log in outer loop: + if( $parenthesesDepth === 0 ){ + break; + } + } + } + } + } + return $outputJs; + } /* simple function to return addMessageJs without preg_replace back reference substitution */ private static function preg_addMessageJs(){ return self::$addMessageJs; Modified: branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js =================================================================== --- branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js 2010-07-31 20:04:25 UTC (rev 70233) +++ branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js 2010-07-31 20:15:33 UTC (rev 70234) @@ -16,8 +16,7 @@ // Setup local reference to embedPlayer interface var embedPlayer = $j( '#' + swapedPlayerId ).get(0); - // Setup the "embedCode" binding to swap in an updated url - + // Setup the "embedCode" binding to swap in an updated url $j( embedPlayer ).bind( 'checkPlayerSourcesEvent', function( event, callback ) { // Confirm SwarmTransport add-on is available ( defines swarmTransport var ) if( typeof window['swarmTransport'] != 'undefined' ){ @@ -31,7 +30,7 @@ } ); // Check if we have a "recommend" binding and provide an xpi install link - mw.log('bind::addControlBindingsEvent'); + mw.log('SwarmTransport::bind:addControlBindingsEvent'); $j( embedPlayer ).bind( 'addControlBindingsEvent', function(){ if( mw.getConfig( 'SwarmTransport.recommend' ) && typeof window['swarmTransport'] == 'undefined' && @@ -74,8 +73,9 @@ // Setup the torrent request: var torrentLookupRequest = { 'url' : mw.absoluteUrl( source.getSrc() ) - }; - + } + + mw.log( 'SwarmTransport:: lookup torrent url: ' + mw.getConfig( 'SwarmTransport.torrentLookupUrl' ) + "\n" + mw.absoluteUrl( source.getSrc() )); // Setup function to run in context based on callback result $j.getJSON( mw.getConfig( 'SwarmTransport.torrentLookupUrl' ) + '?jsonp=?', _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs