| 1 |
|
| 2 |
|
| 3 |
( function () { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
const hovzer = $.getFootHovzer(); |
| 7 |
|
| 8 |
OO.ui.getViewportSpacing = function () { |
| 9 |
return { |
| 10 |
top: 0, |
| 11 |
right: 0, |
| 12 |
bottom: hovzer.$.outerHeight(), |
| 13 |
left: 0 |
| 14 |
}; |
| 15 |
}; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
const debug = mw.Debug = { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
$container: null, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
data: {}, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
init: function ( data ) { |
| 48 |
|
| 49 |
this.data = data || mw.config.get( 'debugInfo' ); |
| 50 |
this.buildHtml(); |
| 51 |
|
| 52 |
|
| 53 |
hovzer.$.append( this.$container ); |
| 54 |
hovzer.update(); |
| 55 |
|
| 56 |
$( '.mw-debug-panelink' ).on( 'click', this.switchPane ); |
| 57 |
}, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
switchPane: function ( e ) { |
| 70 |
const currentPaneId = debug.$container.data( 'currentPane' ), |
| 71 |
requestedPaneId = $( this ).prop( 'id' ).slice( 9 ), |
| 72 |
$currentPane = $( '#mw-debug-pane-' + currentPaneId ), |
| 73 |
$requestedPane = $( '#mw-debug-pane-' + requestedPaneId ); |
| 74 |
let hovDone = false; |
| 75 |
|
| 76 |
function updateHov() { |
| 77 |
if ( !hovDone ) { |
| 78 |
hovzer.update(); |
| 79 |
hovDone = true; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
e.preventDefault(); |
| 85 |
|
| 86 |
$( this ).addClass( 'current' ); |
| 87 |
$( '.mw-debug-panelink' ).not( this ).removeClass( 'current' ); |
| 88 |
|
| 89 |
|
| 90 |
if ( requestedPaneId === currentPaneId ) { |
| 91 |
|
| 92 |
|
| 93 |
$currentPane.slideUp( updateHov ); |
| 94 |
debug.$container.data( 'currentPane', null ); |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
debug.$container.data( 'currentPane', requestedPaneId ); |
| 99 |
|
| 100 |
if ( currentPaneId === undefined || currentPaneId === null ) { |
| 101 |
|
| 102 |
|
| 103 |
$requestedPane.slideDown( updateHov ); |
| 104 |
} else { |
| 105 |
$currentPane.hide(); |
| 106 |
$requestedPane.show(); |
| 107 |
updateHov(); |
| 108 |
} |
| 109 |
}, |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
buildHtml: function () { |
| 115 |
const $container = $( '<div>' ) |
| 116 |
.attr( { |
| 117 |
id: 'mw-debug-toolbar', |
| 118 |
lang: 'en', |
| 119 |
dir: 'ltr' |
| 120 |
} ) |
| 121 |
.addClass( 'mw-debug' ); |
| 122 |
|
| 123 |
const $bits = $( '<div>' ).addClass( 'mw-debug-bits' ); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
function bitDiv( id ) { |
| 133 |
return $( '<div>' ).prop( { |
| 134 |
id: 'mw-debug-' + id, |
| 135 |
className: 'mw-debug-bit' |
| 136 |
} ).appendTo( $bits ); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
function paneLabel( id, text ) { |
| 148 |
return $( '<a>' ) |
| 149 |
.prop( { |
| 150 |
className: 'mw-debug-panelabel', |
| 151 |
href: '#mw-debug-pane-' + id |
| 152 |
} ) |
| 153 |
.text( text ); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
function paneTriggerBitDiv( id, text, count ) { |
| 166 |
if ( count ) { |
| 167 |
text = text + ' (' + count + ')'; |
| 168 |
} |
| 169 |
return $( '<div>' ).prop( { |
| 170 |
id: 'mw-debug-' + id, |
| 171 |
className: 'mw-debug-bit mw-debug-panelink' |
| 172 |
} ) |
| 173 |
.append( paneLabel( id, text ) ) |
| 174 |
.appendTo( $bits ); |
| 175 |
} |
| 176 |
|
| 177 |
paneTriggerBitDiv( 'console', 'Console', this.data.log.length ); |
| 178 |
|
| 179 |
paneTriggerBitDiv( 'querylist', 'Queries', this.data.queries.length ); |
| 180 |
|
| 181 |
paneTriggerBitDiv( 'debuglog', 'Debug log', this.data.debugLog.length ); |
| 182 |
|
| 183 |
paneTriggerBitDiv( 'request', 'Request' ); |
| 184 |
|
| 185 |
paneTriggerBitDiv( 'includes', 'PHP includes', this.data.includes.length ); |
| 186 |
|
| 187 |
let $gitInfo; |
| 188 |
if ( this.data.gitRevision !== false ) { |
| 189 |
const gitInfoText = '(' + this.data.gitRevision.slice( 0, 7 ) + ')'; |
| 190 |
if ( this.data.gitViewUrl !== false ) { |
| 191 |
$gitInfo = $( '<a>' ) |
| 192 |
.attr( 'href', this.data.gitViewUrl ) |
| 193 |
.text( gitInfoText ); |
| 194 |
} else { |
| 195 |
$gitInfo = $( document.createTextNode( gitInfoText ) ); |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
bitDiv( 'mwversion' ) |
| 200 |
.append( $( '<a>' ).attr( 'href', 'https://www.mediawiki.org/' ).text( 'MediaWiki' ) ) |
| 201 |
.append( document.createTextNode( ': ' + this.data.mwVersion + ' ' ) ) |
| 202 |
.append( $gitInfo ); |
| 203 |
|
| 204 |
if ( this.data.gitBranch !== false ) { |
| 205 |
bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data.gitBranch ); |
| 206 |
} |
| 207 |
|
| 208 |
bitDiv( 'phpversion' ) |
| 209 |
.append( $( '<a>' ).attr( 'href', 'https://php.net/' ).text( 'PHP' ) ) |
| 210 |
.append( ': ' + this.data.phpVersion ); |
| 211 |
|
| 212 |
bitDiv( 'time' ) |
| 213 |
.text( 'Time: ' + this.data.time.toFixed( 5 ) ); |
| 214 |
|
| 215 |
bitDiv( 'memory' ) |
| 216 |
.text( 'Memory: ' + this.data.memory + ' (Peak: ' + this.data.memoryPeak + ')' ); |
| 217 |
|
| 218 |
$bits.appendTo( $container ); |
| 219 |
|
| 220 |
const panes = { |
| 221 |
console: this.buildConsoleTable(), |
| 222 |
querylist: this.buildQueryTable(), |
| 223 |
debuglog: this.buildDebugLogTable(), |
| 224 |
request: this.buildRequestPane(), |
| 225 |
includes: this.buildIncludesPane() |
| 226 |
}; |
| 227 |
|
| 228 |
for ( const paneId in panes ) { |
| 229 |
$( '<div>' ) |
| 230 |
.prop( { |
| 231 |
className: 'mw-debug-pane', |
| 232 |
id: 'mw-debug-pane-' + paneId |
| 233 |
} ) |
| 234 |
.append( panes[ paneId ] ) |
| 235 |
.appendTo( $container ); |
| 236 |
} |
| 237 |
|
| 238 |
this.$container = $container; |
| 239 |
}, |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
buildConsoleTable: function () { |
| 247 |
const $table = $( '<table>' ).attr( 'id', 'mw-debug-console' ); |
| 248 |
const length = this.data.log.length; |
| 249 |
|
| 250 |
$( '<colgroup>' ).css( 'width', 20 + ( 10 * 11 ) ).appendTo( $table ); |
| 251 |
$( '<colgroup>' ).appendTo( $table ); |
| 252 |
$( '<colgroup>' ).css( 'width', 350 ).appendTo( $table ); |
| 253 |
|
| 254 |
const entryTypeText = function ( entryType ) { |
| 255 |
switch ( entryType ) { |
| 256 |
case 'log': |
| 257 |
return 'Log'; |
| 258 |
case 'warn': |
| 259 |
return 'Warning'; |
| 260 |
case 'deprecated': |
| 261 |
return 'Deprecated'; |
| 262 |
default: |
| 263 |
return 'Unknown'; |
| 264 |
} |
| 265 |
}; |
| 266 |
|
| 267 |
for ( let i = 0; i < length; i++ ) { |
| 268 |
const entry = this.data.log[ i ]; |
| 269 |
entry.typeText = entryTypeText( entry.type ); |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
$( '<tr>' ) |
| 276 |
.append( $( '<td>' ) |
| 277 |
.text( entry.typeText ) |
| 278 |
.addClass( 'mw-debug-console-' + entry.type ) |
| 279 |
) |
| 280 |
.append( $( '<td>' ).html( entry.msg ) ) |
| 281 |
.append( $( '<td>' ).text( entry.caller ) ) |
| 282 |
.appendTo( $table ); |
| 283 |
} |
| 284 |
|
| 285 |
return $table; |
| 286 |
}, |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
buildQueryTable: function () { |
| 294 |
const $table = $( '<table>' ).attr( 'id', 'mw-debug-querylist' ); |
| 295 |
const length = this.data.queries.length; |
| 296 |
|
| 297 |
$( '<tr>' ) |
| 298 |
.append( $( '<th>' ).attr( 'scope', 'col' ).text( '#' ).css( 'width', '4em' ) ) |
| 299 |
.append( $( '<th>' ).attr( 'scope', 'col' ).text( 'SQL' ) ) |
| 300 |
.append( $( '<th>' ).attr( 'scope', 'col' ).text( 'Time' ).css( 'width', '8em' ) ) |
| 301 |
.append( $( '<th>' ).attr( 'scope', 'col' ).text( 'Call' ).css( 'width', '18em' ) ) |
| 302 |
.appendTo( $table ); |
| 303 |
|
| 304 |
for ( let i = 0; i < length; i++ ) { |
| 305 |
const query = this.data.queries[ i ]; |
| 306 |
|
| 307 |
$( '<tr>' ) |
| 308 |
.append( $( '<td>' ).text( i + 1 ) ) |
| 309 |
.append( $( '<td>' ).text( query.sql ) ) |
| 310 |
.append( $( '<td>' ).text( ( query.time * 1000 ).toFixed( 3 ) + 'ms' ).addClass( 'stats' ) ) |
| 311 |
.append( $( '<td>' ).text( query.function ) ) |
| 312 |
.appendTo( $table ); |
| 313 |
} |
| 314 |
|
| 315 |
return $table; |
| 316 |
}, |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
buildDebugLogTable: function () { |
| 324 |
const $list = $( '<ul>' ); |
| 325 |
const length = this.data.debugLog.length; |
| 326 |
|
| 327 |
for ( let i = 0; i < length; i++ ) { |
| 328 |
const line = this.data.debugLog[ i ]; |
| 329 |
$( '<li>' ) |
| 330 |
.html( mw.html.escape( line ).replace( /\n/g, '<br />\n' ) ) |
| 331 |
.appendTo( $list ); |
| 332 |
} |
| 333 |
|
| 334 |
return $list; |
| 335 |
}, |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
buildRequestPane: function () { |
| 343 |
|
| 344 |
function buildTable( title, data ) { |
| 345 |
const $unit = $( '<div>' ).append( $( '<h2>' ).text( title ) ); |
| 346 |
|
| 347 |
const $table = $( '<table>' ).appendTo( $unit ); |
| 348 |
|
| 349 |
$( '<tr>' ) |
| 350 |
.append( |
| 351 |
$( '<th>' ).attr( 'scope', 'col' ).text( 'Key' ), |
| 352 |
$( '<th>' ).attr( 'scope', 'col' ).text( 'Value' ) |
| 353 |
) |
| 354 |
.appendTo( $table ); |
| 355 |
|
| 356 |
for ( const key in data ) { |
| 357 |
$( '<tr>' ) |
| 358 |
.append( $( '<th>' ).attr( 'scope', 'row' ).text( key ) ) |
| 359 |
.append( $( '<td>' ).text( data[ key ] ) ) |
| 360 |
.appendTo( $table ); |
| 361 |
} |
| 362 |
|
| 363 |
return $unit; |
| 364 |
} |
| 365 |
|
| 366 |
return $( '<div>' ) |
| 367 |
.text( this.data.request.method + ' ' + this.data.request.url ) |
| 368 |
.append( buildTable( 'Headers', this.data.request.headers ) ) |
| 369 |
.append( buildTable( 'Parameters', this.data.request.params ) ); |
| 370 |
}, |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
buildIncludesPane: function () { |
| 378 |
const $table = $( '<table>' ); |
| 379 |
const length = this.data.includes.length; |
| 380 |
|
| 381 |
for ( let i = 0; i < length; i++ ) { |
| 382 |
const file = this.data.includes[ i ]; |
| 383 |
$( '<tr>' ) |
| 384 |
.append( $( '<td>' ).text( file.name ) ) |
| 385 |
.append( $( '<td>' ).text( file.size ).addClass( 'nr' ) ) |
| 386 |
.appendTo( $table ); |
| 387 |
} |
| 388 |
|
| 389 |
return $table; |
| 390 |
} |
| 391 |
}; |
| 392 |
|
| 393 |
$( () => { |
| 394 |
debug.init(); |
| 395 |
} ); |
| 396 |
|
| 397 |
}() ); |