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
133 function paneTriggerBitDiv( id
, text
) {
134 return $( '<div>' ).attr({
135 id
: 'mw-debug-' + id
,
136 'class': 'mw-debug-bit mw-debug-panelink'
138 .append( paneLabel( id
, text
) )
142 paneTriggerBitDiv( 'console', 'Console (' + this.data
.log
.length
+ ')' );
144 paneTriggerBitDiv( 'querylist', 'Queries: ' + this.data
.queries
.length
);
146 paneTriggerBitDiv( 'debuglog', 'Debug Log (' + this.data
.debugLog
.length
+ ' lines)' );
148 paneTriggerBitDiv( 'request', 'Request' );
150 paneTriggerBitDiv( 'includes', this.data
.includes
.length
+ ' Files Included' );
152 bitDiv( 'mwversion' )
153 .append( $( '<a href="//www.mediawiki.org/"></a>' ).text( 'MediaWiki' ) )
154 .append( ': ' + this.data
.mwVersion
);
156 bitDiv( 'phpversion' )
157 .append( $( '<a href="//www.php.net/"></a>' ).text( 'PHP' ) )
158 .append( ': ' + this.data
.phpVersion
);
161 .text( 'Time: ' + this.data
.time
.toFixed( 5 ) );
164 .text( 'Memory: ' + this.data
.memory
)
165 .append( $( '<span title="Peak usage"></span>' ).text( ' (' + this.data
.memoryPeak
+ ')' ) );
168 $bits
.appendTo( $container
);
171 console
: this.buildConsoleTable(),
172 querylist
: this.buildQueryTable(),
173 debuglog
: this.buildDebugLogTable(),
174 request
: this.buildRequestPane(),
175 includes
: this.buildIncludesPane()
178 for ( id
in panes
) {
179 if ( !panes
.hasOwnProperty( id
) ) {
185 'class': 'mw-debug-pane',
186 id
: 'mw-debug-pane-' + id
189 .appendTo( $container
);
192 this.$container
= $container
;
196 * Builds the console panel
198 buildConsoleTable: function () {
199 var $table
, entryTypeText
, i
, length
, entry
;
201 $table
= $( '<table id="mw-debug-console">' );
203 $('<colgroup>').css( 'width', /*padding=*/20 + ( 10*/
*fontSize*/
11 ) ).appendTo( $table
);
204 $('<colgroup>').appendTo( $table
);
205 $('<colgroup>').css( 'width', 350 ).appendTo( $table
);
208 entryTypeText = function( entryType
) {
209 switch ( entryType
) {
221 for ( i
= 0, length
= this.data
.log
.length
; i
< length
; i
+= 1 ) {
222 entry
= this.data
.log
[i
];
223 entry
.typeText
= entryTypeText( entry
.type
);
227 .text( entry
.typeText
)
228 .attr( 'class', 'mw-debug-console-' + entry
.type
)
230 .append( $( '<td>' ).html( entry
.msg
) )
231 .append( $( '<td>' ).text( entry
.caller
) )
241 buildQueryTable: function () {
242 var $table
, i
, length
, query
;
244 $table
= $( '<table id="mw-debug-querylist"></table>' );
247 .append( $('<th>#</th>').css( 'width', '4em' ) )
248 .append( $('<th>SQL</th>') )
249 .append( $('<th>Time</th>').css( 'width', '8em' ) )
250 .append( $('<th>Call</th>').css( 'width', '12em' ) )
253 for ( i
= 0, length
= this.data
.queries
.length
; i
< length
; i
+= 1 ) {
254 query
= this.data
.queries
[i
];
257 .append( $( '<td>' ).text( i
+ 1 ) )
258 .append( $( '<td>' ).text( query
.sql
) )
259 .append( $( '<td class="stats">' ).text( query
.time
.toFixed( 4 )+ 'ms' ) )
260 .append( $( '<td>' ).text( query
['function'] ) )
269 * Legacy debug log pane
271 buildDebugLogTable: function () {
272 var $list
, i
, length
, line
;
275 for ( i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
+= 1 ) {
276 line
= this.data
.debugLog
[i
];
278 .html( mw
.html
.escape( line
).replace( /\n/g, "<br />\n" ) )
286 * Request information pane
288 buildRequestPane: function () {
290 function buildTable( title
, data
) {
291 var $unit
, $table
, key
;
293 $unit
= $( '<div>' ).append( $( '<h2>' ).text( title
) );
295 $table
= $( '<table>' ).appendTo( $unit
);
298 .html( '<th>Key</th><th>Value</th>' )
301 for ( key
in data
) {
302 if ( !data
.hasOwnProperty( key
) ) {
307 .append( $( '<th>' ).text( key
) )
308 .append( $( '<td>' ).text( data
[key
] ) )
316 .text( this.data
.request
.method
+ ' ' + this.data
.request
.url
)
317 .append( buildTable( 'Headers', this.data
.request
.headers
) )
318 .append( buildTable( 'Parameters', this.data
.request
.params
) );
322 * Included files pane
324 buildIncludesPane: function () {
325 var $table
, i
, length
, file
;
327 $table
= $( '<table>' );
329 for ( i
= 0, length
= this.data
.includes
.length
; i
< length
; i
+= 1 ) {
330 file
= this.data
.includes
[i
];
332 .append( $( '<td>' ).text( file
.name
) )
333 .append( $( '<td class="nr">' ).text( file
.size
) )
341 } )( jQuery
, mediaWiki
);