r70364 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70363‎ | r70364 | r70365 >
Date:22:24, 2 August 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Removed debug stripping. Made mw.log an empty function until it's extended with mediawiki.log, which is only included in debug mode. Also added debug module field, which allows a script to be added while in debug mode.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/resources/Resources.php (modified) (history)
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.log.js (added) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -84,10 +84,6 @@
8585 case 'flip-css':
8686 $result = CSSJanus::transform( $data, true, false );
8787 break;
88 - case 'strip-debug':
89 - // FIXME: Fragile
90 - $result = preg_replace( '/\n\s*mw\.log\(([^\)]*\))*\s*[\;\n]/U', "\n", $data );
91 - break;
9288 default:
9389 // Don't cache anything, just pass right through
9490 return $data;
@@ -147,7 +143,7 @@
148144 'loader' => null,
149145 'needs' => array(),
150146 'raw' => false,
151 - 'debug' => false,
 147+ 'debug' => null,
152148 ), $options );
153149 // Validate script option
154150 if ( !is_string( $options['script'] ) ) {
@@ -209,9 +205,7 @@
210206 $modules = array();
211207 foreach ( explode( '|', $request->getVal( 'modules' ) ) as $module ) {
212208 if ( isset( self::$modules[$module] ) ) {
213 - if ( !self::$modules[$module]['debug'] || $parameters['debug'] ) {
214 - $modules[] = $module;
215 - }
 209+ $modules[] = $module;
216210 }
217211 }
218212 // Use output buffering
@@ -221,8 +215,12 @@
222216 foreach ( $modules as $module ) {
223217 if ( self::$modules[$module]['raw'] ) {
224218 readfile( self::$modules[$module]['script'] );
225 - $ready[] = $module;
226219 echo "\n";
 220+ if ( $parameters['debug'] && self::$modules[$module]['debug'] ) {
 221+ readfile( self::$modules[$module]['debug'] );
 222+ echo "\n";
 223+ }
 224+ $ready[] = $module;
227225 }
228226 }
229227 // Special meta-information for the 'mediawiki' module
@@ -268,14 +266,14 @@
269267 if ( !self::$modules[$module]['raw'] ) {
270268 // Script
271269 $script = file_get_contents( self::$modules[$module]['script'] );
 270+ // Debug
 271+ if ( $parameters['debug'] && self::$modules[$module]['debug'] ) {
 272+ $script .= file_get_contents( self::$modules[$module]['debug'] );
 273+ }
272274 // Locale
273275 if ( isset( self::$modules[$module]['locales'][$parameters['lang']] ) ) {
274276 $script .= file_get_contents( self::$modules[$module]['locales'][$parameters['lang']] );
275277 }
276 - // Debug stripping - scary and probably a bad idea
277 - if ( !$parameters['debug'] ) {
278 - $script = self::filter( 'strip-debug', $script );
279 - }
280278 // Style
281279 $style = self::$modules[$module]['style'] ? file_get_contents( self::$modules[$module]['style'] ) : '';
282280 // Theme
Index: branches/resourceloader/phase3/resources/Resources.php
@@ -414,7 +414,10 @@
415415 /* MediaWiki */
416416
417417 'mediawiki' => array(
418 - 'script' => 'resources/mediawiki/mediawiki.js', 'raw' => true ),
 418+ 'script' => 'resources/mediawiki/mediawiki.js',
 419+ 'debug' => 'resources/mediawiki/mediawiki.log.js',
 420+ 'raw' => true,
 421+ ),
419422
420423 /* MediaWiki Legacy */
421424
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -36,7 +36,7 @@
3737 /*
3838 * Core MediaWiki JavaScript Library
3939 */
40 -( function() {
 40+( function( $ ) {
4141
4242 /* Constants */
4343
@@ -49,57 +49,10 @@
5050
5151 /* Methods */
5252
53 - /**
54 - * Log a string msg to the console
55 - *
56 - * All mw.log statements will be removed on minification so lots of mw.log calls will not impact performance in non-debug
57 - * mode. This is done using simple regular expressions, so the input of this function needs to not contain things like a
58 - * self-executing closure. In the case that the browser does not have a console available, one is created by appending a
59 - * <div> element to the bottom of the body and then appending a <div> element to that for each message. In the case that
60 - * the browser does have a console available
61 - *
62 - * @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
63 - * @param string string message to output to console
 53+ /*
 54+ * Dummy function which in debug mode can be replaced with a function that does something clever
6455 */
65 - this.log = function( string ) {
66 - // Allow log messages to use a configured prefix
67 - if ( mw.config.exists( 'mw.log.prefix' ) ) {
68 - string = mw.config.get( 'mw.log.prefix' ) + string;
69 - }
70 - // Try to use an existing console
71 - if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
72 - window.console.log( string );
73 - } else {
74 - // Show a log box for console-less browsers
75 - var $log = $( '#mw_log_console' );
76 - if ( !$log.length ) {
77 - $log = $( '<div id="mw_log_console"></div>' )
78 - .css( {
79 - 'position': 'absolute',
80 - 'overflow': 'auto',
81 - 'z-index': 500,
82 - 'bottom': '0px',
83 - 'left': '0px',
84 - 'right': '0px',
85 - 'height': '150px',
86 - 'background-color': 'white',
87 - 'border-top': 'solid 1px #DDDDDD'
88 - } )
89 - .appendTo( $( 'body' ) );
90 - }
91 - if ( $log.length ) {
92 - $log.append(
93 - $( '<div>' + string + '</div>' )
94 - .css( {
95 - 'border-bottom': 'solid 1px #DDDDDD',
96 - 'font-size': 'small',
97 - 'font-family': 'monospace',
98 - 'padding': '0.125em 0.25em'
99 - } )
100 - );
101 - }
102 - }
103 - };
 56+ this.log = function() { };
10457 /*
10558 * An object which allows single and multiple existence, setting and getting on a list of key / value pairs
10659 */
@@ -616,4 +569,4 @@
617570
618571 // Attach to window
619572 window.MediaWiki = window.mw = this;
620 -} )();
\ No newline at end of file
 573+} )( jQuery );
