From 71a2f6e9e94202ea344e6fd10070024668545fd7 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Wed, 21 Nov 2018 21:14:26 +0000 Subject: [PATCH] Avoid HTML string parsing Identified using https://github.com/wikimedia/eslint-plugin-jquery/pull/12 Change-Id: Ic3ac53804085aa61be54793e7e5f27b23d99a560 --- .../src/jquery/jquery.makeCollapsible.js | 3 +- .../mediawiki.action.view.metadata.js | 4 +-- resources/src/mediawiki.debug/debug.js | 36 +++++++++++-------- .../src/mediawiki.debug/jquery.footHovzer.js | 2 +- .../mediawiki.notification/notification.js | 12 ++++--- .../mediawiki.searchSuggest/searchSuggest.js | 9 ++++- resources/src/mediawiki.toc/toc.js | 7 +++- 7 files changed, 48 insertions(+), 25 deletions(-) diff --git a/resources/src/jquery/jquery.makeCollapsible.js b/resources/src/jquery/jquery.makeCollapsible.js index 43b8f0d667..09306f634c 100644 --- a/resources/src/jquery/jquery.makeCollapsible.js +++ b/resources/src/jquery/jquery.makeCollapsible.js @@ -218,7 +218,8 @@ // Default toggle link. Only build it when needed to avoid jQuery memory leaks (event data). buildDefaultToggleLink = function () { - return $( '' ) + return $( '' ) + .addClass( 'mw-collapsible-text' ) .text( collapseText ) .wrap( '' ) .parent() diff --git a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js index e76ea33ddc..b61349b703 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.metadata.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.metadata.js @@ -42,8 +42,8 @@ } ); $table.find( 'tbody' ).append( - $( '' ).append( - $( '' ).append( $link ) + $( '' ).addClass( 'mw-metadata-show-hide-extended' ).append( + $( '' ).prop( 'colspan', 2 ).append( $link ) ) ); } ); diff --git a/resources/src/mediawiki.debug/debug.js b/resources/src/mediawiki.debug/debug.js index f0c2601139..f1e829c316 100644 --- a/resources/src/mediawiki.debug/debug.js +++ b/resources/src/mediawiki.debug/debug.js @@ -112,9 +112,15 @@ buildHtml: function () { var $container, $bits, panes, id, gitInfo; - $container = $( '
' ); + $container = $( '
' ) + .attr( { + id: 'mw-debug-toolbar', + lang: 'en', + dir: 'ltr' + } ) + .addClass( 'mw-debug' ); - $bits = $( '
' ); + $bits = $( '
' ).addClass( 'mw-debug-bits' ); /** * Returns a jQuery element for a debug-bit div @@ -189,7 +195,7 @@ } bitDiv( 'mwversion' ) - .append( $( 'MediaWiki' ) ) + .append( $( '' ).attr( 'href', '//www.mediawiki.org/' ).text( 'MediaWiki' ) ) .append( document.createTextNode( ': ' + this.data.mwVersion + ' ' ) ) .append( gitInfo ); @@ -198,10 +204,10 @@ } bitDiv( 'phpversion' ) - .append( $( this.data.phpEngine === 'HHVM' ? - 'HHVM' : - 'PHP' - ) ) + .append( this.data.phpEngine === 'HHVM' ? + $( '' ).attr( 'href', 'https://hhvm.com/' ).text( 'HHVM' ) : + $( '' ).attr( 'href', 'https://php.net/' ).text( 'PHP' ) + ) .append( ': ' + this.data.phpVersion ); bitDiv( 'time' ) @@ -241,7 +247,7 @@ buildConsoleTable: function () { var $table, entryTypeText, i, length, entry; - $table = $( '' ); + $table = $( '
' ).attr( 'id', 'mw-debug-console' ); $( '' ).css( 'width', /* padding = */ 20 + ( 10 * /* fontSize = */ 11 ) ).appendTo( $table ); $( '' ).appendTo( $table ); @@ -285,13 +291,13 @@ buildQueryTable: function () { var $table, i, length, query; - $table = $( '
' ); + $table = $( '' ).attr( 'id', 'mw-debug-querylist' ); $( '' ) - .append( $( '' ).css( 'width', '4em' ) ) - .append( $( '' ) ) - .append( $( '' ).css( 'width', '8em' ) ) - .append( $( '' ).css( 'width', '18em' ) ) + .append( $( '' ) .append( $( '' ) .append( $( '
#SQLTimeCall' ).text( '#' ).css( 'width', '4em' ) ) + .append( $( '' ).text( 'SQL' ) ) + .append( $( '' ).text( 'Time' ).css( 'width', '8em' ) ) + .append( $( '' ).text( 'Call' ).css( 'width', '18em' ) ) .appendTo( $table ); for ( i = 0, length = this.data.queries.length; i < length; i += 1 ) { @@ -300,7 +306,7 @@ $( '
' ).text( i + 1 ) ) .append( $( '' ).text( query.sql ) ) - .append( $( '' ).text( ( query.time * 1000 ).toFixed( 4 ) + 'ms' ) ) + .append( $( '' ).text( ( query.time * 1000 ).toFixed( 4 ) + 'ms' ).addClass( 'stats' ) ) .append( $( '' ).text( query[ 'function' ] ) ) .appendTo( $table ); } @@ -375,7 +381,7 @@ file = this.data.includes[ i ]; $( '
' ).text( file.name ) ) - .append( $( '' ).text( file.size ) ) + .append( $( '' ).text( file.size ).addClass( 'nr' ) ) .appendTo( $table ); } diff --git a/resources/src/mediawiki.debug/jquery.footHovzer.js b/resources/src/mediawiki.debug/jquery.footHovzer.js index ef8afdfee7..ddb9b17b2d 100644 --- a/resources/src/mediawiki.debug/jquery.footHovzer.js +++ b/resources/src/mediawiki.debug/jquery.footHovzer.js @@ -7,7 +7,7 @@ function getHovzer() { if ( $hovzer === undefined ) { - $hovzer = $( '
' ).appendTo( 'body' ); + $hovzer = $( '
' ).attr( 'id', 'jquery-foot-hovzer' ).appendTo( 'body' ); } return $hovzer; } diff --git a/resources/src/mediawiki.notification/notification.js b/resources/src/mediawiki.notification/notification.js index 0ec010e8a1..f72fc92053 100644 --- a/resources/src/mediawiki.notification/notification.js +++ b/resources/src/mediawiki.notification/notification.js @@ -29,9 +29,12 @@ function Notification( message, options ) { var $notification, $notificationContent; - $notification = $( '
' ) + $notification = $( '
' ) .data( 'mw-notification', this ) - .addClass( options.autoHide ? 'mw-notification-autohide' : 'mw-notification-noautohide' ); + .addClass( [ + 'mw-notification', + options.autoHide ? 'mw-notification-autohide' : 'mw-notification-noautohide' + ] ); if ( options.tag ) { // Sanitize options.tag before it is used by any code. (Including Notification class methods) @@ -50,12 +53,13 @@ } if ( options.title ) { - $( '
' ) + $( '
' ) + .addClass( 'mw-notification-title' ) .text( options.title ) .appendTo( $notification ); } - $notificationContent = $( '
' ); + $notificationContent = $( '
' ).addClass( 'mw-notification-content' ); if ( typeof message === 'object' ) { // Handle mw.Message objects separately from DOM nodes and jQuery objects diff --git a/resources/src/mediawiki.searchSuggest/searchSuggest.js b/resources/src/mediawiki.searchSuggest/searchSuggest.js index ed4039c1cb..554aadb508 100644 --- a/resources/src/mediawiki.searchSuggest/searchSuggest.js +++ b/resources/src/mediawiki.searchSuggest/searchSuggest.js @@ -297,7 +297,14 @@ } ); } else { $input.closest( 'form' ) - .append( $( '' ) ); + .append( + $( '' ) + .prop( { + type: 'hidden', + value: 1 + } ) + .attr( 'name', 'fulltext' ) + ); } return true; // allow the form to be submitted } diff --git a/resources/src/mediawiki.toc/toc.js b/resources/src/mediawiki.toc/toc.js index 5781d88ceb..de81d6a319 100644 --- a/resources/src/mediawiki.toc/toc.js +++ b/resources/src/mediawiki.toc/toc.js @@ -31,7 +31,12 @@ if ( !$tocToggleCheckbox.length && $tocTitle.length && $tocList.length && !$tocToggleLink.length ) { hideToc = mw.cookie.get( 'hidetoc' ) === '1'; - $tocToggleLink = $( '' ) + $tocToggleLink = $( '' ) + .attr( { + role: 'button', + tabindex: 0 + } ) + .addClass( 'togglelink' ) .text( mw.msg( hideToc ? 'showtoc' : 'hidetoc' ) ) .on( 'click keypress', function ( e ) { if ( -- 2.20.1