r109712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109711‎ | r109712 | r109713 >
Date:01:27, 22 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
A bit of template expansion bug fixing and parser function documentation
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -342,6 +342,7 @@
343343 this.loopAndDepthCheck,
344344 this.env.normalizeTitle( this.env.tokensToString ( title ) )
345345 );
 346+ child.title = title;
346347 return pipe;
347348 };
348349
@@ -357,6 +358,7 @@
358359 AsyncTokenTransformManager.prototype.getAttributePipeline = function ( inputType, args ) {
359360 var pipe = this.childFactories.attributes( inputType, args );
360361 var child = pipe.last;
 362+ child.title = this.title;
361363 child.loopAndDepthCheck = new LoopAndDepthCheck ( this.loopAndDepthCheck, '' );
362364 return pipe;
363365 };
@@ -884,12 +886,14 @@
885887 tokens = this.accum.concat( tokens );
886888 // A sibling will transform tokens, so we don't have to do this
887889 // again.
888 - this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done and parentCB ' +
 890+ this.manager.env.dp( 'TokenAccumulator._returnTokens: ' +
 891+ 'sibling done and parentCB ' +
889892 JSON.stringify( tokens ) );
890893 this.parentCB( tokens, false );
891894 return null;
892895 } else if ( this.outstanding === 1 && notYetDone ) {
893 - this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done and parentCB but notYetDone ' +
 896+ this.manager.env.dp( 'TokenAccumulator._returnTokens: ' +
 897+ 'sibling done and parentCB but notYetDone ' +
894898 JSON.stringify( tokens ) );
895899 // Sibling is not yet done, but child is. Return own parentCB to
896900 // allow the sibling to go direct, and call back parent with
@@ -901,7 +905,8 @@
902906 this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done, but not overall. notYetDone=' +
903907 notYetDone + ', this.outstanding=' + this.outstanding +
904908 ', this.accum=' +
905 - JSON.stringify( this.accum, null, 2 ) );
 909+ JSON.stringify( this.accum, null, 2 ) +
 910+ ' manager.title=', this.manager.title );
906911 }
907912
908913
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
@@ -1,5 +1,8 @@
22 /**
3 - * Some parser functions
 3+ * Some parser functions, and quite a bunch of stubs of parser functions.
 4+ * Instantiated and called by the TemplateHandler extension.
 5+ *
 6+ * @author Gabriel Wicke <gwicke@wikimedia.org>
47 */
58
69 function ParserFunctions ( manager ) {
@@ -53,9 +56,11 @@
5457 ParserFunctions.prototype['pf_lc'] = function ( target, argList, argDict ) {
5558 return [{type: 'TEXT', value: target.toLowerCase()}];
5659 };
 60+
5761 ParserFunctions.prototype['pf_uc'] = function ( target, argList, argDict ) {
5862 return [{type: 'TEXT', value: target.toUpperCase()}];
5963 };
 64+
6065 ParserFunctions.prototype['pf_ucfirst'] = function ( target, argList, argDict ) {
6166 if ( target ) {
6267 return [{
@@ -66,6 +71,7 @@
6772 return [];
6873 }
6974 };
 75+
7076 ParserFunctions.prototype['pf_lcfirst'] = function ( target, argList, argDict ) {
7177 if ( target ) {
7278 return [{
@@ -81,6 +87,11 @@
8288 return [{type: 'TAG', name: target, attribs: argList}];
8389 };
8490
 91+
 92+/**
 93+ * Stub section: Pick any of these and actually implement them!
 94+ */
 95+
8596 // FIXME
8697 ParserFunctions.prototype['pf_#ifexpr'] = function ( target, argList, argDict ) {
8798 return [];
@@ -94,8 +105,6 @@
95106 ParserFunctions.prototype['pf_#ifexist'] = function ( target, argList, argDict ) {
96107 return [];
97108 };
98 -
99 -// pure fake..
100109 ParserFunctions.prototype['pf_formatnum'] = function ( target, argList, argDict ) {
101110 return [{type: 'TEXT', value: target}];
102111 };
@@ -124,22 +133,11 @@
125134 return [{type: 'TEXT', value: 'Main'}];
126135 };
127136
128 -// FIXME! This is just fake.
129137 ParserFunctions.prototype['pf_#time'] = function ( target, argList, argDict ) {
130138 return [{type: 'TEXT', value: new Date().toString()}];
131139 };
132140
133 -// #time
134 -// #ifexp
135 -// PAGENAME
136 -// #expr
137 -// NAMESPACE
138 -// #iferror
139 -//
140141
141 -//ParserFunctions.prototype['pf_FORMATNUM'] = function ( target, argList, argDict ) {
142 -//};
143 -
144142 if (typeof module == "object") {
145143 module.exports.ParserFunctions = ParserFunctions;
146144 }
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -144,6 +144,7 @@
145145 TemplateHandler.prototype._expandTemplate = function ( tplExpandData ) {
146146 //console.log('TemplateHandler.expandTemplate: ' +
147147 // JSON.stringify( tplExpandData, null, 2 ) );
 148+ var res;
148149
149150
150151 if ( ! tplExpandData.target ) {
@@ -170,7 +171,7 @@
171172 if ( prefix && 'pf_' + prefix in this.parserFunctions ) {
172173 var funcArg = target.substr( prefix.length + 1 );
173174 this.manager.env.dp( 'entering prefix', funcArg, args );
174 - var res = this.parserFunctions[ 'pf_' + prefix ]( funcArg,
 175+ res = this.parserFunctions[ 'pf_' + prefix ]( funcArg,
175176 tplExpandData.expandDone, args );
176177
177178 // XXX: support async parser functions!
@@ -188,9 +189,8 @@
189190
190191 var checkRes = this.manager.loopAndDepthCheck.check( target );
191192 if( checkRes ) {
192 - // Loop detected, abort!
193 - return {
194 - tokens: [
 193+ // Loop detected or depth limit exceeded, abort!
 194+ res = [
195195 {
196196 type: 'TEXT',
197197 value: checkRes
@@ -208,8 +208,12 @@
209209 type: 'ENDTAG',
210210 name: 'a'
211211 }
212 - ]
213 - };
 212+ ];
 213+ if ( tplExpandData.overallAsync ) {
 214+ return tplExpandData.cb( res, false );
 215+ } else {
 216+ return { tokens: res };
 217+ }
214218 }
215219
216220 // Get a nested transformation pipeline for the input type. The input

Status & tagging log