r109633 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109632‎ | r109633 | r109634 >
Date:18:47, 20 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Fix a bug in TokenCollector, and misc tweaks for template expansions.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/parse.js (modified) (history)
  • /trunk/extensions/VisualEditor/tests/parser/parserTests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/parserTests.js
@@ -183,7 +183,10 @@
184184 this.failOutputTests = 0;
185185
186186 // Create a new parser environment
187 - this.env = new MWParserEnvironment({ fetchTemplates: false });
 187+ this.env = new MWParserEnvironment({
 188+ fetchTemplates: false,
 189+ debug: false
 190+ });
188191 }
189192
190193
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js
@@ -11,7 +11,7 @@
1212 new TokenCollector(
1313 manager,
1414 function ( tokens ) {
15 - //manager.env.dp( 'noinclude stripping', tokens );
 15+ manager.env.dp( 'noinclude stripping', tokens );
1616 return {};
1717 }, // just strip it all..
1818 true, // match the end-of-input if </noinclude> is missing
Index: trunk/extensions/VisualEditor/modules/parser/parse.js
@@ -20,7 +20,7 @@
2121 wgScriptExtension: ".php",
2222 fetchTemplates: true,
2323 // enable/disable debug output using this switch
24 - debug: false
 24+ debug: true
2525 } ),
2626 parser = new ParserPipeline( env );
2727
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -16,8 +16,9 @@
1717 PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer,
1818 TokenTransformManager = require('./mediawiki.TokenTransformManager.js'),
1919
20 - NoInclude = require('./ext.core.NoOnlyInclude.js').NoInclude,
21 - OnlyInclude = require('./ext.core.NoOnlyInclude.js').OnlyInclude,
 20+ NoOnlyInclude = require('./ext.core.NoOnlyInclude.js'),
 21+ OnlyInclude = NoOnlyInclude.OnlyInclude,
 22+ NoInclude = NoOnlyInclude.NoInclude,
2223 QuoteTransformer = require('./ext.core.QuoteTransformer.js').QuoteTransformer,
2324 PostExpandParagraphHandler = require('./ext.core.PostExpandParagraphHandler.js')
2425 .PostExpandParagraphHandler,
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -291,15 +291,15 @@
292292 TemplateHandler.prototype._fetchTemplateAndTitle = function ( title, callback, tplExpandData ) {
293293 // @fixme normalize name?
294294 var self = this;
295 - if (this.manager.env.pageCache[title]) {
296 - // Unroll the stack here
 295+ if ( title in this.manager.env.pageCache ) {
 296+ // Unwind the stack
297297 process.nextTick(
298298 function () {
299299 callback( self.manager.env.pageCache[title], title )
300300 }
301301 );
302302 } else if ( ! this.manager.env.fetchTemplates ) {
303 - callback('Page/template fetching disabled, and no cache for ' + title);
 303+ callback( 'Page/template fetching disabled, and no cache for ' + title, title );
304304 } else {
305305
306306 // We are about to start an async request for a template, so mark this
@@ -406,11 +406,8 @@
407407 //console.log( 'response for ' + title + ' :' + body + ':' );
408408 if(error) {
409409 manager.env.dp(error);
410 - callback('Page/template fetch failure for title ' + title, title);
411 - return ;
412 - }
413 -
414 - if(response.statusCode == 200) {
 410+ self.emit('src', 'Page/template fetch failure for title ' + title, title);
 411+ } else if(response.statusCode == 200) {
415412 var src = '';
416413 try {
417414 //console.log( 'body: ' + body );
@@ -438,9 +435,11 @@
439436 manager.env.pageCache[title] = src;
440437 manager.env.dp(data);
441438 self.emit( 'src', src, title );
442 - // Remove self from request queue
443 - delete manager.env.requestQueue[title];
444439 }
 440+ // XXX: handle other status codes
 441+
 442+ // Remove self from request queue
 443+ delete manager.env.requestQueue[title];
445444 });
446445 }
447446
Index: trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js
@@ -51,28 +51,39 @@
5252 * XXX: Adjust to sync phase callback when that is modified!
5353 */
5454 TokenCollector.prototype._onDelimiterToken = function ( token, cb, frame ) {
55 - this.manager.addTransform( this._onAnyToken.bind ( this ),
56 - this.rank + this._anyDelta, 'any' );
57 - this.tokens.push ( token );
58 - if ( ! this.isActive ) {
59 - this.isActive = true;
60 - this.cb = cb;
61 - return { async: true };
62 - } else if ( token.type !== 'end' || this.toEnd ) {
63 - // end token
64 - var res = this.transformation ( this.tokens, this.cb, this.manager );
65 - this.tokens = [];
 55+ var res;
 56+ if ( this.isActive ) {
 57+ // finish processing
 58+ this.tokens.push ( token );
 59+ this.isActive = false;
6660 this.manager.removeTransform( this.rank + this._anyDelta, 'any' );
67 - this.isActive = false;
68 - // Transformation can be either sync or async, but receives all collected
69 - // tokens instead of a single token.
70 - return res;
71 - // XXX sync version: return tokens
72 - } else if ( token.type === 'end' && ! this.toEnd ) {
 61+ if ( token.type !== 'END' || this.toEnd ) {
 62+ // end token
 63+ res = this.transformation ( this.tokens, this.cb, this.manager );
 64+ this.tokens = [];
 65+ // Transformation can be either sync or async, but receives all collected
 66+ // tokens instead of a single token.
 67+ return res;
 68+ // XXX sync version: return tokens
 69+ } else {
 70+ // just return collected tokens
 71+ res = this.tokens;
 72+ this.tokens = [];
 73+ return { tokens: res };
 74+ }
 75+ } else if ( token.type !== 'END' ) {
 76+ this.manager.env.dp( 'starting collection on ', token );
 77+ // start collection
 78+ this.tokens.push ( token );
 79+ this.manager.addTransform( this._onAnyToken.bind ( this ),
 80+ this.rank + this._anyDelta, 'any' );
7381 // Did not encounter a matching end token before the end, and are not
7482 // supposed to collect to the end. So just return the tokens verbatim.
75 - this.isActive = false;
76 - return { tokens: this.tokens };
 83+ this.isActive = true;
 84+ return { };
 85+ } else {
 86+ // pass through end token
 87+ return { token: token };
7788 }
7889 };
7990

Status & tagging log