r113716 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113715‎ | r113716 | r113717 >
Date:12:32, 13 March 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Move link types to data-mw-rt, and support some more template tokenization
edge cases. For example, the PHP parser treats | foo | = bar | as | foo = bar |,
believe it or not ;)
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js
@@ -3,37 +3,40 @@
44 * strings or String objects (if attributes are needed).
55 */
66
7 -var toString = function() { return JSON.stringify( this ); }
 7+var toString = function() { return JSON.stringify( this ); };
88
9 -function TagTk( name, attribs ) {
 9+function TagTk( name, attribs, dataAttribs ) {
1010 //this.type = 'TAG';
1111 this.name = name;
1212 this.attribs = attribs || [];
 13+ this.dataAttribs = dataAttribs || {};
1314 }
14 -TagTk.prototype = new Object();
 15+TagTk.prototype = {};
1516 TagTk.prototype.toJSON = function () {
1617 return $.extend( { type: 'TagTk' }, this );
1718 };
1819 TagTk.prototype.constructor = TagTk;
1920 TagTk.prototype.toString = toString;
2021
21 -function EndTagTk( name, attribs ) {
 22+function EndTagTk( name, attribs, dataAttribs ) {
2223 this.name = name;
2324 this.attribs = attribs || [];
 25+ this.dataAttribs = dataAttribs || {};
2426 }
25 -EndTagTk.prototype = new Object();
 27+EndTagTk.prototype = {};
2628 EndTagTk.prototype.toJSON = function () {
2729 return $.extend( { type: 'EndTagTk' }, this );
2830 };
2931 EndTagTk.prototype.constructor = EndTagTk;
3032 EndTagTk.prototype.toString = toString;
3133
32 -function SelfclosingTagTk( name, attribs ) {
 34+function SelfclosingTagTk( name, attribs, dataAttribs ) {
3335 //this.type = 'SELFCLOSINGTAG';
3436 this.name = name;
3537 this.attribs = attribs || [];
 38+ this.dataAttribs = dataAttribs || {};
3639 }
37 -SelfclosingTagTk.prototype = new Object();
 40+SelfclosingTagTk.prototype = {};
3841 SelfclosingTagTk.prototype.toJSON = function () {
3942 return $.extend( { type: 'SelfclosingTagTk' }, this );
4043 };
@@ -43,7 +46,7 @@
4447 function NlTk( ) {
4548 //this.type = 'NEWLINE';
4649 }
47 -NlTk.prototype = new Object();
 50+NlTk.prototype = {};
4851 NlTk.prototype.toJSON = function () {
4952 return $.extend( { type: 'NlTk' }, this );
5053 };
@@ -53,7 +56,7 @@
5457 function CommentTk( value ) {
5558 this.value = value;
5659 }
57 -CommentTk.prototype = new Object();
 60+CommentTk.prototype = {};
5861 CommentTk.prototype.toJSON = function () {
5962 return $.extend( { type: 'COMMENT' }, this );
6063 };
@@ -61,7 +64,7 @@
6265 CommentTk.prototype.toString = toString;
6366
6467 function EOFTk( ) { }
65 -EOFTk.prototype = new Object();
 68+EOFTk.prototype = {};
6669 EOFTk.prototype.toJSON = function () {
6770 return $.extend( { type: 'EOFTk' }, this );
6871 };
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -754,6 +754,8 @@
755755
756756 template_param
757757 = name:template_param_name
 758+ // Insanity: MW accepts |foo | = bar as a single param..
 759+ (pipe (space / newline)* &'=')?
758760 val:(
759761 s0:space*
760762 "="
@@ -1825,5 +1827,8 @@
18261828 // Special-case support for those pipe templates
18271829 pipe = "|" / "{{!}}"
18281830
 1831+// Similar, for tables..
 1832+exclam = "!" / "{{;}}"
 1833+
18291834 /* Tabs do not mix well with the hybrid production syntax */
18301835 /* vim: set filetype=javascript expandtab ts=4 sw=4 cindent : */
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
@@ -60,7 +60,9 @@
6161 content.push( tail );
6262 }
6363
64 - obj.attribs.push( new KV('data-mw-type', 'internal') );
 64+ //obj.attribs.push( new KV('data-mw-type', 'internal') );
 65+ obj.dataAttribs = token.dataAttribs;
 66+ obj.dataAttribs.linkType = 'internal';
6567 return {
6668 tokens: [obj].concat( content, new EndTagTk( 'a' ) )
6769 };
@@ -263,10 +265,10 @@
264266 tokens:
265267 [
266268
267 - new TagTk( 'a', [
268 - new KV('href', href),
269 - new KV('data-mw-type', 'external')
270 - ] )
 269+ new TagTk ( 'a',
 270+ [ new KV('href', href) ],
 271+ token.dataAttribs
 272+ )
271273 ].concat( content, [ new EndTagTk( 'a' )])
272274 };
273275 } else {
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
@@ -120,6 +120,7 @@
121121 )
122122 ) || null;
123123 case '{':
 124+ // {{!}} pipe templates..
124125 return (
125126 counters.pipe ||
126127 counters.template

Status & tagging log