r70234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70233‎ | r70234 | r70235 >
Date:20:15, 31 July 2010
Author:dale
Status:deferred
Tags:
Comment:
* 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 (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/ResourceLoader.php
@@ -27,6 +27,7 @@
2828 $myResourceLoader->doResourceLoader();
2929 }
3030
 31+
3132 class ResourceLoader {
3233
3334 // The list of named javascript & css files
@@ -811,7 +812,7 @@
812813 global $wgEnableScriptLocalization;
813814 // Strip out mw.log debug lines (if not in debug mode)
814815 if( !$this->debug ){
815 - $scriptText = preg_replace( '/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $scriptText );
 816+ $scriptText = $this->removeLogStatments( $scriptText );
816817 }
817818
818819 // Do language swap by index:
@@ -854,6 +855,63 @@
855856 // Return the javascript str unmodified if we did not transform with the localisation
856857 return $scriptText;
857858 }
 859+ /**
 860+ * Remove all occurances of mw.log( 'some js string or expresion' );
 861+ * @param {string} $jsString
 862+ */
 863+ static function removeLogStatments( $jsString ){
 864+ $outputJs = '';
 865+ for ( $i = 0; $i < strlen( $jsString ); $i++ ) {
 866+ // find next occurance of
 867+ preg_match( '/[\n;]\s*mw\.log\s*/', $jsString, $matches, PREG_OFFSET_CAPTURE, $i );
 868+ // check if any matches are left:
 869+ if( count( $matches ) == 0){
 870+ $outputJs .= substr( $jsString, $i );
 871+ break;
 872+ }
 873+ if( count( $matches ) > 0 ){
 874+ $startOfLogIndex = strlen( $matches[0][0] ) + $matches[0][1];
 875+ // append everytnig up to this point:
 876+ $outputJs .= substr( $jsString, $i, ( $startOfLogIndex - strlen( $matches[0][0] ) )-$i );
 877+
 878+ // Increment i to position of closing ) not inside quotes
 879+ $parenthesesDepth = 0;
 880+ $ignorenext = false;
 881+ $inquote = false;
 882+ for ( $i = $startOfLogIndex; $i < strlen( $jsString ); $i++ ) {
 883+ $char = $jsString[$i];
 884+ if ( $ignorenext ) {
 885+ $ignorenext = false;
 886+ } else {
 887+ // Search for a close ) that is not in quotes
 888+ switch( $char ) {
 889+ case '"':
 890+ $inquote = !$inquote;
 891+ break;
 892+ case '(':
 893+ if( ! $inquote){
 894+ $parenthesesDepth++;
 895+ }
 896+ break;
 897+ case ')':
 898+ if( ! $inquote ){
 899+ $parenthesesDepth--;
 900+ }
 901+ break;
 902+ case '\\':
 903+ if ( $inquote ) $ignorenext = true;
 904+ break;
 905+ }
 906+ // done with close parentheses search for next mw.log in outer loop:
 907+ if( $parenthesesDepth === 0 ){
 908+ break;
 909+ }
 910+ }
 911+ }
 912+ }
 913+ }
 914+ return $outputJs;
 915+ }
858916 /* simple function to return addMessageJs without preg_replace back reference substitution */
859917 private static function preg_addMessageJs(){
860918 return self::$addMessageJs;
Index: branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js
@@ -16,8 +16,7 @@
1717 // Setup local reference to embedPlayer interface
1818 var embedPlayer = $j( '#' + swapedPlayerId ).get(0);
1919
20 - // Setup the "embedCode" binding to swap in an updated url
21 -
 20+ // Setup the "embedCode" binding to swap in an updated url
2221 $j( embedPlayer ).bind( 'checkPlayerSourcesEvent', function( event, callback ) {
2322 // Confirm SwarmTransport add-on is available ( defines swarmTransport var )
2423 if( typeof window['swarmTransport'] != 'undefined' ){
@@ -31,7 +30,7 @@
3231 } );
3332
3433 // Check if we have a "recommend" binding and provide an xpi install link
35 - mw.log('bind::addControlBindingsEvent');
 34+ mw.log('SwarmTransport::bind:addControlBindingsEvent');
3635 $j( embedPlayer ).bind( 'addControlBindingsEvent', function(){
3736 if( mw.getConfig( 'SwarmTransport.recommend' ) &&
3837 typeof window['swarmTransport'] == 'undefined' &&
@@ -74,8 +73,9 @@
7574 // Setup the torrent request:
7675 var torrentLookupRequest = {
7776 'url' : mw.absoluteUrl( source.getSrc() )
78 - };
79 -
 77+ }
 78+
 79+ mw.log( 'SwarmTransport:: lookup torrent url: ' + mw.getConfig( 'SwarmTransport.torrentLookupUrl' ) + "\n" + mw.absoluteUrl( source.getSrc() ));
8080 // Setup function to run in context based on callback result
8181 $j.getJSON(
8282 mw.getConfig( 'SwarmTransport.torrentLookupUrl' ) + '?jsonp=?',

Status & tagging log