Index: branches/MwEmbedStandAlone/ResourceLoader.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | $myResourceLoader->doResourceLoader(); |
29 | 29 | } |
30 | 30 | |
| 31 | + |
31 | 32 | class ResourceLoader { |
32 | 33 | |
33 | 34 | // The list of named javascript & css files |
— | — | @@ -811,7 +812,7 @@ |
812 | 813 | global $wgEnableScriptLocalization; |
813 | 814 | // Strip out mw.log debug lines (if not in debug mode) |
814 | 815 | if( !$this->debug ){ |
815 | | - $scriptText = preg_replace( '/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $scriptText ); |
| 816 | + $scriptText = $this->removeLogStatments( $scriptText ); |
816 | 817 | } |
817 | 818 | |
818 | 819 | // Do language swap by index: |
— | — | @@ -854,6 +855,63 @@ |
855 | 856 | // Return the javascript str unmodified if we did not transform with the localisation |
856 | 857 | return $scriptText; |
857 | 858 | } |
| 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 | + } |
858 | 916 | /* simple function to return addMessageJs without preg_replace back reference substitution */ |
859 | 917 | private static function preg_addMessageJs(){ |
860 | 918 | return self::$addMessageJs; |
Index: branches/MwEmbedStandAlone/modules/SwarmTransport/mw.SwarmTransport.js |
— | — | @@ -16,8 +16,7 @@ |
17 | 17 | // Setup local reference to embedPlayer interface |
18 | 18 | var embedPlayer = $j( '#' + swapedPlayerId ).get(0); |
19 | 19 | |
20 | | - // Setup the "embedCode" binding to swap in an updated url |
21 | | - |
| 20 | + // Setup the "embedCode" binding to swap in an updated url |
22 | 21 | $j( embedPlayer ).bind( 'checkPlayerSourcesEvent', function( event, callback ) { |
23 | 22 | // Confirm SwarmTransport add-on is available ( defines swarmTransport var ) |
24 | 23 | if( typeof window['swarmTransport'] != 'undefined' ){ |
— | — | @@ -31,7 +30,7 @@ |
32 | 31 | } ); |
33 | 32 | |
34 | 33 | // Check if we have a "recommend" binding and provide an xpi install link |
35 | | - mw.log('bind::addControlBindingsEvent'); |
| 34 | + mw.log('SwarmTransport::bind:addControlBindingsEvent'); |
36 | 35 | $j( embedPlayer ).bind( 'addControlBindingsEvent', function(){ |
37 | 36 | if( mw.getConfig( 'SwarmTransport.recommend' ) && |
38 | 37 | typeof window['swarmTransport'] == 'undefined' && |
— | — | @@ -74,8 +73,9 @@ |
75 | 74 | // Setup the torrent request: |
76 | 75 | var torrentLookupRequest = { |
77 | 76 | '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() )); |
80 | 80 | // Setup function to run in context based on callback result |
81 | 81 | $j.getJSON( |
82 | 82 | mw.getConfig( 'SwarmTransport.torrentLookupUrl' ) + '?jsonp=?', |