r112685 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112684‎ | r112685 | r112686 >
Date:13:56, 29 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Start to move wikilink expansion to a separate async token transformer.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js (added) (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/pegTokenizer.pegjs.txt
@@ -746,12 +746,11 @@
747747 // class. Can we work out a static negative class instead?
748748 // XXX: Exclude uppercase chars from non-latin languages too!
749749 trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* {
750 - var obj = new TagTk( 'a',
751 - [
752 - new KV('data-mw-type', 'internal')
753 - ] ),
 750+ var obj = new SelfclosingTagTk( 'wikilink' ),
754751 textTokens = [];
755752 obj.attribs.push( new KV('href', target) );
 753+
 754+ // Deal with content. XXX: Properly support pipe-trick etc
756755 if (lcontent && lcontent.length) {
757756 textTokens = lcontent;
758757 if (trail) {
@@ -765,8 +764,10 @@
766765 textTokens = $.extend(true, [], target);
767766 }
768767 }
 768+
 769+ obj.attribs.push( new KV( 'content', flatten( textTokens ) ) );
769770 //console.warn( "XXX:" + pp([obj].concat(textTokens, [new EndTagTk( 'a' )])) );
770 - return [obj].concat(textTokens, [new EndTagTk( 'a' )]);
 771+ return [obj];
771772 }
772773
773774 link_text
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
@@ -65,6 +65,7 @@
6666 return { async: true };
6767 }
6868 } else {
 69+ token.rank = this.rank;
6970 return { token: token };
7071 }
7172 };
@@ -80,6 +81,7 @@
8182 // Remove the target from the attributes
8283 expandData.token.attribs = attributes;
8384 if ( expandData.async ) {
 85+ expandData.token.rank = this.rank;
8486 expandData.cb( [expandData.token], false );
8587 }
8688 };
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
@@ -0,0 +1,48 @@
 2+/**
 3+ * Simple link handler. Registers after template expansions, as an
 4+ * asynchronous transform.
 5+ *
 6+ * @author Gabriel Wicke <gwicke@wikimedia.org>
 7+ *
 8+ * * Collect description/parameter tokens between 'a' tags
 9+ * * Extract image options and add image html if target is media/image
 10+ * namespace
 11+ * *
 12+ *
 13+ *
 14+ * TODO: keep round-trip information in meta tag or the like
 15+ *
 16+ *
 17+ *
 18+ * Pro/Contra of single token vs. tags and tokens
 19+ * - Need to collect description tokens between a and /a
 20+ * + noinclude etc handled automatically by having all tokens on content level
 21+ */
 22+
 23+function WikiLinkHandler( manager, isInclude ) {
 24+ this.manager = manager;
 25+ this.manager.addTransform( this.onWikiLink.bind( this ), this.rank, 'tag', 'wikilink' );
 26+}
 27+
 28+WikiLinkHandler.prototype.rank = 1.15; // after AttributeExpander
 29+
 30+WikiLinkHandler.prototype.onWikiLink = function ( token, manager, cb ) {
 31+ // Split off and normalize namespace
 32+ // Compare with image/media namespaces
 33+ // handle image
 34+ // handle
 35+ // Check if page exists
 36+ //
 37+ var obj = new TagTk( 'a', [ this.manager.env.lookupKV( token.attribs, 'href' ) ] );
 38+ obj.attribs.push( new KV('data-mw-type', 'internal') );
 39+ var out = [obj].concat( this.manager.env.lookupKV( token.attribs, 'content' ).v,
 40+ new EndTagTk( 'a' ) );
 41+ //console.warn( JSON.stringify( out, null, 2 ) );
 42+ return { tokens: out };
 43+};
 44+
 45+
 46+
 47+if (typeof module == "object") {
 48+ module.exports.WikiLinkHandler = WikiLinkHandler;
 49+}
Property changes on: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js
___________________________________________________________________
Added: svn:eol-style
150 + native
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -26,6 +26,7 @@
2727 Sanitizer = require('./ext.core.Sanitizer.js').Sanitizer,
2828 TemplateHandler = require('./ext.core.TemplateHandler.js').TemplateHandler,
2929 AttributeExpander = require('./ext.core.AttributeExpander.js').AttributeExpander,
 30+ WikiLinkHandler = require('./ext.core.LinkHandler.js').WikiLinkHandler,
3031 Cite = require('./ext.Cite.js').Cite,
3132 FauxHTML5 = require('./mediawiki.HTML5TreeBuilder.node.js').FauxHTML5,
3233 DOMPostProcessor = require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor,
@@ -165,7 +166,8 @@
166167 // Expand attributes after templates to avoid expanding unused branches
167168 // XXX: Should we support further processing after attribute
168169 // expansion?
169 - AttributeExpander
 170+ AttributeExpander,
 171+ WikiLinkHandler
170172 /* ExtensionHandler1, */
171173 /* ExtensionHandler2, */
172174 ],

Status & tagging log