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

Revision: 112685
Author:   gwicke
Date:     2012-02-29 13:56:29 +0000 (Wed, 29 Feb 2012)
Log Message:
-----------
Start to move wikilink expansion to a separate async token transformer.

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
    trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
    trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt

Added Paths:
-----------
    trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js

Modified: 
trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js  
2012-02-29 13:43:25 UTC (rev 112684)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js  
2012-02-29 13:56:29 UTC (rev 112685)
@@ -65,6 +65,7 @@
                        return { async: true };
                }
        } else {
+               token.rank = this.rank;
                return { token: token };
        }
 };
@@ -80,6 +81,7 @@
        // Remove the target from the attributes
        expandData.token.attribs = attributes;
        if ( expandData.async ) {
+               expandData.token.rank = this.rank;
                expandData.cb( [expandData.token], false );
        }
 };

Added: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
                        (rev 0)
+++ trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js        
2012-02-29 13:56:29 UTC (rev 112685)
@@ -0,0 +1,48 @@
+/**
+ * Simple link handler. Registers after template expansions, as an
+ * asynchronous transform.
+ *
+ * @author Gabriel Wicke <[email protected]>
+ * 
+ * * Collect description/parameter tokens between 'a' tags
+ * * Extract image options and add image html if target is media/image
+ *   namespace
+ * * 
+ *
+ *
+ * TODO: keep round-trip information in meta tag or the like
+ *
+ *
+ *
+ * Pro/Contra of single token vs. tags and tokens
+ * - Need to collect description tokens between a and /a
+ * + noinclude etc handled automatically by having all tokens on content level
+ */
+
+function WikiLinkHandler( manager, isInclude ) {
+       this.manager = manager;
+       this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 
'tag', 'wikilink' );
+}
+
+WikiLinkHandler.prototype.rank = 1.15; // after AttributeExpander
+
+WikiLinkHandler.prototype.onWikiLink = function ( token, manager, cb ) {
+       // Split off and normalize namespace
+       // Compare with image/media namespaces
+       //      handle image
+       //      handle 
+       // Check if page exists
+       // 
+       var obj = new TagTk( 'a', [ this.manager.env.lookupKV( token.attribs, 
'href' ) ] );
+    obj.attribs.push( new KV('data-mw-type', 'internal') );
+       var out = [obj].concat( this.manager.env.lookupKV( token.attribs, 
'content' ).v, 
+                                                       new EndTagTk( 'a' ) );
+       //console.warn( JSON.stringify( out, null, 2 ) );
+       return { tokens: out };
+};
+
+
+
+if (typeof module == "object") {
+       module.exports.WikiLinkHandler = WikiLinkHandler;
+}


Property changes on: 
trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js    
2012-02-29 13:43:25 UTC (rev 112684)
+++ trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js    
2012-02-29 13:56:29 UTC (rev 112685)
@@ -26,6 +26,7 @@
        Sanitizer                   = 
require('./ext.core.Sanitizer.js').Sanitizer,
        TemplateHandler             = 
require('./ext.core.TemplateHandler.js').TemplateHandler,
        AttributeExpander            = 
require('./ext.core.AttributeExpander.js').AttributeExpander,
+       WikiLinkHandler             = 
require('./ext.core.LinkHandler.js').WikiLinkHandler,
        Cite                        = require('./ext.Cite.js').Cite,
        FauxHTML5                   = 
require('./mediawiki.HTML5TreeBuilder.node.js').FauxHTML5,
        DOMPostProcessor            = 
require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor,
@@ -165,7 +166,8 @@
                                // Expand attributes after templates to avoid 
expanding unused branches
                                // XXX: Should we support further processing 
after attribute
                                // expansion?
-                               AttributeExpander
+                               AttributeExpander,
+                               WikiLinkHandler
                                /* ExtensionHandler1, */
                                /* ExtensionHandler2, */
                        ],

Modified: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
===================================================================
--- trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-02-29 13:43:25 UTC (rev 112684)
+++ trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 
2012-02-29 13:56:29 UTC (rev 112685)
@@ -746,12 +746,11 @@
     // class. Can we work out a static negative class instead?
     // XXX: Exclude uppercase chars from non-latin languages too!
     trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* {
-      var obj = new TagTk( 'a', 
-                [
-                    new KV('data-mw-type', 'internal')
-                ] ),
+      var obj = new SelfclosingTagTk( 'wikilink' ),
           textTokens = [];
       obj.attribs.push( new KV('href', target) );
+
+      // Deal with content. XXX: Properly support pipe-trick etc
       if (lcontent && lcontent.length) {
           textTokens = lcontent;
           if (trail) {
@@ -765,8 +764,10 @@
               textTokens = $.extend(true, [], target);
           }
       }
+
+      obj.attribs.push( new KV( 'content', flatten( textTokens ) ) );
       //console.warn( "XXX:" + pp([obj].concat(textTokens, [new EndTagTk( 'a' 
)])) );
-      return [obj].concat(textTokens, [new EndTagTk( 'a' )]);
+      return [obj];
   }
 
 link_text


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

Reply via email to