2 * JavaScript for the new debug toolbar, enabled with $wgDebugToolbar
8 ( function ( $, mw
, undefined ) {
11 var hovzer
= $.getFootHovzer();
13 var debug
= mw
.Debug
= {
15 * Toolbar container element
22 * Object containing data for the debug toolbar
29 * Initializes the debugging pane
31 * @param {Object} data
33 init: function ( data
) {
38 // Insert the container into the DOM
39 hovzer
.$.append( this.$container
);
42 $( '.mw-debug-panelink' ).click( this.switchPane
);
46 * Switches between panes
48 * @todo Store cookie for last pane open
50 * @param {jQuery.Event} e
52 switchPane: function ( e
) {
53 var currentPaneId
= debug
.$container
.data( 'currentPane' ),
54 requestedPaneId
= $(this).prop( 'id' ).substr( 9 ),
55 $currentPane
= $( '#mw-debug-pane-' + currentPaneId
),
56 $requestedPane
= $( '#mw-debug-pane-' + requestedPaneId
),
59 function updateHov() {
66 $( this ).addClass( 'current ');
67 $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ');
69 // Hide the current pane
70 if ( requestedPaneId
=== currentPaneId
) {
71 $currentPane
.slideUp( updateHov
);
72 debug
.$container
.data( 'currentPane', null );
76 debug
.$container
.data( 'currentPane', requestedPaneId
);
78 if ( currentPaneId
=== undefined || currentPaneId
=== null ) {
79 $requestedPane
.slideDown( updateHov
);
82 $requestedPane
.show();
88 * Constructs the HTML for the debugging toolbar
90 buildHtml: function () {
91 var $container
, $bits
, panes
, id
;
93 $container
= $( '<div id="mw-debug-toolbar" class="mw-debug"></div>' );
95 $bits
= $( '<div class="mw-debug-bits"></div>' );
98 * Returns a jQuery element for a debug-bit div
103 function bitDiv( id
) {
104 return $( '<div>' ).attr({
105 id
: 'mw-debug-' + id
,
106 'class': 'mw-debug-bit'
112 * Returns a jQuery element for a pane link
118 function paneLabel( id
, text
) {
121 'class': 'mw-debug-panelabel',
122 href
: '#mw-debug-pane-' + id
128 * Returns a jQuery element for a debug-bit div with a for a pane link
130 * @param id CSS id snippet. Will be prefixed with 'mw-debug-'
131 * @param text Text to show
132 * @param count Optional count to show
135 function paneTriggerBitDiv( id
, text
, count
) {
137 text
= text
+ ' (' + count
+ ')';
139 return $( '<div>' ).attr({
140 id
: 'mw-debug-' + id
,
141 'class': 'mw-debug-bit mw-debug-panelink'
143 .append( paneLabel( id
, text
) )
147 paneTriggerBitDiv( 'console', 'Console', this.data
.log
.length
);
149 paneTriggerBitDiv( 'querylist', 'Queries', this.data
.queries
.length
);
151 paneTriggerBitDiv( 'debuglog', 'Debug Log', this.data
.debugLog
.length
);
153 paneTriggerBitDiv( 'request', 'Request' );
155 paneTriggerBitDiv( 'includes', 'PHP includes', this.data
.includes
.length
);
157 bitDiv( 'mwversion' )
158 .append( $( '<a href="//www.mediawiki.org/"></a>' ).text( 'MediaWiki' ) )
159 .append( ': ' + this.data
.mwVersion
);
161 bitDiv( 'phpversion' )
162 .append( $( '<a href="//www.php.net/"></a>' ).text( 'PHP' ) )
163 .append( ': ' + this.data
.phpVersion
);
166 .text( 'Time: ' + this.data
.time
.toFixed( 5 ) );
169 .text( 'Memory: ' + this.data
.memory
)
170 .append( $( '<span title="Peak usage"></span>' ).text( ' (' + this.data
.memoryPeak
+ ')' ) );
173 $bits
.appendTo( $container
);
176 console
: this.buildConsoleTable(),
177 querylist
: this.buildQueryTable(),
178 debuglog
: this.buildDebugLogTable(),
179 request
: this.buildRequestPane(),
180 includes
: this.buildIncludesPane()
183 for ( id
in panes
) {
184 if ( !panes
.hasOwnProperty( id
) ) {
190 'class': 'mw-debug-pane',
191 id
: 'mw-debug-pane-' + id
194 .appendTo( $container
);
197 this.$container
= $container
;
201 * Builds the console panel
203 buildConsoleTable: function () {
204 var $table
, entryTypeText
, i
, length
, entry
;
206 $table
= $( '<table id="mw-debug-console">' );
208 $('<colgroup>').css( 'width', /*padding=*/20 + ( 10*/
*fontSize*/
11 ) ).appendTo( $table
);
209 $('<colgroup>').appendTo( $table
);
210 $('<colgroup>').css( 'width', 350 ).appendTo( $table
);
213 entryTypeText = function( entryType
) {
214 switch ( entryType
) {
226 for ( i
= 0, length
= this.data
.log
.length
; i
< length
; i
+= 1 ) {
227 entry
= this.data
.log
[i
];
228 entry
.typeText
= entryTypeText( entry
.type
);
232 .text( entry
.typeText
)
233 .attr( 'class', 'mw-debug-console-' + entry
.type
)
235 .append( $( '<td>' ).html( entry
.msg
) )
236 .append( $( '<td>' ).text( entry
.caller
) )
246 buildQueryTable: function () {
247 var $table
, i
, length
, query
;
249 $table
= $( '<table id="mw-debug-querylist"></table>' );
252 .append( $('<th>#</th>').css( 'width', '4em' ) )
253 .append( $('<th>SQL</th>') )
254 .append( $('<th>Time</th>').css( 'width', '8em' ) )
255 .append( $('<th>Call</th>').css( 'width', '12em' ) )
258 for ( i
= 0, length
= this.data
.queries
.length
; i
< length
; i
+= 1 ) {
259 query
= this.data
.queries
[i
];
262 .append( $( '<td>' ).text( i
+ 1 ) )
263 .append( $( '<td>' ).text( query
.sql
) )
264 .append( $( '<td class="stats">' ).text( ( query
.time
* 1000 ).toFixed( 4 ) + 'ms' ) )
265 .append( $( '<td>' ).text( query
['function'] ) )
274 * Legacy debug log pane
276 buildDebugLogTable: function () {
277 var $list
, i
, length
, line
;
280 for ( i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
+= 1 ) {
281 line
= this.data
.debugLog
[i
];
283 .html( mw
.html
.escape( line
).replace( /\n/g, "<br />\n" ) )
291 * Request information pane
293 buildRequestPane: function () {
295 function buildTable( title
, data
) {
296 var $unit
, $table
, key
;
298 $unit
= $( '<div>' ).append( $( '<h2>' ).text( title
) );
300 $table
= $( '<table>' ).appendTo( $unit
);
303 .html( '<th>Key</th><th>Value</th>' )
306 for ( key
in data
) {
307 if ( !data
.hasOwnProperty( key
) ) {
312 .append( $( '<th>' ).text( key
) )
313 .append( $( '<td>' ).text( data
[key
] ) )
321 .text( this.data
.request
.method
+ ' ' + this.data
.request
.url
)
322 .append( buildTable( 'Headers', this.data
.request
.headers
) )
323 .append( buildTable( 'Parameters', this.data
.request
.params
) );
327 * Included files pane
329 buildIncludesPane: function () {
330 var $table
, i
, length
, file
;
332 $table
= $( '<table>' );
334 for ( i
= 0, length
= this.data
.includes
.length
; i
< length
; i
+= 1 ) {
335 file
= this.data
.includes
[i
];
337 .append( $( '<td>' ).text( file
.name
) )
338 .append( $( '<td class="nr">' ).text( file
.size
) )
346 } )( jQuery
, mediaWiki
);