r111924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111923‎ | r111924 | r111925 >
Date:12:56, 20 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Push transformer setup a bit further into the attribute pipeline.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -334,11 +334,12 @@
335335 * @param {Object} args, the argument map for templates
336336 * @param {Object} env, the environment.
337337 */
338 -function AsyncTokenTransformManager ( childFactories, args, env ) {
 338+function AsyncTokenTransformManager ( childFactories, args, env, inputType ) {
339339 // Factory function for new AsyncTokenTransformManager creation with
340340 // default transforms enabled
341341 // Also sets up a tokenizer and phase-1-transform depending on the input format
342342 // nestedAsyncTokenTransformManager = manager.newChildPipeline( inputType, args );
 343+ this.inputType = inputType;
343344 this.childFactories = childFactories;
344345 this._construct();
345346 this._reset( args, env );
@@ -624,12 +625,13 @@
625626 * @constructor
626627 * @param {Object} environment.
627628 */
628 -function SyncTokenTransformManager ( env, phaseEndRank ) {
 629+function SyncTokenTransformManager ( env, phaseEndRank, inputType ) {
629630 // both inherited
630631 this._construct();
631632 this.phaseEndRank = phaseEndRank;
632633 this.args = {}; // no arguments at the top level
633634 this.env = env;
 635+ this.inputType = inputType;
634636 }
635637
636638 // Inherit from TokenTransformManager, and thus also from EventEmitter.
@@ -777,13 +779,14 @@
778780 this.outstanding++;
779781
780782 // transform the key
781 - pipe = this.manager.getAttributePipeline( this.manager.args );
782 - pipe.addListener( 'chunk',
 783+ pipe = this.manager.getAttributePipeline( this.manager.inputType,
 784+ this.manager.args );
 785+ pipe.addListener( 'chunk',
783786 this.onChunk.bind( this, this._returnAttributeKey.bind( this, i ) )
784 - );
 787+ );
785788 pipe.addListener( 'end',
786789 this.onEnd.bind( this, this._returnAttributeKey.bind( this, i ) )
787 - );
 790+ );
788791 pipe.process( attributes[i].k.concat([{type:'END'}]) );
789792 } else {
790793 kv.key = cur.k;
@@ -794,7 +797,8 @@
795798 this.outstanding++;
796799
797800 // transform the value
798 - pipe = this.manager.getAttributePipeline( this.manager.args );
 801+ pipe = this.manager.getAttributePipeline( this.manager.inputType,
 802+ this.manager.args );
799803 pipe.addListener( 'chunk',
800804 this.onChunk.bind( this, this._returnAttributeValue.bind( this, i ) )
801805 );
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -71,7 +71,8 @@
7272 this.inputPipeline.last.atTopLevel = true;
7373
7474
75 - this.tokenPostProcessor = new TokenTransformManager.SyncTokenTransformManager ( env );
 75+ this.tokenPostProcessor = new TokenTransformManager
 76+ .SyncTokenTransformManager ( env, inputType );
7677 this.tokenPostProcessor.listenForTokensFrom ( this.inputPipeline );
7778
7879
@@ -209,11 +210,11 @@
210211 /**
211212 * Token stream transformations.
212213 * This is where all the wiki-specific functionality is implemented.
213 - * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
 214+ * See
 215+ * https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
214216 */
215 - // XXX: Use this.env.config.transforms['inputType'][stage] or
216 - // somesuch to set up the transforms by input type
217 - var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env );
 217+ var tokenPreProcessor = new TokenTransformManager
 218+ .SyncTokenTransformManager ( this.env );
218219 tokenPreProcessor.listenForTokensFrom ( wikiTokenizer );
219220
220221 this._addTransformers( 'text/wiki', 'sync01',
@@ -225,14 +226,12 @@
226227 'input': this.makeInputPipeline.bind( this ),
227228 'attributes': this.makeAttributePipeline.bind( this )
228229 },
229 - args, this.env
 230+ args, this.env, inputType
230231 );
231232
232233 // Register template expansion extension
233234 this._addTransformers( 'text/wiki', 'async12',
234235 tokenExpander, ! isNoInclude );
235 - //new TemplateHandler( tokenExpander );
236 - //new AttributeExpander( tokenExpander );
237236
238237 tokenExpander.listenForTokensFrom ( tokenPreProcessor );
239238 // XXX: hack.
@@ -259,9 +258,9 @@
260259 * Factory for attribute transformations, with input type implicit in the
261260 * environment.
262261 */
263 -ParserPipeline.prototype.makeAttributePipeline = function ( args ) {
264 - if ( this.pipelineCache['text/wiki'].attribute.length ) {
265 - var pipe = this.pipelineCache['text/wiki'].attribute.pop();
 262+ParserPipeline.prototype.makeAttributePipeline = function ( inputType, args ) {
 263+ if ( this.pipelineCache[inputType].attribute.length ) {
 264+ var pipe = this.pipelineCache[inputType].attribute.pop();
266265 pipe.last.args = args;
267266 return pipe;
268267 } else {
@@ -270,7 +269,12 @@
271270 * This is where all the wiki-specific functionality is implemented.
272271 * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
273272 */
274 - var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env );
 273+ var tokenPreProcessor = new TokenTransformManager
 274+ .SyncTokenTransformManager ( this.env, inputType );
 275+
 276+ // XXX: set include flag properly!
 277+ //this._addTransformers( inputType, 'sync01', tokenPreProcessor, false );
 278+
275279 new NoInclude( tokenPreProcessor );
276280
277281 var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager (
@@ -278,14 +282,17 @@
279283 'input': this.makeInputPipeline.bind( this ),
280284 'attributes': this.makeAttributePipeline.bind( this )
281285 },
282 - args, this.env
 286+ args, this.env, inputType
283287 );
284 - new TemplateHandler( tokenExpander );
285 - new AttributeExpander( tokenExpander );
 288+ // Register template expansion extension
 289+ this._addTransformers( 'text/wiki', 'async12',
 290+ tokenExpander, false );
 291+ //new TemplateHandler( tokenExpander );
 292+ //new AttributeExpander( tokenExpander );
286293 tokenExpander.listenForTokensFrom ( tokenPreProcessor );
287294
288295 return new CachedTokenPipeline(
289 - this.cachePipeline.bind( this, 'text/wiki', 'attribute' ),
 296+ this.cachePipeline.bind( this, inputType, 'attribute' ),
290297 tokenPreProcessor,
291298 tokenExpander
292299 );
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -82,7 +82,7 @@
8383 JSON.stringify( attributes, null, 2 ) );
8484 new AttributeTransformManager(
8585 this.manager,
86 - this._returnAttributes.bind( this, tplExpandData )
 86+ this._returnAttributes.bind( this, tplExpandData )
8787 ).process( attributes );
8888
8989 // Unblock finish

Status & tagging log