r69467 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69466‎ | r69467 | r69468 >
Date:06:29, 17 July 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Greatly simplified the way debug mode is handled
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/resources/Resources.php (modified) (history)
  • /branches/resourceloader/phase3/resources/base/mw.js (modified) (history)
  • /branches/resourceloader/phase3/resources/base/mw/mw.debug.js (deleted) (history)
  • /branches/resourceloader/phase3/resources/test/index.html (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -253,6 +253,7 @@
254254 foreach ( $modules as $module ) {
255255 if ( static::$modules[$module]['raw'] ) {
256256 readfile( static::$modules[$module]['script'] );
 257+ echo "\n";
257258 }
258259 }
259260 // Special meta-information for the 'mw' module
@@ -267,7 +268,12 @@
268269 // Include each loader once
269270 foreach ( array_unique( $loaders ) as $loader ) {
270271 readfile( $loader );
 272+ echo "\n";
271273 }
 274+ // Configure debug mode on server
 275+ if ( $parameters['debug'] ) {
 276+ echo "mw.debug = true;\n";
 277+ }
272278 /*
273279 * Skin::makeGlobalVariablesScript needs to be modified so that we still output the globals for now, but also
274280 * put them into the initial payload like this:
@@ -300,7 +306,7 @@
301307 // Messages
302308 $messages = isset( $blobs[$module] ) ? $blobs[$module] : '{}';
303309 // Output
304 - echo "mw.loader.implement(\n'{$module}', function() { {$script} }, '{$style}', {$messages}\n);\n";
 310+ echo "mw.loader.implement( '{$module}', function() {\n{$script}\n}, '{$style}', {$messages} );\n";
305311 }
306312 }
307313 // Set headers -- when we support CSS only mode, this might change!
Index: branches/resourceloader/phase3/resources/test/index.html
@@ -8,8 +8,8 @@
99 color: white;
1010 }
1111 </style>
12 - <script type="text/javascript" src="../../load.php?modules=jquery|mw"></script>
13 - <script type="text/javascript" src="../../load.php?modules=mw.util|test"></script>
 12+ <script type="text/javascript" src="../../load.php?modules=jquery|mw&debug=1"></script>
 13+ <script type="text/javascript" src="../../load.php?modules=mw.util|test&debug=1"></script>
1414 <script>
1515 mw.config.set( 'wgScriptPath', '../..' );
1616 </script>
Index: branches/resourceloader/phase3/resources/Resources.php
@@ -13,11 +13,6 @@
1414 'script' => 'resources/base/mw/mw.util.js',
1515 'raw' => true,
1616 ),
17 - 'mw.debug' => array(
18 - 'script' => 'resources/base/mw/mw.debug.js',
19 - 'raw' => true,
20 - 'debug' => true
21 - ),
2217 'test' => array(
2318 'script' => 'resources/test/test.js',
2419 'loader' => 'resources/test/loader.js',
Index: branches/resourceloader/phase3/resources/base/mw/mw.debug.js
@@ -1,56 +0,0 @@
2 -/**
3 - * Debug system
4 - */
5 -
6 -window.mw.debug = true;
7 -/**
8 -* Log a string msg to the console
9 -*
10 -* All mw.log statements will be removed on minification so lots of mw.log calls will not impact performance in non-debug
11 -* mode. This is done using simple regular expressions, so the input of this function needs to not contain things like a
12 -* self-executing closure. In the case that the browser does not have a console available, one is created by appending a
13 -* <div> element to the bottom of the body and then appending a <div> element to that for each message. In the case that
14 -* the browser does have a console available
15 -*
16 -* @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
17 -* @param {String} string String to output to console
18 -*/
19 -window.mw.log = function( string ) {
20 - // Allow log messages to use a configured prefix
21 - if ( mw.config.exists( 'mw.log.prefix' ) ) {
22 - string = mw.config.get( 'mw.log.prefix' ) + string;
23 - }
24 - // Try to use an existing console
25 - if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
26 - window.console.log( string );
27 - } else {
28 - // Show a log box for console-less browsers
29 - var $log = $( '#mw_log_console' );
30 - if ( !$log.length ) {
31 - $log = $( '<div id="mw_log_console"></div>' )
32 - .css( {
33 - 'position': 'absolute',
34 - 'overflow': 'auto',
35 - 'z-index': 500,
36 - 'bottom': '0px',
37 - 'left': '0px',
38 - 'right': '0px',
39 - 'height': '150px',
40 - 'background-color': 'white',
41 - 'border-top': 'solid 1px #DDDDDD'
42 - } )
43 - .appendTo( $( 'body' ) );
44 - }
45 - if ( $log.length ) {
46 - $log.append(
47 - $( '<div>' + string + '</div>' )
48 - .css( {
49 - 'border-bottom': 'solid 1px #DDDDDD',
50 - 'font-size': 'small',
51 - 'font-family': 'monospace',
52 - 'padding': '0.125em 0.25em'
53 - } )
54 - );
55 - }
56 - }
57 -};
\ No newline at end of file
Index: branches/resourceloader/phase3/resources/base/mw.js
@@ -437,7 +437,7 @@
438438 }
439439 } );
440440 /*
441 - * Read-write access to site and user configurations
 441+ * Site and user configurations
442442 */
443443 mw.config = new mw.prototypes.Collection();
444444 /*
@@ -445,6 +445,60 @@
446446 */
447447 mw.loader = new mw.prototypes.ResourceLoader();
448448 /*
449 - * Provides read-write access to localizations
 449+ * Localization system
450450 */
451 -mw.msg = new mw.prototypes.Language();
\ No newline at end of file
 451+mw.msg = new mw.prototypes.Language();
 452+/*
 453+ * Debug logging
 454+ */
 455+/**
 456+* Log a string msg to the console
 457+*
 458+* All mw.log statements will be removed on minification so lots of mw.log calls will not impact performance in non-debug
 459+* mode. This is done using simple regular expressions, so the input of this function needs to not contain things like a
 460+* self-executing closure. In the case that the browser does not have a console available, one is created by appending a
 461+* <div> element to the bottom of the body and then appending a <div> element to that for each message. In the case that
 462+* the browser does have a console available
 463+*
 464+* @author Michael Dale <mdale@wikimedia.org>, Trevor Parscal <tparscal@wikimedia.org>
 465+* @param {String} string String to output to console
 466+*/
 467+window.mw.log = function( string ) {
 468+ // Allow log messages to use a configured prefix
 469+ if ( mw.config.exists( 'mw.log.prefix' ) ) {
 470+ string = mw.config.get( 'mw.log.prefix' ) + string;
 471+ }
 472+ // Try to use an existing console
 473+ if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) {
 474+ window.console.log( string );
 475+ } else {
 476+ // Show a log box for console-less browsers
 477+ var $log = $( '#mw_log_console' );
 478+ if ( !$log.length ) {
 479+ $log = $( '<div id="mw_log_console"></div>' )
 480+ .css( {
 481+ 'position': 'absolute',
 482+ 'overflow': 'auto',
 483+ 'z-index': 500,
 484+ 'bottom': '0px',
 485+ 'left': '0px',
 486+ 'right': '0px',
 487+ 'height': '150px',
 488+ 'background-color': 'white',
 489+ 'border-top': 'solid 1px #DDDDDD'
 490+ } )
 491+ .appendTo( $( 'body' ) );
 492+ }
 493+ if ( $log.length ) {
 494+ $log.append(
 495+ $( '<div>' + string + '</div>' )
 496+ .css( {
 497+ 'border-bottom': 'solid 1px #DDDDDD',
 498+ 'font-size': 'small',
 499+ 'font-family': 'monospace',
 500+ 'padding': '0.125em 0.25em'
 501+ } )
 502+ );
 503+ }
 504+ }
 505+};
\ No newline at end of file

Comments

#Comment by Catrope (talk | contribs)   19:10, 19 July 2010
+			// Configure debug mode on server
+			if ( $parameters['debug'] ) {
+				echo "mw.debug = true;\n";
+			}

Surely you meant to say 'client'?

#Comment by Catrope (talk | contribs)   19:12, 19 July 2010

I disapprove of this revision on principle. We're sticking more and more code (debug logger) in the base rather than loading it on-demand. This slows things down all around. I see no reason why we couldn't go back to loading a special debug module like we did before.

#Comment by Trevor Parscal (WMF) (talk | contribs)   18:19, 12 October 2010

r70364 resolves this.

Status & tagging log