https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113716

Revision: 113716
Author:   gwicke
Date:     2012-03-13 12:32:31 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
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
    trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js
    trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
    trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt

Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-13 11:04:14 UTC (rev 113715)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-03-13 12:32:31 UTC (rev 113716)
@@ -60,7 +60,9 @@
                        content.push( tail );
                }
                
-               obj.attribs.push( new KV('data-mw-type', 'internal') );
+               //obj.attribs.push( new KV('data-mw-type', 'internal') );
+               obj.dataAttribs = token.dataAttribs;
+               obj.dataAttribs.linkType = 'internal';
                return { 
                        tokens: [obj].concat( content, new EndTagTk( 'a' ) )
                };
@@ -263,10 +265,10 @@
                        tokens:
                                [
                                        
-                                       new TagTk( 'a', [
-                                                               new KV('href', 
href),
-                                                               new 
KV('data-mw-type', 'external')
-                                                       ] )
+                                       new TagTk ( 'a', 
+                                                       [ new KV('href', href) 
], 
+                                                       token.dataAttribs
+                                       )
                                ].concat( content, [ new EndTagTk( 'a' )])
                };
        } else {

Modified: 
trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js    
2012-03-13 11:04:14 UTC (rev 113715)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js    
2012-03-13 12:32:31 UTC (rev 113716)
@@ -3,37 +3,40 @@
  * strings or String objects (if attributes are needed).
  */
 
-var toString = function() { return JSON.stringify( this ); }
+var toString = function() { return JSON.stringify( this ); };
 
-function TagTk( name, attribs ) { 
+function TagTk( name, attribs, dataAttribs ) { 
        //this.type = 'TAG';
        this.name = name;
        this.attribs = attribs || [];
+       this.dataAttribs = dataAttribs || {};
 }
-TagTk.prototype = new Object();
+TagTk.prototype = {};
 TagTk.prototype.toJSON = function () {
        return $.extend( { type: 'TagTk' }, this );
 };
 TagTk.prototype.constructor = TagTk;
 TagTk.prototype.toString = toString;
 
-function EndTagTk( name, attribs ) { 
+function EndTagTk( name, attribs, dataAttribs ) { 
        this.name = name;
        this.attribs = attribs || [];
+       this.dataAttribs = dataAttribs || {};
 }
-EndTagTk.prototype = new Object();
+EndTagTk.prototype = {};
 EndTagTk.prototype.toJSON = function () {
        return $.extend( { type: 'EndTagTk' }, this );
 };
 EndTagTk.prototype.constructor = EndTagTk;
 EndTagTk.prototype.toString = toString;
 
-function SelfclosingTagTk( name, attribs ) { 
+function SelfclosingTagTk( name, attribs, dataAttribs ) { 
        //this.type = 'SELFCLOSINGTAG';
        this.name = name;
        this.attribs = attribs || [];
+       this.dataAttribs = dataAttribs || {};
 }
-SelfclosingTagTk.prototype = new Object();
+SelfclosingTagTk.prototype = {};
 SelfclosingTagTk.prototype.toJSON = function () {
        return $.extend( { type: 'SelfclosingTagTk' }, this );
 };
@@ -43,7 +46,7 @@
 function NlTk( ) {
        //this.type = 'NEWLINE';
 }
-NlTk.prototype = new Object();
+NlTk.prototype = {};
 NlTk.prototype.toJSON = function () {
        return $.extend( { type: 'NlTk' }, this );
 };
@@ -53,7 +56,7 @@
 function CommentTk( value ) { 
        this.value = value;
 }
-CommentTk.prototype = new Object();
+CommentTk.prototype = {};
 CommentTk.prototype.toJSON = function () {
        return $.extend( { type: 'COMMENT' }, this );
 };
@@ -61,7 +64,7 @@
 CommentTk.prototype.toString = toString; 
 
 function EOFTk( ) { }
-EOFTk.prototype = new Object();
+EOFTk.prototype = {};
 EOFTk.prototype.toJSON = function () {
        return $.extend( { type: 'EOFTk' }, this );
 };

Modified: 
trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js     
2012-03-13 11:04:14 UTC (rev 113715)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js     
2012-03-13 12:32:31 UTC (rev 113716)
@@ -120,6 +120,7 @@
                                  ) 
                                ) || null;
                case '{':
+                       // {{!}} pipe templates..
                        return (
                                        counters.pipe ||
                                        counters.template                       
           

Modified: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-03-13 11:04:14 UTC (rev 113715)
+++ trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-03-13 12:32:31 UTC (rev 113716)
@@ -754,6 +754,8 @@
 
 template_param
   = name:template_param_name 
+    // Insanity: MW accepts |foo | = bar as a single param..
+    (pipe (space / newline)* &'=')?
     val:(
         s0:space* 
         "="
@@ -1825,5 +1827,8 @@
 // Special-case support for those pipe templates
 pipe = "|" / "{{!}}"
 
+// Similar, for tables..
+exclam = "!" / "{{;}}"
+
 /* Tabs do not mix well with the hybrid production syntax */
 /* vim: set filetype=javascript expandtab ts=4 sw=4 cindent : */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to