Merge "Adding fragment support to SpecialPage::getTitleFor()"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.debug.js
index 641ee12..88af3c6 100644 (file)
@@ -1,16 +1,17 @@
 /**
- * JavaScript for the new debug toolbar, enabled with $wgDebugToolbar
+ * JavaScript for the new debug toolbar, enabled through $wgDebugToolbar.
  *
  * @author John Du Hart
  * @since 1.19
  */
 
-( function ( $, mw, undefined ) {
-"use strict";
+( function ( mw, $ ) {
+       'use strict';
 
-       var hovzer = $.getFootHovzer();
+       var debug,
+               hovzer = $.getFootHovzer();
 
-       var debug = mw.Debug = {
+       debug = mw.Debug = {
                /**
                 * Toolbar container element
                 *
                data: {},
 
                /**
-                * Initializes the debugging pane
+                * Initializes the debugging pane.
+                * Shouldn't be called before the document is ready
+                * (since it binds to elements on the page).
                 *
-                * @param {Object} data
+                * @param {Object} data, defaults to 'debugInfo' from mw.config
                 */
                init: function ( data ) {
 
-                       this.data = data;
+                       this.data = data || mw.config.get( 'debugInfo' );
                        this.buildHtml();
 
                        // Insert the container into the DOM
@@ -63,6 +66,9 @@
                                }
                        }
 
+                       // Skip hash fragment handling. Prevents screen from jumping.
+                       e.preventDefault();
+
                        $( this ).addClass( 'current ');
                        $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ');
 
@@ -88,9 +94,9 @@
                 * Constructs the HTML for the debugging toolbar
                 */
                buildHtml: function () {
-                       var $container, $bits, panes, id;
+                       var $container, $bits, panes, id, gitInfo;
 
-                       $container = $( '<div id="mw-debug-toolbar" class="mw-debug"></div>' );
+                       $container = $( '<div id="mw-debug-toolbar" class="mw-debug" lang="en" dir="ltr"></div>' );
 
                        $bits = $( '<div class="mw-debug-bits"></div>' );
 
                         * @return {jQuery}
                         */
                        function bitDiv( id ) {
-                               return $( '<div>' ).attr({
+                               return $( '<div>' ).prop({
                                        id: 'mw-debug-' + id,
-                                       'class': 'mw-debug-bit'
+                                       className: 'mw-debug-bit'
                                })
                                .appendTo( $bits );
                        }
                         */
                        function paneLabel( id, text ) {
                                return $( '<a>' )
-                                       .attr({
-                                               'class': 'mw-debug-panelabel',
+                                       .prop({
+                                               className: 'mw-debug-panelabel',
                                                href: '#mw-debug-pane-' + id
                                        })
                                        .text( text );
                        /**
                         * Returns a jQuery element for a debug-bit div with a for a pane link
                         *
-                        * @param id
+                        * @param id CSS id snippet. Will be prefixed with 'mw-debug-'
+                        * @param text Text to show
+                        * @param count Optional count to show
                         * @return {jQuery}
                         */
-                       function paneTriggerBitDiv( id, text ) {
-                               return $( '<div>' ).attr({
+                       function paneTriggerBitDiv( id, text, count ) {
+                               if ( count ) {
+                                       text = text + ' (' + count + ')';
+                               }
+                               return $( '<div>' ).prop({
                                        id: 'mw-debug-' + id,
-                                       'class': 'mw-debug-bit mw-debug-panelink'
+                                       className: 'mw-debug-bit mw-debug-panelink'
                                })
                                .append( paneLabel( id, text ) )
                                .appendTo( $bits );
                        }
 
-                       paneTriggerBitDiv( 'console', 'Console (' + this.data.log.length + ')' );
+                       paneTriggerBitDiv( 'console', 'Console', this.data.log.length );
 
-                       paneTriggerBitDiv( 'querylist', 'Queries: ' + this.data.queries.length );
+                       paneTriggerBitDiv( 'querylist', 'Queries', this.data.queries.length );
 
-                       paneTriggerBitDiv( 'debuglog', 'Debug Log (' + this.data.debugLog.length + ' lines)' );
+                       paneTriggerBitDiv( 'debuglog', 'Debug log', this.data.debugLog.length );
 
                        paneTriggerBitDiv( 'request', 'Request' );
 
-                       paneTriggerBitDiv( 'includes', this.data.includes.length + ' Files Included' );
+                       paneTriggerBitDiv( 'includes', 'PHP includes', this.data.includes.length );
+
+                       gitInfo = '';
+                       if ( this.data.gitRevision !== false ) {
+                               gitInfo = '(' + this.data.gitRevision.substring( 0, 7 ) + ')';
+                               if ( this.data.gitViewUrl !== false ) {
+                                       gitInfo = $( '<a>' )
+                                               .attr( 'href', this.data.gitViewUrl )
+                                               .text( gitInfo );
+                               }
+                       }
 
                        bitDiv( 'mwversion' )
-                               .append( $( '<a href="//www.mediawiki.org/"></a>' ).text( 'MediaWiki' ) )
-                               .append( ': ' + this.data.mwVersion );
+                               .append( $( '<a href="//www.mediawiki.org/">MediaWiki</a>' ) )
+                               .append( document.createTextNode( ': ' + this.data.mwVersion + ' ' ) )
+                               .append( gitInfo );
+
+                       if ( this.data.gitBranch !== false ) {
+                               bitDiv( 'gitbranch' ).text( 'Git branch: ' + this.data.gitBranch );
+                       }
 
                        bitDiv( 'phpversion' )
                                .append( $( '<a href="//www.php.net/"></a>' ).text( 'PHP' ) )
                                .text( 'Time: ' + this.data.time.toFixed( 5 ) );
 
                        bitDiv( 'memory' )
-                               .text( 'Memory: ' + this.data.memory )
-                               .append( $( '<span title="Peak usage"></span>' ).text( ' (' + this.data.memoryPeak + ')' ) );
-                               
+                               .text( 'Memory: ' + this.data.memory + ' (Peak: ' + this.data.memoryPeak + ')' );
 
                        $bits.appendTo( $container );
 
                                }
 
                                $( '<div>' )
-                                       .attr({
-                                               'class': 'mw-debug-pane',
+                                       .prop({
+                                               className: 'mw-debug-pane',
                                                id: 'mw-debug-pane-' + id
                                        })
                                        .append( panes[id] )
 
                        $table = $( '<table id="mw-debug-console">' );
 
-                       $('<colgroup>').css( 'width', /*padding=*/20 + ( 10*/*fontSize*/11 ) ).appendTo( $table );
-                       $('<colgroup>').appendTo( $table );
-                       $('<colgroup>').css( 'width', 350 ).appendTo( $table );
+                       $( '<colgroup>' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table );
+                       $( '<colgroup>' ).appendTo( $table );
+                       $( '<colgroup>' ).css( 'width', 350 ).appendTo( $table );
 
 
                        entryTypeText = function( entryType ) {
                                $( '<tr>' )
                                        .append( $( '<td>' )
                                                .text( entry.typeText )
-                                               .attr( 'class', 'mw-debug-console-' + entry.type )
+                                               .addClass( 'mw-debug-console-' + entry.type )
                                        )
                                        .append( $( '<td>' ).html( entry.msg ) )
                                        .append( $( '<td>' ).text( entry.caller ) )
 
                        $table = $( '<table id="mw-debug-querylist"></table>' );
 
-                       // Widths on table cells and columns behave weird in some browsers like Chrome,
-                       // in that, contrary to the W3 box model, padding does not increase cells having a fixed width
-                       $('<colgroup>').css( 'width', /*padding=*/20 + ( String( this.data.queries.length ).length*/*fontSize*/11 ) ).appendTo( $table );
-                       $('<colgroup>').appendTo( $table );
-                       $('<colgroup>').css( 'width', 350 ).appendTo( $table );
+                       $( '<tr>' )
+                               .append( $( '<th>#</th>' ).css( 'width', '4em' )    )
+                               .append( $( '<th>SQL</th>' ) )
+                               .append( $( '<th>Time</th>' ).css( 'width', '8em'  ) )
+                               .append( $( '<th>Call</th>' ).css( 'width', '18em' ) )
+                       .appendTo( $table );
 
                        for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) {
                                query = this.data.queries[i];
                                $( '<tr>' )
                                        .append( $( '<td>' ).text( i + 1 ) )
                                        .append( $( '<td>' ).text( query.sql ) )
-                                       .append( $( '<td>' )
-                                               .append( $( '<span class="stats"></span>' ).text( '(' + query.time.toFixed( 4 ) + 'ms) ' ) )
-                                               .append( query['function'] )
-                                       )
-                                       .appendTo( $table );
+                                       .append( $( '<td class="stats">' ).text( ( query.time * 1000 ).toFixed( 4 ) + 'ms' ) )
+                                       .append( $( '<td>' ).text( query['function'] ) )
+                               .appendTo( $table );
                        }
 
 
                        for ( i = 0, length = this.data.debugLog.length; i < length; i += 1 ) {
                                line = this.data.debugLog[i];
                                $( '<li>' )
-                                       .html( mw.html.escape( line ).replace( /\n/g, "<br />\n" ) )
+                                       .html( mw.html.escape( line ).replace( /\n/g, '<br />\n' ) )
                                        .appendTo( $list );
                        }
 
                }
        };
 
-} )( jQuery, mediaWiki );
+}( mediaWiki, jQuery ) );