r110769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110768‎ | r110769 | r110770 >
Date:19:15, 6 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Temporarily disable the sanitizer and start to support preprocessor
functionality (comments, templates, template arguments) in arbitrary
attributes. The grammar for this is still quite rough, will need to
consolidate that area.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
@@ -44,7 +44,7 @@
4545
4646 // #ifeq
4747 ParserFunctions.prototype['pf_#ifeq'] = function ( target, argList, argDict ) {
48 - if ( ! argList.length ) {
 48+ if ( argList.length < 2 ) {
4949 return [];
5050 } else {
5151 if ( target.trim() === this.manager.env.tokensToString( argList[0][1] ).trim() ) {
@@ -80,7 +80,9 @@
8181 };
8282
8383 ParserFunctions.prototype['pf_#tag'] = function ( target, argList, argDict ) {
84 - return [new TagTk(target, argList)];
 84+ return [ new TagTk( target ),
 85+ argList[0].v,
 86+ new EndTagTk( target ) ];
8587 };
8688
8789 // A first approximation, anyway..
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -29,6 +29,36 @@
3030 return es;
3131 };
3232
 33+
 34+ var flatten_string = function ( c ) {
 35+ var out = [],
 36+ text = [];
 37+ c = flatten(c);
 38+ for (var i = 0, l = c.length; i < l; i++) {
 39+ var ci = c[i];
 40+ if (ci.constructor === String) {
 41+ if(ci !== '') {
 42+ text.push(ci);
 43+ }
 44+ } else {
 45+ if (text.length) {
 46+ out.push( text.join('') );
 47+ text = [];
 48+ }
 49+ out.push(ci);
 50+ }
 51+ }
 52+ if (text.length) {
 53+ out.push( text.join('') );
 54+ }
 55+
 56+ if ( out.length === 1 && out[0].constructor === String ) {
 57+ return out[0];
 58+ } else {
 59+ return out;
 60+ }
 61+ };
 62+
3363 // Remove escaped quotes from attributes etc
3464 // This was in the original PEG parser, but could not find anything in
3565 // MediaWiki that supports \' and \"-style escaping. So remove? -- gwicke
@@ -308,6 +338,40 @@
309339 / ' ' & ':' { return "\u00a0"; }
310340 / t:text_char )+
311341
 342+directive
 343+ = comment
 344+ / tplarg_or_template
 345+ / htmlentity
 346+
 347+spaceless_preprocessor_text
 348+ = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); }
 349+ / directive
 350+ / !inline_breaks !' ' text_char )+ {
 351+ return flatten_string ( r );
 352+ }
 353+
 354+link_preprocessor_text
 355+ = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); }
 356+ / directive
 357+ / !inline_breaks no_punctuation_char
 358+ / s:[.:,] !(space / eolf) { return s }
 359+ / urlencoded_char
 360+ / [&%] )+ {
 361+ return flatten_string ( r );
 362+ }
 363+
 364+// Plain text, but can contain templates, template arguments, comments etc-
 365+// all stuff that is normally handled by the preprocessor
 366+// Returns either a list of tokens, or a plain string (if nothing is to be
 367+// processed).
 368+preprocessor_text
 369+ = r:( t:[^'<~[{\n\r\t|!\]} &=]+ { return t.join(''); }
 370+ / directive
 371+ / !inline_breaks text_char )+ {
 372+ return flatten_string ( r );
 373+ }
 374+
 375+
312376 /*
313377 '//', // for protocol-relative URLs, but not in text!
314378 'ftp://',
@@ -553,6 +617,7 @@
554618 = //& { dp('inline_element enter' + input.substr(pos, 10)); return true; }
555619 & '<' ( comment / xmlish_tag )
556620 / & '{' ( & '{{{{{' template / tplarg / template )
 621+ / & '{' tplarg_or_template
557622 /// & '{' ( tplarg / template )
558623 // Eat three opening brackets as text.
559624 / '[[[' { return '[[[' }
@@ -632,9 +697,9 @@
633698 extlink
634699 = "["
635700 & { return setFlag('extlink'); }
636 - target:(url / tplarg / template)
637 - space*
638 - text:inlineline?
 701+ //target:urllink
 702+ target:link_preprocessor_text
 703+ text:(space* t:inlineline { return t } )?
639704 "]" {
640705 clearFlag('extlink');
641706 if ( text == '' ) {
@@ -642,13 +707,15 @@
643708 text = [ "[" + linkCount + "]" ];
644709 linkCount++;
645710 }
646 - return [
 711+ var res = [
647712 new TagTk( 'a', [
648713 new KV('href', target),
649714 new KV('data-type', 'external')
650715 ] ),
651716 ].concat( text
652717 , [ new EndTagTk( 'a' )]);
 718+ //console.log( JSON.stringify( res, null, 2 ) );
 719+ return res;
653720 }
654721 / "[" & { clearFlag('extlink'); return false; }
655722
@@ -713,6 +780,8 @@
714781 return flatten( a ).join('');
715782 }
716783
 784+tplarg_or_template = & '{{{{{' template / tplarg / template
 785+
717786 template
718787 = "{{" target:template_param_text
719788 params:(newline? "|" newline? p:template_param { return p })*
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
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -168,7 +168,9 @@
169169 var prefix = target.split(':', 1)[0].toLowerCase().trim();
170170 if ( prefix && 'pf_' + prefix in this.parserFunctions ) {
171171 var funcArg = target.substr( prefix.length + 1 );
172 - this.manager.env.tp( 'func prefix: ' + prefix + ' arg=' + funcArg );
 172+ this.manager.env.tp( 'func prefix: ' + prefix +
 173+ ' args=' + JSON.stringify( tplExpandData.expandedArgs, null, 2) +
 174+ ' funcArg=' + funcArg);
173175 //this.manager.env.dp( 'entering prefix', funcArg, args );
174176 res = this.parserFunctions[ 'pf_' + prefix ]( funcArg,
175177 tplExpandData.expandedArgs, args );
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
@@ -116,10 +116,11 @@
117117 }
118118 for ( var i = 0, l = tokens.length; i < l; i++ ) {
119119 var token = tokens[i];
120 - if ( ! token ) {
 120+ if ( token === undefined ) {
121121 console.trace();
122 - this.dp( 'MWParserEnvironment.tokensToString, invalid token: ' +
123 - JSON.stringify( token ) );
 122+ this.tp( 'MWParserEnvironment.tokensToString, invalid token: ' +
 123+ JSON.stringify( token ) +
 124+ ' tokens:' + JSON.stringify( tokens, null, 2 ));
124125 continue;
125126 }
126127 if ( token.constructor === String ) {

Status & tagging log