https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114331
Revision: 114331 Author: rsterbin Date: 2012-03-20 23:31:15 +0000 (Tue, 20 Mar 2012) Log Message: ----------- Followup to 114064; updated regex to avoid cascading replacements and catch two-digit replacement codes Modified Paths: -------------- trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js Modified: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js =================================================================== --- trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js 2012-03-20 23:30:51 UTC (rev 114330) +++ trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js 2012-03-20 23:31:15 UTC (rev 114331) @@ -2914,20 +2914,23 @@ */ $.articleFeedbackv5.buildLink = function ( fulltext, link1, link2, link3 ) { var full = mw.html.escape( mw.msg( fulltext ) ); - for ( var i = 1; i < arguments.length; i++ ) { - var sub = arguments[i]; - var re = new RegExp("\\$" + i, 'g'); + var args = arguments; + return full.replace( /\$(\d+)/g, function( str, number ) { + var i = parseInt( number, 10 ); + var sub = args[i]; + var replacement = ''; if ( sub.tag == 'quotes' ) { - full = full.replace( re, '"' + mw.msg( sub.text ) + '"' ); + replacement = '"' + mw.msg( sub.text ) + '"'; } else { - full = full.replace( re, mw.html.element( + replacement = mw.html.element( 'tag' in sub ? sub.tag : 'a', $.articleFeedbackv5.attribs( sub ), mw.msg( sub.text ) - ).toString() ); + ).toString(); } - } - return full; + console.log(replacement); + return replacement; + } ); }; // }}} _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs