Merge "API: Remove deprecated response values from action=login"
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.log.js
1 /*!
2 * Logger for MediaWiki javascript.
3 * Implements the stub left by the main 'mediawiki' module.
4 *
5 * @author Michael Dale <mdale@wikimedia.org>
6 * @author Trevor Parscal <tparscal@wikimedia.org>
7 */
8
9 ( function ( mw, $ ) {
10
11 // Keep reference to the dummy placeholder from mediawiki.js
12 // The root is replaced below, but it has other methods that we need to restore.
13 var original = mw.log,
14 slice = Array.prototype.slice;
15
16 /**
17 * Logs a message to the console in debug mode.
18 *
19 * In the case the browser does not have a console API, a console is created on-the-fly by appending
20 * a `<div id="mw-log-console">` element to the bottom of the body and then appending this and future
21 * messages to that, instead of the console.
22 *
23 * @member mw.log
24 * @param {...string} msg Messages to output to console.
25 */
26 mw.log = function () {
27 // Turn arguments into an array
28 var args = slice.call( arguments ),
29 // Allow log messages to use a configured prefix to identify the source window (ie. frame)
30 prefix = mw.config.exists( 'mw.log.prefix' ) ? mw.config.get( 'mw.log.prefix' ) + '> ' : '';
31
32 // Try to use an existing console
33 // Generally we can cache this, but in this case we want to re-evaluate this as a
34 // global property live so that things like Firebug Lite can take precedence.
35 if ( window.console && window.console.log && window.console.log.apply ) {
36 args.unshift( prefix );
37 window.console.log.apply( window.console, args );
38 return;
39 }
40
41 // If there is no console, use our own log box
42 mw.loader.using( 'jquery.footHovzer', function () {
43
44 var hovzer,
45 d = new Date(),
46 // Create HH:MM:SS.MIL timestamp
47 time = ( d.getHours() < 10 ? '0' + d.getHours() : d.getHours() ) +
48 ':' + ( d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes() ) +
49 ':' + ( d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds() ) +
50 '.' + ( d.getMilliseconds() < 10 ? '00' + d.getMilliseconds() : ( d.getMilliseconds() < 100 ? '0' + d.getMilliseconds() : d.getMilliseconds() ) ),
51 $log = $( '#mw-log-console' );
52
53 if ( !$log.length ) {
54 $log = $( '<div id="mw-log-console"></div>' ).css( {
55 overflow: 'auto',
56 height: '150px',
57 backgroundColor: 'white',
58 borderTop: 'solid 2px #ADADAD'
59 } );
60 hovzer = $.getFootHovzer();
61 hovzer.$.append( $log );
62 hovzer.update();
63 }
64 $log.append(
65 $( '<div>' )
66 .css( {
67 borderBottom: 'solid 1px #DDDDDD',
68 fontSize: 'small',
69 fontFamily: 'monospace',
70 whiteSpace: 'pre-wrap',
71 padding: '0.125em 0.25em'
72 } )
73 .text( prefix + args.join( ', ' ) )
74 .prepend( '<span style="float: right;">[' + time + ']</span>' )
75 );
76 } );
77 };
78
79 // Restore original methods
80 mw.log.warn = original.warn;
81 mw.log.error = original.error;
82 mw.log.deprecate = original.deprecate;
83
84 }( mediaWiki, jQuery ) );