r110834 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110833‎ | r110834 | r110835 >
Date:10:28, 7 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Pluck a few low-hanging fruit in external link tokenization, and add a simple
localurl parser function implementation. 230 parser tests now passing.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js
@@ -59,7 +59,14 @@
6060 // Sanitizer, but UTF8 in link might actually be ok in HTML5
6161 testWhiteList["External link containing double-single-quotes with no space separating the url from text in italics"] = "<p><a href=\"http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm\"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a data-type=\"internal\" href=\"Museo Picasso (París)\">Museo Picasso</a>.</p>";
6262
 63+// plain percent sign is also valid in HTML5
 64+testWhiteList["Bug 4781, 5267: %28, %29 in URL"] = "<p><a href=\"http://www.example.com/?title=Ben-Hur_(1959_film)\" data-sourcePos=\"0:53\">http://www.example.com/?title=Ben-Hur_(1959_film)</a></p>";
6365
 66+testWhiteList["External links: wiki links within external link (Bug 3695)"] = "<p><a href=\"http://example.com\" data-type=\"external\" data-sourcePos=\"0:54\"></a><a data-type=\"internal\" href=\"wikilink\">wikilink</a> embedded in ext link</p>";
 67+
 68+testWhiteList["Bug 4781, 5267: %25 in URL"] = "<p><a href=\"http://www.example.com/?title=100%_Bran\" data-sourcePos=\"0:41\">http://www.example.com/?title=100%_Bran</a></p>";
 69+
 70+
6471 if (typeof module == "object") {
6572 module.exports.testWhiteList = testWhiteList;
6673 }
Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -199,7 +199,8 @@
200200 this.env = new MWParserEnvironment({
201201 fetchTemplates: false,
202202 debug: this.argv.debug,
203 - trace: this.argv.trace
 203+ trace: this.argv.trace,
 204+ wgScriptPath: ''
204205 });
205206 }
206207
@@ -313,7 +314,7 @@
314315 // general class and titles, typically on links
315316 .replace(/(title|class|rel)="[^"]+"/g, '')
316317 // strip red link markup, we do not check if a page exists yet
317 - .replace(/\/index.php\?title=|&amp;action=edit&amp;redlink=1/g, '')
 318+ .replace(/\/index.php\?title=([^']+)&amp;action=edit&amp;redlink=1/g, '$1')
318319 // the expected html has some extra space in tags, strip it
319320 .replace(/<a +href/g, '<a href')
320321 .replace(/" +>/g, '">');
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
@@ -212,6 +212,18 @@
213213 return [ res.toString() ];
214214 };
215215
 216+ParserFunctions.prototype['pf_localurl'] = function ( target, argList, argDict ) {
 217+ return ( this.manager.env.wgScriptPath + '/index' +
 218+ this.manager.env.wgScriptExtension + '?title=' +
 219+ target + '&' +
 220+ argList.map(
 221+ function( kv ) {
 222+ //console.log( JSON.stringify( kv ) );
 223+ return (kv.v !== '' && kv.k + '=' + kv.v ) || kv.k;
 224+ }
 225+ ).join('&')
 226+ );
 227+};
216228
217229
218230 /**
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -351,11 +351,11 @@
352352 }
353353
354354 link_preprocessor_text
355 - = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); }
 355+ = r:( t:[^'<~[{\n\r|!\]}\t &="']+ { return t.join(''); }
356356 / directive
 357+ / urlencoded_char
357358 / !inline_breaks no_punctuation_char
358359 / s:[.:,] !(space / eolf) { return s }
359 - / urlencoded_char
360360 / [&%] )+ {
361361 return flatten_string ( r );
362362 }
@@ -687,7 +687,8 @@
688688
689689
690690 urllink
691 - = target:url {
 691+ = ! { return syntaxFlags['extlink'] }
 692+ target:url {
692693 return [ new TagTk( 'a', [new KV('href', target)] )
693694 , target
694695 , new EndTagTk( 'a' )
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -77,7 +77,7 @@
7878 // Add token transformations..
7979 new QuoteTransformer( this.tokenPostProcessor );
8080 new PostExpandParagraphHandler( this.tokenPostProcessor );
81 - //new Sanitizer( this.tokenPostProcessor );
 81+ new Sanitizer( this.tokenPostProcessor );
8282
8383 //var citeExtension = new Cite( this.tokenTransformer );
8484

Status & tagging log