resourceloader: Remove elaborate dom-based console shim
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 9 May 2018 17:27:44 +0000 (18:27 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 9 May 2018 17:31:45 +0000 (18:31 +0100)
This was a hack loosely inspired by Firebug Lite, that essentially
created a footer toolbar like the one from "mediawiki.debug", and
write console messages to it, if the browser doesn't have a console
natively.

We don't currently support any browsers in JS-mode that don't have
a console feature of some kind.

I'm keeping the file for now, because it is still useful for
mw.log (not to be confused with mw.log.warn or mw.log.error) to
not do anything in production mode by default. This because there
can be significant overhead from writing to real console object,
regardless of the fact that it isn't visible in browsers by default.

Test Plan:
* Both before and after this commit,
  - On a normal page view, `mw.log("msg")` does nothing when run
    from the browser console.
  - On a page with ?debug=true, `mw.log("msg")` acts
    like `console.log("msg")` would.

Bug: T192623
Change-Id: Ifc8dd91f473c9235e1d4e27c202c97802530a272

resources/src/mediawiki/mediawiki.log.js

index 969e872..a3f3c68 100644 (file)
@@ -1,74 +1,25 @@
 /*!
- * Logger for MediaWiki javascript.
- * Implements the stub left by the main 'mediawiki' module.
+ * This file is concatenated to mediawiki.js in debug mode.
+ *
+ * See Resources.php.
  *
  * @author Michael Dale <mdale@wikimedia.org>
  * @author Trevor Parscal <tparscal@wikimedia.org>
  */
-
-( function ( mw, $ ) {
-
-       // Keep reference to the dummy placeholder from mediawiki.js
-       // The root is replaced below, but it has other methods that we need to restore.
-       var original = mw.log,
-               slice = Array.prototype.slice;
-
-       mw.log = function () {
-               // Turn arguments into an array
-               var args = slice.call( arguments ),
-                       // Allow log messages to use a configured prefix to identify the source window (ie. frame)
-                       prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
-
-               // Try to use an existing console
-               // Generally we can cache this, but in this case we want to re-evaluate this as a
-               // global property live so that things like Firebug Lite can take precedence.
-               if ( window.console && window.console.log && window.console.log.apply ) {
-                       args.unshift( prefix );
-                       window.console.log.apply( window.console, args );
-                       return;
-               }
-
-               // If there is no console, use our own log box
-               mw.loader.using( 'jquery.footHovzer', function () {
-
-                       var     hovzer,
-                               d = new Date(),
-                               // Create HH:MM:SS.MIL timestamp
-                               time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
-                                       ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
-                                       ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
-                                       '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
-                               $log = $( '#mw-log-console' );
-
-                       if ( !$log.length ) {
-                               $log = $( '<div id="mw-log-console"></div>' ).css( {
-                                       overflow: 'auto',
-                                       height: '150px',
-                                       backgroundColor: 'white',
-                                       borderTop: 'solid 2px #ADADAD'
-                               } );
-                               hovzer = $.getFootHovzer();
-                               hovzer.$.append( $log );
-                               hovzer.update();
-                       }
-                       $log.append(
-                               $( '<div>' )
-                                       .css( {
-                                               borderBottom: 'solid 1px #DDDDDD',
-                                               fontSize: 'small',
-                                               fontFamily: 'monospace',
-                                               whiteSpace: 'pre-wrap',
-                                               padding: '0.125em 0.25em'
-                                       } )
-                                       .text( prefix + args.join( ', ' ) )
-                                       .prepend( '<span style="float: right;">[' + time + ']</span>' )
-                       );
-               } );
-       };
-
-       // Restore original methods
-       mw.log.warn = original.warn;
-       mw.log.error = original.error;
-       mw.log.deprecate = original.deprecate;
-
-}( mediaWiki, jQuery ) );
+( function ( mw ) {
+       /* global console */
+       /* eslint-disable no-console */
+       var original = mw.log;
+
+       // Replace the mw.log() no-op defined in mediawiki.js, with
+       // a function that logs to console.log (if available).
+       if ( window.console && console.log && console.log.apply ) {
+               mw.log = function () {
+                       console.log.apply( console, arguments );
+               };
+               // Re-attach original sub methods
+               mw.log.warn = original.warn;
+               mw.log.error = original.error;
+               mw.log.deprecate = original.deprecate;
+       }
+}( mediaWiki ) );