Index: trunk/phase3/resources/mediawiki/mediawiki.debug.css |
— | — | @@ -50,10 +50,6 @@ |
51 | 51 | float: right; |
52 | 52 | } |
53 | 53 | |
54 | | -#mw-debug-querylist tr { |
55 | | - |
56 | | -} |
57 | | - |
58 | 54 | #mw-debug-querylist td { |
59 | 55 | padding: 2px 5px; |
60 | 56 | border-bottom: 1px solid #ccc; |
Index: trunk/phase3/resources/mediawiki/mediawiki.debug.js |
— | — | @@ -1,11 +1,12 @@ |
2 | 2 | /** |
3 | | - * Javascript for the new debug toolbar, enabled with $wgDebugToolbar |
| 3 | + * JavaScript for the new debug toolbar, enabled with $wgDebugToolbar |
4 | 4 | * |
5 | 5 | * @author John Du Hart |
6 | 6 | * @since 1.19 |
7 | 7 | */ |
8 | 8 | |
9 | | -( function( $ ) { |
| 9 | +( function ( $, mw, undefined ) { |
| 10 | +"use strict"; |
10 | 11 | |
11 | 12 | var debug = mw.Debug = { |
12 | 13 | /** |
— | — | @@ -16,18 +17,18 @@ |
17 | 18 | $container: null, |
18 | 19 | |
19 | 20 | /** |
20 | | - * Array containing data for the debug toolbar |
| 21 | + * Object containing data for the debug toolbar |
21 | 22 | * |
22 | | - * @var {Array} |
| 23 | + * @var {Object} |
23 | 24 | */ |
24 | 25 | data: {}, |
25 | 26 | |
26 | 27 | /** |
27 | 28 | * Initializes the debugging pane |
28 | 29 | * |
29 | | - * @param {Array} data |
| 30 | + * @param {Object} data |
30 | 31 | */ |
31 | | - init: function( data ) { |
| 32 | + init: function ( data ) { |
32 | 33 | this.data = data; |
33 | 34 | this.buildHtml(); |
34 | 35 | |
— | — | @@ -44,7 +45,7 @@ |
45 | 46 | * @context {Element} |
46 | 47 | * @param {jQuery.Event} e |
47 | 48 | */ |
48 | | - switchPane: function( e ) { |
| 49 | + switchPane: function ( e ) { |
49 | 50 | var currentPaneId = debug.$container.data( 'currentPane' ), |
50 | 51 | requestedPaneId = $(this).parent().attr( 'id' ).substr( 9 ), |
51 | 52 | $currentPane = $( '#mw-debug-pane-' + currentPaneId ), |
— | — | @@ -71,11 +72,13 @@ |
72 | 73 | /** |
73 | 74 | * Constructs the HTML for the debugging toolbar |
74 | 75 | */ |
75 | | - buildHtml: function() { |
76 | | - var $container = this.$container = $( '<div></div>' ) |
| 76 | + buildHtml: function () { |
| 77 | + var $container, panes, id; |
| 78 | + |
| 79 | + $container = $( '<div>' ) |
77 | 80 | .attr({ |
78 | 81 | id: 'mw-debug-container', |
79 | | - class: 'mw-debug' |
| 82 | + 'class': 'mw-debug' |
80 | 83 | }); |
81 | 84 | |
82 | 85 | /** |
— | — | @@ -84,12 +87,13 @@ |
85 | 88 | * @param id |
86 | 89 | * @return {jQuery} |
87 | 90 | */ |
88 | | - var bitDiv = function( id ) { |
89 | | - return $( '<div></div>' ).attr({ |
| 91 | + function bitDiv( id ) { |
| 92 | + return $( '<div>' ).attr({ |
90 | 93 | id: 'mw-debug-' + id, |
91 | | - class: 'mw-debug-bit' |
| 94 | + 'class': 'mw-debug-bit' |
92 | 95 | }); |
93 | | - }; |
| 96 | + } |
| 97 | + |
94 | 98 | /** |
95 | 99 | * Returns a jQuery element for a pane link |
96 | 100 | * |
— | — | @@ -97,23 +101,23 @@ |
98 | 102 | * @param text |
99 | 103 | * @return {jQuery} |
100 | 104 | */ |
101 | | - var paneLink = function( id, text ) { |
102 | | - return $( '<a></a>' ) |
| 105 | + function paneLink( id, text ) { |
| 106 | + return $( '<a>' ) |
103 | 107 | .attr({ |
104 | 108 | href: '#', |
105 | | - class: 'mw-debug-panelink', |
| 109 | + 'class': 'mw-debug-panelink', |
106 | 110 | id: 'mw-debug-' + id + '-link' |
107 | 111 | }) |
108 | 112 | .text( text ); |
109 | 113 | } |
110 | 114 | |
111 | 115 | bitDiv( 'mwversion' ) |
112 | | - .append( $( '<a href="https://www.mediawiki.org//www.mediawiki.org/">' ).text( 'MediaWiki' ) ) |
| 116 | + .append( $( '<a href="https://www.mediawiki.org//www.mediawiki.org/"></a>' ).text( 'MediaWiki' ) ) |
113 | 117 | .append( ': ' + this.data.mwVersion ) |
114 | 118 | .appendTo( $container ); |
115 | 119 | |
116 | 120 | bitDiv( 'phpversion' ) |
117 | | - .append( $( '<a href="https://www.mediawiki.org//www.php.net/">' ).text( 'PHP' ) ) |
| 121 | + .append( $( '<a href="https://www.mediawiki.org//www.php.net/"></a>' ).text( 'PHP' ) ) |
118 | 122 | .append( ': ' + this.data.phpVersion ) |
119 | 123 | .appendTo( $container ); |
120 | 124 | |
— | — | @@ -141,42 +145,46 @@ |
142 | 146 | .append( paneLink( 'files-includes', this.data.includes.length + ' Files Included' ) ) |
143 | 147 | .appendTo( $container ); |
144 | 148 | |
145 | | - var panes = { |
146 | | - 'querylist': this.buildQueryTable(), |
147 | | - 'debuglog': this.buildDebugLogTable(), |
148 | | - 'request': this.buildRequestPane(), |
149 | | - 'includes': this.buildIncludesPane() |
| 149 | + panes = { |
| 150 | + querylist: this.buildQueryTable(), |
| 151 | + debuglog: this.buildDebugLogTable(), |
| 152 | + request: this.buildRequestPane(), |
| 153 | + includes: this.buildIncludesPane() |
150 | 154 | }; |
151 | 155 | |
152 | | - for ( var id in panes ) { |
| 156 | + for ( id in panes ) { |
153 | 157 | if ( !panes.hasOwnProperty( id ) ) { |
154 | 158 | continue; |
155 | 159 | } |
156 | 160 | |
157 | | - $( '<div></div>' ) |
| 161 | + $( '<div>' ) |
158 | 162 | .attr({ |
159 | | - class: 'mw-debug-pane', |
| 163 | + 'class': 'mw-debug-pane', |
160 | 164 | id: 'mw-debug-pane-' + id |
161 | 165 | }) |
162 | 166 | .append( panes[id] ) |
163 | 167 | .appendTo( $container ); |
164 | 168 | } |
| 169 | + |
| 170 | + this.$container = $container; |
165 | 171 | }, |
166 | 172 | |
167 | 173 | /** |
168 | 174 | * Query list pane |
169 | 175 | */ |
170 | | - buildQueryTable: function() { |
171 | | - var $table = $( '<table id="mw-debug-querylist"></table>' ); |
| 176 | + buildQueryTable: function () { |
| 177 | + var $table, i, length, query; |
172 | 178 | |
173 | | - for ( var i = 0, length = this.data.queries.length; i < length; i++ ) { |
174 | | - var query = this.data.queries[i]; |
| 179 | + $table = $( '<table id="mw-debug-querylist"></table>' ); |
175 | 180 | |
| 181 | + for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { |
| 182 | + query = this.data.queries[i]; |
| 183 | + |
176 | 184 | $( '<tr>' ) |
177 | 185 | .append( $( '<td>' ).text( i + 1 ) ) |
178 | 186 | .append( $( '<td>' ).text( query.sql ) ) |
179 | 187 | .append( $( '<td>' ) |
180 | | - .append( $( '<span class="mw-debug-query-time">' ).text( '(' + query.time.toFixed( 4 ) + 'ms) ' ) ) |
| 188 | + .append( $( '<span class="mw-debug-query-time"></span>' ).text( '(' + query.time.toFixed( 4 ) + 'ms) ' ) ) |
181 | 189 | .append( query['function'] ) |
182 | 190 | ) |
183 | 191 | .appendTo( $table ); |
— | — | @@ -188,11 +196,12 @@ |
189 | 197 | /** |
190 | 198 | * Legacy debug log pane |
191 | 199 | */ |
192 | | - buildDebugLogTable: function() { |
193 | | - var $list = $( '<ul>' ); |
| 200 | + buildDebugLogTable: function () { |
| 201 | + var $list, i, length, line; |
| 202 | + $list = $( '<ul>' ); |
194 | 203 | |
195 | | - for ( var i = 0, length = this.data.debugLog.length; i < length; i++ ) { |
196 | | - var line = this.data.debugLog[i]; |
| 204 | + for ( i = 0, length = this.data.debugLog.length; i < length; i += 1 ) { |
| 205 | + line = this.data.debugLog[i]; |
197 | 206 | $( '<li>' ) |
198 | 207 | .html( mw.html.escape( line ).replace( /\n/g, "<br />\n" ) ) |
199 | 208 | .appendTo( $list ); |
— | — | @@ -204,18 +213,20 @@ |
205 | 214 | /** |
206 | 215 | * Request information pane |
207 | 216 | */ |
208 | | - buildRequestPane: function() { |
209 | | - var buildTable = function( title, data ) { |
210 | | - var $unit = $( '<div></div>' ) |
211 | | - .append( $( '<h2>' ).text( title ) ); |
| 217 | + buildRequestPane: function () { |
212 | 218 | |
213 | | - var $table = $( '<table>' ).appendTo( $unit ); |
| 219 | + function buildTable( title, data ) { |
| 220 | + var $unit, $table, key; |
214 | 221 | |
| 222 | + $unit = $( '<div>' ).append( $( '<h2>' ).text( title ) ); |
| 223 | + |
| 224 | + $table = $( '<table>' ).appendTo( $unit ); |
| 225 | + |
215 | 226 | $( '<tr>' ) |
216 | | - .html( '<th>Key</th> <th>Value</th>' ) |
| 227 | + .html( '<th>Key</th><th>Value</th>' ) |
217 | 228 | .appendTo( $table ); |
218 | 229 | |
219 | | - for ( var key in data ) { |
| 230 | + for ( key in data ) { |
220 | 231 | if ( !data.hasOwnProperty( key ) ) { |
221 | 232 | continue; |
222 | 233 | } |
— | — | @@ -227,26 +238,27 @@ |
228 | 239 | } |
229 | 240 | |
230 | 241 | return $unit; |
231 | | - }; |
| 242 | + } |
232 | 243 | |
233 | | - var $pane = $( '<div>' ) |
| 244 | + return $( '<div>' ) |
234 | 245 | .text( this.data.request.method + ' ' + this.data.request.url ) |
235 | 246 | .append( buildTable( 'Headers', this.data.request.headers ) ) |
236 | 247 | .append( buildTable( 'Parameters', this.data.request.params ) ); |
237 | | - return $pane; |
238 | 248 | }, |
239 | 249 | |
240 | 250 | /** |
241 | 251 | * Included files pane |
242 | 252 | */ |
243 | | - buildIncludesPane: function() { |
244 | | - var $list = $( '<ul>' ) |
| 253 | + buildIncludesPane: function () { |
| 254 | + var $list, i, len, file; |
245 | 255 | |
246 | | - for ( var i = 0, l = this.data.includes.length; i < l; i++ ) { |
247 | | - var file = this.data.includes[i]; |
| 256 | + $list = $( '<ul>' ); |
| 257 | + |
| 258 | + for ( i = 0, len = this.data.includes.length; i < len; i += 1 ) { |
| 259 | + file = this.data.includes[i]; |
248 | 260 | $( '<li>' ) |
249 | 261 | .text( file.name ) |
250 | | - .prepend( $( '<span class="mw-debug-right">' ).text( file.size ) ) |
| 262 | + .prepend( $( '<span class="mw-debug-right"></span>' ).text( file.size ) ) |
251 | 263 | .appendTo( $list ); |
252 | 264 | } |
253 | 265 | |
— | — | @@ -254,4 +266,4 @@ |
255 | 267 | } |
256 | 268 | }; |
257 | 269 | |
258 | | -} )( jQuery ); |
\ No newline at end of file |
| 270 | +} )( jQuery, mediaWiki ); |