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