2 * JavaScript for the new debug toolbar, enabled through $wgDebugToolbar.
12 hovzer
= $.getFootHovzer();
16 * Toolbar container element
23 * Object containing data for the debug toolbar
30 * Initializes the debugging pane.
31 * Shouldn't be called before the document is ready
32 * (since it binds to elements on the page).
34 * @param {Object} data, defaults to 'debugInfo' from mw.config
36 init: function ( data
) {
38 this.data
= data
|| mw
.config
.get( 'debugInfo' );
41 // Insert the container into the DOM
42 hovzer
.$.append( this.$container
);
45 $( '.mw-debug-panelink' ).click( this.switchPane
);
49 * Switches between panes
51 * @todo Store cookie for last pane open
53 * @param {jQuery.Event} e
55 switchPane: function ( e
) {
56 var currentPaneId
= debug
.$container
.data( 'currentPane' ),
57 requestedPaneId
= $(this).prop( 'id' ).substr( 9 ),
58 $currentPane
= $( '#mw-debug-pane-' + currentPaneId
),
59 $requestedPane
= $( '#mw-debug-pane-' + requestedPaneId
),
62 function updateHov() {
69 // Skip hash fragment handling. Prevents screen from jumping.
72 $( this ).addClass( 'current ');
73 $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ');
75 // Hide the current pane
76 if ( requestedPaneId
=== currentPaneId
) {
77 $currentPane
.slideUp( updateHov
);
78 debug
.$container
.data( 'currentPane', null );
82 debug
.$container
.data( 'currentPane', requestedPaneId
);
84 if ( currentPaneId
=== undefined || currentPaneId
=== null ) {
85 $requestedPane
.slideDown( updateHov
);
88 $requestedPane
.show();
94 * Constructs the HTML for the debugging toolbar
96 buildHtml: function () {
97 var $container
, $bits
, panes
, id
, gitInfo
;
99 $container
= $( '<div id="mw-debug-toolbar" class="mw-debug" lang="en" dir="ltr"></div>' );
101 $bits
= $( '<div class="mw-debug-bits"></div>' );
104 * Returns a jQuery element for a debug-bit div
109 function bitDiv( id
) {
110 return $( '<div>' ).prop({
111 id
: 'mw-debug-' + id
,
112 className
: 'mw-debug-bit'
118 * Returns a jQuery element for a pane link
124 function paneLabel( id
, text
) {
127 className
: 'mw-debug-panelabel',
128 href
: '#mw-debug-pane-' + id
134 * Returns a jQuery element for a debug-bit div with a for a pane link
136 * @param id CSS id snippet. Will be prefixed with 'mw-debug-'
137 * @param text Text to show
138 * @param count Optional count to show
141 function paneTriggerBitDiv( id
, text
, count
) {
143 text
= text
+ ' (' + count
+ ')';
145 return $( '<div>' ).prop({
146 id
: 'mw-debug-' + id
,
147 className
: 'mw-debug-bit mw-debug-panelink'
149 .append( paneLabel( id
, text
) )
153 paneTriggerBitDiv( 'console', 'Console', this.data
.log
.length
);
155 paneTriggerBitDiv( 'querylist', 'Queries', this.data
.queries
.length
);
157 paneTriggerBitDiv( 'debuglog', 'Debug log', this.data
.debugLog
.length
);
159 paneTriggerBitDiv( 'request', 'Request' );
161 paneTriggerBitDiv( 'includes', 'PHP includes', this.data
.includes
.length
);
164 if ( this.data
.gitRevision
!== false ) {
165 gitInfo
= '(' + this.data
.gitRevision
.substring( 0, 7 ) + ')';
166 if ( this.data
.gitViewUrl
!== false ) {
168 .attr( 'href', this.data
.gitViewUrl
)
173 bitDiv( 'mwversion' )
174 .append( $( '<a href="//www.mediawiki.org/">MediaWiki</a>' ) )
175 .append( document
.createTextNode( ': ' + this.data
.mwVersion
+ ' ' ) )
178 if ( this.data
.gitBranch
!== false ) {
179 bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data
.gitBranch
);
182 bitDiv( 'phpversion' )
183 .append( $( '<a href="//www.php.net/"></a>' ).text( 'PHP' ) )
184 .append( ': ' + this.data
.phpVersion
);
187 .text( 'Time: ' + this.data
.time
.toFixed( 5 ) );
190 .text( 'Memory: ' + this.data
.memory
+ ' (Peak: ' + this.data
.memoryPeak
+ ')' );
192 $bits
.appendTo( $container
);
195 console
: this.buildConsoleTable(),
196 querylist
: this.buildQueryTable(),
197 debuglog
: this.buildDebugLogTable(),
198 request
: this.buildRequestPane(),
199 includes
: this.buildIncludesPane()
202 for ( id
in panes
) {
203 if ( !panes
.hasOwnProperty( id
) ) {
209 className
: 'mw-debug-pane',
210 id
: 'mw-debug-pane-' + id
213 .appendTo( $container
);
216 this.$container
= $container
;
220 * Builds the console panel
222 buildConsoleTable: function () {
223 var $table
, entryTypeText
, i
, length
, entry
;
225 $table
= $( '<table id="mw-debug-console">' );
227 $( '<colgroup>' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table
);
228 $( '<colgroup>' ).appendTo( $table
);
229 $( '<colgroup>' ).css( 'width', 350 ).appendTo( $table
);
232 entryTypeText = function ( entryType
) {
233 switch ( entryType
) {
245 for ( i
= 0, length
= this.data
.log
.length
; i
< length
; i
+= 1 ) {
246 entry
= this.data
.log
[i
];
247 entry
.typeText
= entryTypeText( entry
.type
);
251 .text( entry
.typeText
)
252 .addClass( 'mw-debug-console-' + entry
.type
)
254 .append( $( '<td>' ).html( entry
.msg
) )
255 .append( $( '<td>' ).text( entry
.caller
) )
265 buildQueryTable: function () {
266 var $table
, i
, length
, query
;
268 $table
= $( '<table id="mw-debug-querylist"></table>' );
271 .append( $( '<th>#</th>' ).css( 'width', '4em' ) )
272 .append( $( '<th>SQL</th>' ) )
273 .append( $( '<th>Time</th>' ).css( 'width', '8em' ) )
274 .append( $( '<th>Call</th>' ).css( 'width', '18em' ) )
277 for ( i
= 0, length
= this.data
.queries
.length
; i
< length
; i
+= 1 ) {
278 query
= this.data
.queries
[i
];
281 .append( $( '<td>' ).text( i
+ 1 ) )
282 .append( $( '<td>' ).text( query
.sql
) )
283 .append( $( '<td class="stats">' ).text( ( query
.time
* 1000 ).toFixed( 4 ) + 'ms' ) )
284 .append( $( '<td>' ).text( query
['function'] ) )
293 * Legacy debug log pane
295 buildDebugLogTable: function () {
296 var $list
, i
, length
, line
;
299 for ( i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
+= 1 ) {
300 line
= this.data
.debugLog
[i
];
302 .html( mw
.html
.escape( line
).replace( /\n/g, '<br />\n' ) )
310 * Request information pane
312 buildRequestPane: function () {
314 function buildTable( title
, data
) {
315 var $unit
, $table
, key
;
317 $unit
= $( '<div>' ).append( $( '<h2>' ).text( title
) );
319 $table
= $( '<table>' ).appendTo( $unit
);
322 .html( '<th>Key</th><th>Value</th>' )
325 for ( key
in data
) {
326 if ( !data
.hasOwnProperty( key
) ) {
331 .append( $( '<th>' ).text( key
) )
332 .append( $( '<td>' ).text( data
[key
] ) )
340 .text( this.data
.request
.method
+ ' ' + this.data
.request
.url
)
341 .append( buildTable( 'Headers', this.data
.request
.headers
) )
342 .append( buildTable( 'Parameters', this.data
.request
.params
) );
346 * Included files pane
348 buildIncludesPane: function () {
349 var $table
, i
, length
, file
;
351 $table
= $( '<table>' );
353 for ( i
= 0, length
= this.data
.includes
.length
; i
< length
; i
+= 1 ) {
354 file
= this.data
.includes
[i
];
356 .append( $( '<td>' ).text( file
.name
) )
357 .append( $( '<td class="nr">' ).text( file
.size
) )
365 }( mediaWiki
, jQuery
) );