\ No newline at end of file
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.log.js
@@ -0,0 +1,63 @@
 2+/*
 3+ * User-agent detection
 4+ */
 5+
 6+( function( $, mw ) {
 7+
 8+/* Extension */
 9+
 10+$.extend( mw, {
 11+
 12+ /* Functions */
 13+
 14+ /**
 15+ * Log output to the console
 16+ *
 17+ * In the case that the browser does not have a console available, one is created by appending a <div> element to
 18+ * the bottom of the body and then appending a <div> element to that for each message.
 19+ *
 20+ * @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
 21+ * @param {string} string message to output to console
 22+ */
 23+ 'log': function( string ) {
 24+ // Allow log messages to use a configured prefix
 25+ if ( mw.config.exists( 'mw.log.prefix' ) ) {
 26+ string = mw.config.get( 'mw.log.prefix' ) + string;
 27+ }
 28+ // Try to use an existing console
 29+ if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
 30+ window.console.log( string );
 31+ } else {
 32+ // Show a log box for console-less browsers
 33+ var $log = $( '#mw_log_console' );
 34+ if ( !$log.length ) {
 35+ $log = $( '<div id="mw_log_console"></div>' )
 36+ .css( {
 37+ 'position': 'absolute',
 38+ 'overflow': 'auto',
 39+ 'z-index': 500,
 40+ 'bottom': '0px',
 41+ 'left': '0px',
 42+ 'right': '0px',
 43+ 'height': '150px',
 44+ 'background-color': 'white',
 45+ 'border-top': 'solid 1px #DDDDDD'
 46+ } )
 47+ .appendTo( $( 'body' ) );
 48+ }
 49+ if ( $log.length ) {
 50+ $log.append(
 51+ $( '<div>' + string + '</div>' )
 52+ .css( {
 53+ 'border-bottom': 'solid 1px #DDDDDD',
 54+ 'font-size': 'small',
 55+ 'font-family': 'monospace',
 56+ 'padding': '0.125em 0.25em'
 57+ } )
 58+ );
 59+ }
 60+ }
 61+ }
 62+} );
 63+
 64+} )( jQuery, MediaWiki );
\ No newline at end of file
Property changes on: branches/resourceloader/phase3/resources/mediawiki/mediawiki.log.js
___________________________________________________________________
Added: svn:eol-style
165 + native

Comments

#Comment by Nikerabbit (talk | contribs)   14:13, 3 August 2010
+ * User-agent detection

Wrong comment?

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:02, 3 August 2010

Yup, copy paste mistake. see r70388 for the fix.

Status & tagging log