[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ApiSandbox: Better handling of parsed messages

2016-12-01 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: ApiSandbox: Better handling of parsed messages
..


ApiSandbox: Better handling of parsed messages

There are several places where we're parsing a message to an HTML string
and passing it into ooui in a way that it'll interpret it as text. There
are more where we're handling it properly, but by parsing HTML strings
outselves instead of letting mw.Message do it.

So, let's add a Util function that will parse a message using
.parseDom() and apply our fixups.

Change-Id: I1f71916ac2fb3567c2fa2dffc64c4c8c91050ee9
---
M resources/src/mediawiki.special/mediawiki.special.apisandbox.js
1 file changed, 45 insertions(+), 28 deletions(-)

Approvals:
  Bartosz DziewoƄski: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js 
b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
index d2015d8..60155fd 100644
--- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
+++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
@@ -51,9 +51,7 @@
tokenWidget: {
alertTokenError: function ( code, error ) {
windowManager.openWindow( 'errorAlert', {
-   title: mw.message(
-   
'apisandbox-results-fixtoken-fail', this.paramInfo.tokentype
-   ).parse(),
+   title: Util.parseMsg( 
'apisandbox-results-fixtoken-fail', this.paramInfo.tokentype ),
message: error,
actions: [
{
@@ -218,7 +216,7 @@
};
 
/**
-* @class mw.special.ApiSandbox.Utils
+* @class mw.special.ApiSandbox.Util
 * @private
 */
Util = {
@@ -591,17 +589,42 @@
},
 
/**
-* Parse an HTML string, adding target="_blank" to any links
+* Parse an HTML string and call Util.fixupHTML()
 *
 * @param {string} html HTML to parse
 * @return {jQuery}
 */
parseHTML: function ( html ) {
var $ret = $( $.parseHTML( html ) );
-   $ret.filter( 'a' ).add( $ret.find( 'a' ) )
+   return Util.fixupHTML( $ret );
+   },
+
+   /**
+* Parse an i18n message and call Util.fixupHTML()
+*
+* @param {string} key Key of message to get
+* @param {...Mixed} parameters Values for $N replacements
+* @return {jQuery}
+*/
+   parseMsg: function () {
+   var $ret = mw.message.apply( mw.message, arguments 
).parseDom();
+   return Util.fixupHTML( $ret );
+   },
+
+   /**
+* Fix HTML for ApiSandbox display
+*
+* Fixes are:
+* - Add target="_blank" to any links
+*
+* @param {jQuery} $html DOM to process
+* @return {jQuery}
+*/
+   fixupHTML: function ( $html ) {
+   $html.filter( 'a' ).add( $html.find( 'a' ) )
.filter( '[href]:not([target])' )
.attr( 'target', '_blank' );
-   return $ret;
+   return $html;
}
};
 
@@ -683,7 +706,7 @@
 
$content
.empty()
-   .append( $( '' ).append( mw.message( 
'apisandbox-intro' ).parse() ) )
+   .append( $( '' ).append( Util.parseMsg( 
'apisandbox-intro' ) ) )
.append(
$( '', { id: 'mw-apisandbox-ui' } )
.append( $toolbar )
@@ -896,8 +919,8 @@
$.when.apply( $, deferreds ).done( function () {
if ( $.inArray( false, arguments ) !== -1 ) {
windowManager.openWindow( 'errorAlert', 
{
-   title: mw.message( 
'apisandbox-submit-invalid-fields-title' ).parse(),
-   message: mw.message( 
'apisandbox-submit-invalid-fields-message' ).parse(),
+   title: Util.parseMsg( 
'apisandbox-submit-invalid-fields-title' ),
+   message: Util.parseMsg( 
'apisandbox-submit-invalid-

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: ApiSandbox: Better handling of parsed messages

2016-11-28 Thread Anomie (Code Review)
Anomie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323855

Change subject: ApiSandbox: Better handling of parsed messages
..

ApiSandbox: Better handling of parsed messages

There are several places where we're parsing a message to an HTML string
and passing it into ooui in a way that it'll interpret it as text. There
are more where we're handling it properly, but by parsing HTML strings
outselves instead of letting mw.Message do it.

So, let's add a Util function that will parse a message using
.parseDom() and apply our fixups.

Change-Id: I1f71916ac2fb3567c2fa2dffc64c4c8c91050ee9
---
M resources/src/mediawiki.special/mediawiki.special.apisandbox.js
1 file changed, 45 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/55/323855/1

diff --git a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js 
b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
index d2015d8..60155fd 100644
--- a/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
+++ b/resources/src/mediawiki.special/mediawiki.special.apisandbox.js
@@ -51,9 +51,7 @@
tokenWidget: {
alertTokenError: function ( code, error ) {
windowManager.openWindow( 'errorAlert', {
-   title: mw.message(
-   
'apisandbox-results-fixtoken-fail', this.paramInfo.tokentype
-   ).parse(),
+   title: Util.parseMsg( 
'apisandbox-results-fixtoken-fail', this.paramInfo.tokentype ),
message: error,
actions: [
{
@@ -218,7 +216,7 @@
};
 
/**
-* @class mw.special.ApiSandbox.Utils
+* @class mw.special.ApiSandbox.Util
 * @private
 */
Util = {
@@ -591,17 +589,42 @@
},
 
/**
-* Parse an HTML string, adding target="_blank" to any links
+* Parse an HTML string and call Util.fixupHTML()
 *
 * @param {string} html HTML to parse
 * @return {jQuery}
 */
parseHTML: function ( html ) {
var $ret = $( $.parseHTML( html ) );
-   $ret.filter( 'a' ).add( $ret.find( 'a' ) )
+   return Util.fixupHTML( $ret );
+   },
+
+   /**
+* Parse an i18n message and call Util.fixupHTML()
+*
+* @param {string} key Key of message to get
+* @param {...Mixed} parameters Values for $N replacements
+* @return {jQuery}
+*/
+   parseMsg: function () {
+   var $ret = mw.message.apply( mw.message, arguments 
).parseDom();
+   return Util.fixupHTML( $ret );
+   },
+
+   /**
+* Fix HTML for ApiSandbox display
+*
+* Fixes are:
+* - Add target="_blank" to any links
+*
+* @param {jQuery} $html DOM to process
+* @return {jQuery}
+*/
+   fixupHTML: function ( $html ) {
+   $html.filter( 'a' ).add( $html.find( 'a' ) )
.filter( '[href]:not([target])' )
.attr( 'target', '_blank' );
-   return $ret;
+   return $html;
}
};
 
@@ -683,7 +706,7 @@
 
$content
.empty()
-   .append( $( '' ).append( mw.message( 
'apisandbox-intro' ).parse() ) )
+   .append( $( '' ).append( Util.parseMsg( 
'apisandbox-intro' ) ) )
.append(
$( '', { id: 'mw-apisandbox-ui' } )
.append( $toolbar )
@@ -896,8 +919,8 @@
$.when.apply( $, deferreds ).done( function () {
if ( $.inArray( false, arguments ) !== -1 ) {
windowManager.openWindow( 'errorAlert', 
{
-   title: mw.message( 
'apisandbox-submit-invalid-fields-title' ).parse(),
-   message: mw.message( 
'apisandbox-submit-invalid-fields-message' ).parse(),
+   title: Util.parseMsg( 
'apisandbox-submit-invalid-fields-title' ),
+   message: Util.parseMsg(