2 * Javascript for the new debug toolbar, enabled with $wgDebugToolbar
10 var debug
= mw
.Debug
= {
12 * Toolbar container element
19 * Array containing data for the debug toolbar
26 * Initializes the debugging pane
30 init: function( data
) {
34 // Insert the container into the DOM
35 $( 'body' ).append( this.$container
);
37 $( '.mw-debug-panelink' ).click( this.switchPane
);
41 * Switches between panes
43 * @todo Store cookie for last pane open
45 * @param {jQuery.Event} e
47 switchPane: function( e
) {
48 var currentPaneId
= debug
.$container
.data( 'currentPane' ),
49 requestedPaneId
= $(this).parent().attr( 'id' ).substr( 9 ),
50 $currentPane
= $( '#mw-debug-pane-' + currentPaneId
),
51 $requestedPane
= $( '#mw-debug-pane-' + requestedPaneId
);
54 // Hide the current pane
55 if ( requestedPaneId
=== currentPaneId
) {
56 $currentPane
.slideUp();
57 debug
.$container
.data( 'currentPane', null );
61 debug
.$container
.data( 'currentPane', requestedPaneId
);
63 if ( currentPaneId
=== undefined || currentPaneId
=== null ) {
64 $requestedPane
.slideDown();
67 $requestedPane
.show();
72 * Constructs the HTML for the debugging toolbar
74 buildHtml: function() {
75 this.$container
= $( '<div></div>' )
77 id
: 'mw-debug-container',
83 html
+= '<div class="mw-debug-bit" id="mw-debug-mwversion">'
84 + '<a href="//www.mediawiki.org/">MediaWiki</a>: '
85 + this.data
.mwVersion
+ '</div>';
87 html
+= '<div class="mw-debug-bit" id="mw-debug-phpversion">'
88 + '<a href="//www.php.net/">PHP</a>: '
89 + this.data
.phpVersion
+ '</div>';
91 html
+= '<div class="mw-debug-bit" id="mw-debug-time">'
92 + 'Time: ' + this.data
.time
.toFixed( 5 ) + 's</div>';
93 html
+= '<div class="mw-debug-bit" id="mw-debug-memory">'
94 + 'Memory: ' + this.data
.memory
+ ' (<span title="Peak usage">'
95 + this.data
.memoryPeak
+ '</span>)</div>';
97 var queryLink
= '<a href="#" class="mw-debug-panelink" id="mw-debug-query-link">Queries: '
98 + this.data
.queries
.length
+ '</a>';
99 html
+= '<div class="mw-debug-bit" id="mw-debug-querylist">'
100 + queryLink
+ '</div>';
102 var debugLink
= '<a href="#" class="mw-debug-panelink" id="mw-debug-debuglog-link">Debug Log ('
103 + this.data
.debugLog
.length
+ ' lines)</a>';
104 html
+= '<div class="mw-debug-bit" id="mw-debug-debuglog">'
105 + debugLink
+ '</div>';
107 var requestLink
= '<a href="#" class="mw-debug-panelink" id="mw-debug-request-link">Request</a>';
108 html
+= '<div class="mw-debug-bit" id="mw-debug-request">'
109 + requestLink
+ '</div>';
111 var filesLink
= '<a href="#" class="mw-debug-panelink" id="mw-debug-files-includes">'
112 + this.data
.includes
.length
+ ' Files Included</a>';
113 html
+= '<div class="mw-debug-bit" id="mw-debug-includes">'
114 + filesLink
+ '</div>';
116 html
+= '<div class="mw-debug-pane" id="mw-debug-pane-querylist">'
117 + this.buildQueryTable() + '</div>';
118 html
+= '<div class="mw-debug-pane" id="mw-debug-pane-debuglog">'
119 + this.buildDebugLogTable() + '</div>';
120 html
+= '<div class="mw-debug-pane" id="mw-debug-pane-request">'
121 + this.buildRequestPane() + '</div>';
122 html
+= '<div class="mw-debug-pane" id="mw-debug-pane-includes">'
123 + this.buildIncludesPane() + '</div>';
125 this.$container
.html( html
);
131 buildQueryTable: function() {
132 var html
= '<table id="mw-debug-querylist">';
134 for ( var i
= 0, length
= this.data
.queries
.length
; i
< length
; i
++ ) {
135 var query
= this.data
.queries
[i
];
137 html
+= '<tr><td>' + ( i
+ 1 ) + '</td>';
139 html
+= '<td>' + query
.sql
+ '</td>';
140 html
+= '<td><span class="mw-debug-query-time">(' + query
.time
.toFixed( 4 ) + 'ms)</span> ' + query
.function + '</td>';
151 * Legacy debug log pane
153 buildDebugLogTable: function() {
156 for ( var i
= 0, length
= this.data
.debugLog
.length
; i
< length
; i
++ ) {
157 var line
= this.data
.debugLog
[i
];
158 html
+= '<li>' + line
.replace( /\n/g, "<br />\n" ) + '</li>';
161 return html
+ '</ul>';
165 * Request information pane
167 buildRequestPane: function() {
168 var buildTable = function( title
, data
) {
169 var t
= '<h2>' + title
+ '</h2>'
170 + '<table> <tr> <th>Key</th> <th>Value</th> </tr>';
172 for ( var key
in data
) {
173 if ( !data
.hasOwnProperty( key
) ) {
176 var value
= data
[key
];
178 t
+= '<tr><th>' + key
+ '</th><td>' + value
+ '</td></tr>';
185 var html
= this.data
.request
.method
+ ' ' + this.data
.request
.url
;
186 html
+= buildTable( 'Headers', this.data
.request
.headers
);
187 html
+= buildTable( 'Parameters', this.data
.request
.params
);
193 * Included files pane
195 buildIncludesPane: function() {
198 for ( var i
= 0, l
= this.data
.includes
.length
; i
< l
; i
++ ) {
199 var file
= this.data
.includes
[i
];
200 html
+= '<li><span class="mw-debug-right">' + file
.size
+ '</span> ' + file
.name
+ '</li>';