( function ( mw, $ ) { 'use strict'; var debug, hovzer = $.getFootHovzer(); /** * Debug toolbar. * * Enabled server-side through `$wgDebugToolbar`. * * @class mw.Debug * @singleton * @author John Du Hart * @since 1.19 */ debug = mw.Debug = { /** * Toolbar container element * * @property {jQuery} */ $container: null, /** * Object containing data for the debug toolbar * * @property {Object} */ data: {}, /** * Initialize the debugging pane * * Shouldn't be called before the document is ready * (since it binds to elements on the page). * * @param {Object} [data] Defaults to 'debugInfo' from mw.config */ init: function ( data ) { this.data = data || mw.config.get( 'debugInfo' ); this.buildHtml(); // Insert the container into the DOM hovzer.$.append( this.$container ); hovzer.update(); $( '.mw-debug-panelink' ).click( this.switchPane ); }, /** * Switch between panes * * Should be called with an HTMLElement as its thisArg, * because it's meant to be an event handler. * * TODO: Store cookie for last pane open. * * @param {jQuery.Event} e */ switchPane: function ( e ) { var currentPaneId = debug.$container.data( 'currentPane' ), requestedPaneId = $( this ).prop( 'id' ).slice( 9 ), $currentPane = $( '#mw-debug-pane-' + currentPaneId ), $requestedPane = $( '#mw-debug-pane-' + requestedPaneId ), hovDone = false; function updateHov() { if ( !hovDone ) { hovzer.update(); hovDone = true; } } // Skip hash fragment handling. Prevents screen from jumping. e.preventDefault(); $( this ).addClass( 'current ' ); $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ' ); // Hide the current pane if ( requestedPaneId === currentPaneId ) { $currentPane.slideUp( updateHov ); debug.$container.data( 'currentPane', null ); return; } debug.$container.data( 'currentPane', requestedPaneId ); if ( currentPaneId === undefined || currentPaneId === null ) { $requestedPane.slideDown( updateHov ); } else { $currentPane.hide(); $requestedPane.show(); updateHov(); } }, /** * Construct the HTML for the debugging toolbar */ buildHtml: function () { var $container, $bits, panes, id, gitInfo; $container = $( '
' ); $bits = $( '' ); /** * Returns a jQuery element for a debug-bit div * * @ignore * @param {string} id * @return {jQuery} */ function bitDiv( id ) { return $( '' ) .text( entry.typeText ) .addClass( 'mw-debug-console-' + entry.type ) ) .append( $( ' | ' ).html( entry.msg ) ) .append( $( ' | ' ).text( entry.caller ) )
.appendTo( $table );
}
return $table;
},
/**
* Build query list pane
*
* @return {jQuery}
*/
buildQueryTable: function () {
var $table, i, length, query;
$table = $( ' | |||||||
# | ' ).css( 'width', '4em' ) ) .append( $( 'SQL | ' ) ) .append( $( 'Time | ' ).css( 'width', '8em' ) ) .append( $( 'Call | ' ).css( 'width', '18em' ) ) .appendTo( $table ); for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { query = this.data.queries[i]; $( '||||||
---|---|---|---|---|---|---|---|---|---|
' ).text( i + 1 ) ) .append( $( ' | ' ).text( query.sql ) ) .append( $( ' | ' ).text( ( query.time * 1000 ).toFixed( 4 ) + 'ms' ) ) .append( $( ' | ' ).text( query['function'] ) )
.appendTo( $table );
}
return $table;
},
/**
* Build legacy debug log pane
*
* @return {jQuery}
*/
buildDebugLogTable: function () {
var $list, i, length, line;
$list = $( '
|