Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -207,7 +207,8 @@ |
208 | 208 | for ( i = 0, l = ts.length; i < l; i++ ) { |
209 | 209 | transformer = ts[i]; |
210 | 210 | if ( res.token.rank && transformer.rank < res.token.rank ) { |
211 | | - //console.log( 'SKIPPING' + JSON.stringify( token, null, 2 ) + JSON.stringify( transformer, null, 2 ) ); |
| 211 | + //console.log( 'SKIPPING' + JSON.stringify( token, null, 2 ) + |
| 212 | + // '\ntransform:\n' + JSON.stringify( transformer, null, 2 ) ); |
212 | 213 | // skip transformation, was already applied. |
213 | 214 | continue; |
214 | 215 | } |
— | — | @@ -404,15 +405,15 @@ |
405 | 406 | * @param {Array} chunk of tokens |
406 | 407 | */ |
407 | 408 | AsyncTokenTransformManager.prototype.onChunk = function ( tokens ) { |
408 | | - //console.log('TokenTransformManager onChunk'); |
409 | 409 | // Set top-level callback to next transform phase |
410 | 410 | var res = this.transformTokens ( tokens, this.tokenCB ); |
411 | 411 | this.tailAccumulator = res.async; |
412 | | - this.emit( 'chunk', tokens ); |
| 412 | + //console.log('AsyncTokenTransformManager onChunk ', tokens); |
413 | 413 | //this.phase2TailCB( tokens, true ); |
414 | 414 | if ( res.async ) { |
415 | 415 | this.tokenCB = res.async.getParentCB ( 'sibling' ); |
416 | 416 | } |
| 417 | + this.emit( 'chunk', res.tokens ); |
417 | 418 | }; |
418 | 419 | |
419 | 420 | /** |
— | — | @@ -422,10 +423,10 @@ |
423 | 424 | */ |
424 | 425 | AsyncTokenTransformManager.prototype.transformTokens = function ( tokens, parentCB ) { |
425 | 426 | |
426 | | - //console.log('_transformPhase01: ' + JSON.stringify(tokens) ); |
| 427 | + //console.log('AsyncTokenTransformManager.transformTokens: ' + JSON.stringify(tokens) ); |
427 | 428 | |
428 | 429 | var res, |
429 | | - phaseEndRank = 2, // parametrize! |
| 430 | + phaseEndRank = 2, // XXX: parametrize! |
430 | 431 | // Prepare a new accumulator, to be used by async children (if any) |
431 | 432 | localAccum = [], |
432 | 433 | accum = new TokenAccumulator( parentCB ), |
— | — | @@ -478,7 +479,7 @@ |
479 | 480 | // If there is no accumulator yet, then directly return the |
480 | 481 | // token to the parent. Collect them in localAccum for this |
481 | 482 | // purpose. |
482 | | - localAccum.push(res.token); |
| 483 | + localAccum.push( res.token ); |
483 | 484 | } |
484 | 485 | } else { |
485 | 486 | // re-process token. |
— | — | @@ -486,6 +487,7 @@ |
487 | 488 | i--; |
488 | 489 | } |
489 | 490 | } else if ( res.async ) { |
| 491 | + //console.log( 'tokens returned' ); |
490 | 492 | // The child now switched to activeAccum, we have to create a new |
491 | 493 | // accumulator for the next potential child. |
492 | 494 | activeAccum = accum; |
— | — | @@ -511,15 +513,15 @@ |
512 | 514 | * (everything is done), or a truish value if not yet done. |
513 | 515 | */ |
514 | 516 | AsyncTokenTransformManager.prototype._returnTokens = function ( tokens, notYetDone ) { |
515 | | - // FIXME: store frame in object? |
516 | | - this.emit('chunk', tokens); |
517 | 517 | //tokens = this._transformPhase2( this.frame, tokens, this.parentCB ); |
518 | 518 | //console.log('AsyncTokenTransformManager._returnTokens, after _transformPhase2.'); |
519 | 519 | |
520 | | - //this.emit( 'chunk', tokens ); |
| 520 | + this.emit( 'chunk', tokens ); |
521 | 521 | |
522 | 522 | if ( ! notYetDone ) { |
523 | | - console.log('AsyncTokenTransformManager._returnTokens done.'); |
| 523 | + //console.log('AsyncTokenTransformManager._returnTokens done. tokens:' + |
| 524 | + // JSON.stringify( tokens, null, 2 ) + ', listeners: ' + |
| 525 | + // JSON.stringify( this.listeners( 'chunk' ), null, 2 ) ); |
524 | 526 | // signal our done-ness to consumers. |
525 | 527 | this.emit( 'end' ); |
526 | 528 | // and reset internal state. |
— | — | @@ -557,9 +559,10 @@ |
558 | 560 | * @constructor |
559 | 561 | * @param {Object} environment. |
560 | 562 | */ |
561 | | -function SyncTokenTransformManager ( env ) { |
| 563 | +function SyncTokenTransformManager ( env, phaseEndRank ) { |
562 | 564 | // both inherited |
563 | 565 | this._construct(); |
| 566 | + this.phaseEndRank = phaseEndRank; |
564 | 567 | this.args = {}; // no arguments at the top level |
565 | 568 | this.env = env; |
566 | 569 | } |
— | — | @@ -586,8 +589,9 @@ |
587 | 590 | * @param {Array} Token chunk. |
588 | 591 | */ |
589 | 592 | SyncTokenTransformManager.prototype.onChunk = function ( tokens ) { |
| 593 | + //console.log('SyncTokenTransformManager.onChunk: ' + |
| 594 | + // JSON.stringify( tokens, null, 2 ) ); |
590 | 595 | var res, |
591 | | - phaseEndRank = 3, |
592 | 596 | localAccum = [], |
593 | 597 | localAccumLength = 0, |
594 | 598 | tokensLength = tokens.length, |
— | — | @@ -603,23 +607,23 @@ |
604 | 608 | case 'TAG': |
605 | 609 | case 'ENDTAG': |
606 | 610 | case 'SELFCLOSINGTAG': |
607 | | - res = this._transformTagToken( token, cb, phaseEndRank ); |
| 611 | + res = this._transformTagToken( token, cb, this.phaseEndRank ); |
608 | 612 | break; |
609 | 613 | case 'TEXT': |
610 | | - res = this._transformToken( token, cb, phaseEndRank, |
| 614 | + res = this._transformToken( token, cb, this.phaseEndRank, |
611 | 615 | ts.text ); |
612 | 616 | break; |
613 | 617 | case 'COMMENT': |
614 | | - res = this._transformToken( token, cb, phaseEndRank, ts.comment ); |
| 618 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.comment ); |
615 | 619 | break; |
616 | 620 | case 'NEWLINE': |
617 | | - res = this._transformToken( token, cb, phaseEndRank, ts.newline ); |
| 621 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.newline ); |
618 | 622 | break; |
619 | 623 | case 'END': |
620 | | - res = this._transformToken( token, cb, phaseEndRank, ts.end ); |
| 624 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.end ); |
621 | 625 | break; |
622 | 626 | default: |
623 | | - res = this._transformToken( token, cb, phaseEndRank, ts.martian ); |
| 627 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.martian ); |
624 | 628 | break; |
625 | 629 | } |
626 | 630 | |
— | — | @@ -630,7 +634,7 @@ |
631 | 635 | tokensLength = tokens.length; |
632 | 636 | i--; // continue at first inserted token |
633 | 637 | } else if ( res.token ) { |
634 | | - if ( res.token.rank === phaseEndRank ) { |
| 638 | + if ( res.token.rank === this.phaseEndRank ) { |
635 | 639 | // token is done. |
636 | 640 | localAccum.push(res.token); |
637 | 641 | this.prevToken = res.token; |
— | — | @@ -684,6 +688,7 @@ |
685 | 689 | //this.pipe.process( |
686 | 690 | var pipe, |
687 | 691 | ref; |
| 692 | + //console.log( 'AttributeTransformManager.process: ' + JSON.stringify( attributes ) ); |
688 | 693 | |
689 | 694 | // transform each argument (key and value), and handle asynchronous returns |
690 | 695 | for ( var i = 0, l = attributes.length; i < l; i++ ) { |
— | — | @@ -711,6 +716,7 @@ |
712 | 717 | pipe.addListener( 'end', |
713 | 718 | this.onEnd.bind( this, this._returnAttributeValue.bind( this, i ) ) |
714 | 719 | ); |
| 720 | + //console.log('starting attribute transform of ' + JSON.stringify( attributes[i][1] ) ); |
715 | 721 | pipe.process( attributes[i][1] ); |
716 | 722 | } |
717 | 723 | }; |
— | — | @@ -724,21 +730,22 @@ |
725 | 731 | } |
726 | 732 | |
727 | 733 | // and call the callback with the result |
| 734 | + //console.log('AttributeTransformManager._returnAttributes: ' + out ); |
728 | 735 | this.callback( out ); |
729 | 736 | }; |
730 | 737 | |
731 | 738 | /** |
732 | 739 | * Collect chunks returned from the pipeline |
733 | 740 | */ |
734 | | -AttributeTransformManager.prototype.onChunk = function ( callback, ref, chunk ) { |
735 | | - callback.call( ref, chunk, true ); |
| 741 | +AttributeTransformManager.prototype.onChunk = function ( cb, chunk ) { |
| 742 | + cb( chunk, true ); |
736 | 743 | }; |
737 | 744 | |
738 | 745 | /** |
739 | 746 | * Empty the pipeline by returning to the parent |
740 | 747 | */ |
741 | | -AttributeTransformManager.prototype.onEnd = function ( callback, ref ) { |
742 | | - callback.call( ref, [], false ); |
| 748 | +AttributeTransformManager.prototype.onEnd = function ( cb ) { |
| 749 | + cb( [], false ); |
743 | 750 | }; |
744 | 751 | |
745 | 752 | |
— | — | @@ -746,7 +753,8 @@ |
747 | 754 | * Callback for async argument value expansions |
748 | 755 | */ |
749 | 756 | AttributeTransformManager.prototype._returnAttributeValue = function ( ref, tokens, notYetDone ) { |
750 | | - this.kvs[ref].value.push( tokens ); |
| 757 | + //console.log( 'check _returnAttributeValue: ' + JSON.stringify( tokens ) ); |
| 758 | + this.kvs[ref].value = this.kvs[ref].value.concat( tokens ); |
751 | 759 | if ( ! notYetDone ) { |
752 | 760 | this.outstanding--; |
753 | 761 | if ( this.outstanding === 0 ) { |
— | — | @@ -760,7 +768,7 @@ |
761 | 769 | * Callback for async argument key expansions |
762 | 770 | */ |
763 | 771 | AttributeTransformManager.prototype._returnAttributeKey = function ( ref, tokens, notYetDone ) { |
764 | | - this.kvs[ref].key.push( tokens ); |
| 772 | + this.kvs[ref].key = this.kvs[ref].key.concat( tokens ); |
765 | 773 | if ( ! notYetDone ) { |
766 | 774 | this.outstanding--; |
767 | 775 | if ( this.outstanding === 0 ) { |
— | — | @@ -818,32 +826,38 @@ |
819 | 827 | this.outstanding--; |
820 | 828 | } |
821 | 829 | |
| 830 | + //console.log( 'TokenAccumulator._returnTokens' ); |
822 | 831 | if ( reference === 'child' ) { |
| 832 | + tokens = tokens.concat( this.accum ); |
| 833 | + //console.log('TokenAccumulator._returnTokens: ' + |
| 834 | + // JSON.stringify( tokens, null, 2 ) |
| 835 | + // ); |
| 836 | + this.accum = []; |
823 | 837 | // XXX: Use some marker to avoid re-transforming token chunks several |
824 | 838 | // times? |
825 | | - res = this.transformTokens( tokens, this.parentCB ); |
| 839 | + //res = this.transformTokens( tokens, this.parentCB ); |
826 | 840 | |
827 | | - if ( res.async ) { |
828 | | - // new asynchronous expansion started, chain of accumulators |
829 | | - // created |
830 | | - if ( this.outstanding === 0 ) { |
831 | | - // Last accum in chain should only wait for child |
832 | | - res.async.outstanding--; |
833 | | - cb = this.parentCB; |
834 | | - } else { |
835 | | - cb = this.parentCB; |
836 | | - // set own callback to new sibling, the end of accumulator chain |
837 | | - this.parentCB = res.async.getParentCB( 'sibling' ); |
838 | | - } |
839 | | - } |
840 | | - if ( ! notYetDone ) { |
841 | | - // Child is done, return accumulator from sibling. Siblings |
842 | | - // process tokens themselves, so we concat those to the result of |
843 | | - // processing tokens from the child. |
844 | | - tokens = res.tokens.concat( this.accum ); |
845 | | - this.accum = []; |
846 | | - } |
847 | | - this.cb( res.tokens, res.async ); |
| 841 | + //if ( res.async ) { |
| 842 | + // // new asynchronous expansion started, chain of accumulators |
| 843 | + // // created |
| 844 | + // if ( this.outstanding === 0 ) { |
| 845 | + // // Last accum in chain should only wait for child |
| 846 | + // res.async.outstanding--; |
| 847 | + // cb = this.parentCB; |
| 848 | + // } else { |
| 849 | + // cb = this.parentCB; |
| 850 | + // // set own callback to new sibling, the end of accumulator chain |
| 851 | + // this.parentCB = res.async.getParentCB( 'sibling' ); |
| 852 | + // } |
| 853 | + //} |
| 854 | + //if ( ! notYetDone ) { |
| 855 | + // // Child is done, return accumulator from sibling. Siblings |
| 856 | + // // process tokens themselves, so we concat those to the result of |
| 857 | + // // processing tokens from the child. |
| 858 | + // tokens = res.tokens.concat( this.accum ); |
| 859 | + // this.accum = []; |
| 860 | + //} |
| 861 | + this.parentCB( tokens, false ); |
848 | 862 | return null; |
849 | 863 | } else { |
850 | 864 | // sibling |
— | — | @@ -869,7 +883,8 @@ |
870 | 884 | * Mark the sibling as done (normally at the tail of a chain). |
871 | 885 | */ |
872 | 886 | TokenAccumulator.prototype.siblingDone = function () { |
873 | | - this._returnTokens01 ( 'sibling', [], false ); |
| 887 | + //console.log( 'TokenAccumulator.siblingDone: ' ); |
| 888 | + this._returnTokens ( 'sibling', [], false ); |
874 | 889 | }; |
875 | 890 | |
876 | 891 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -151,7 +151,7 @@ |
152 | 152 | ); |
153 | 153 | |
154 | 154 | // Register template expansion extension |
155 | | - //new TemplateHandler( tokenExpander ); |
| 155 | + new TemplateHandler( tokenExpander ); |
156 | 156 | |
157 | 157 | tokenExpander.listenForTokensFrom ( tokenPreProcessor ); |
158 | 158 | // XXX: hack. |
— | — | @@ -194,7 +194,7 @@ |
195 | 195 | }, |
196 | 196 | args, this.env |
197 | 197 | ); |
198 | | - //new TemplateHandler( tokenExpander ); |
| 198 | + new TemplateHandler( tokenExpander ); |
199 | 199 | tokenExpander.listenForTokensFrom ( tokenPreProcessor ); |
200 | 200 | |
201 | 201 | return new CachedTokenPipeline( |
— | — | @@ -250,12 +250,16 @@ |
251 | 251 | /************************ CachedTokenPipeline ********************************/ |
252 | 252 | |
253 | 253 | /** |
254 | | - * Manage a part of a pipeline, that emits 'end' and 'chunk' events from its |
255 | | - * last stage. |
| 254 | + * Wrap a part of a pipeline. The last member of the pipeline is supposed to |
| 255 | + * emit 'end' and 'chunk' events, while the first is supposed to support a |
| 256 | + * process() method that sets the pipeline in motion. |
256 | 257 | * |
257 | 258 | * @class |
258 | 259 | * @constructor |
259 | | - * @param { |
| 260 | + * @param {Function} returnToCacheCB: Callback to return the |
| 261 | + * CachedTokenPipeline to a cache when processing has finished |
| 262 | + * @param {Object} first: First stage of the pipeline |
| 263 | + * @param {Object} last: Last stage of the pipeline |
260 | 264 | */ |
261 | 265 | function CachedTokenPipeline ( returnToCacheCB, first, last ) { |
262 | 266 | this.returnToCacheCB = returnToCacheCB; |
— | — | @@ -283,6 +287,10 @@ |
284 | 288 | * Forward chunks to our listeners |
285 | 289 | */ |
286 | 290 | CachedTokenPipeline.prototype.forwardChunk = function ( chunk ) { |
| 291 | + //console.log( 'CachedTokenPipeline.forwardChunk: ' + |
| 292 | + // JSON.stringify( chunk, null, 2 ) |
| 293 | + // ); |
| 294 | + |
287 | 295 | this.emit( 'chunk', chunk ); |
288 | 296 | }; |
289 | 297 | |
— | — | @@ -292,6 +300,8 @@ |
293 | 301 | * the given pipeline stage and returns it to a cache. |
294 | 302 | */ |
295 | 303 | CachedTokenPipeline.prototype.forwardEndAndRecycleSelf = function ( ) { |
| 304 | + //console.log( 'CachedTokenPipeline.forwardEndAndRecycleSelf: ' + |
| 305 | + // JSON.stringify( this.listeners( 'chunk' ), null, 2 ) ); |
296 | 306 | // first, forward the event |
297 | 307 | this.emit( 'end' ); |
298 | 308 | // now recycle self |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | } |
21 | 21 | |
22 | 22 | TemplateHandler.prototype.reset = function () { |
23 | | - this.outstanding = 0; |
| 23 | + this.resultTokens = []; |
24 | 24 | }; |
25 | 25 | |
26 | 26 | // constants |
— | — | @@ -47,7 +47,9 @@ |
48 | 48 | * processes the template. |
49 | 49 | */ |
50 | 50 | TemplateHandler.prototype.onTemplate = function ( token, cb ) { |
51 | | - console.log('onTemplate!'); |
| 51 | + //console.log('onTemplate!'); |
| 52 | + |
| 53 | + this.parentCB = cb; |
52 | 54 | |
53 | 55 | // check for 'subst:' |
54 | 56 | // check for variable magic names |
— | — | @@ -58,7 +60,7 @@ |
59 | 61 | var templateTokenTransformData = { |
60 | 62 | args: {}, |
61 | 63 | manager: this.manager, |
62 | | - outstanding: 0, |
| 64 | + outstanding: 1, // Avoid premature finish |
63 | 65 | cb: cb, |
64 | 66 | origToken: token, |
65 | 67 | isAsync: false |
— | — | @@ -69,14 +71,18 @@ |
70 | 72 | res, |
71 | 73 | kv; |
72 | 74 | |
73 | | - var attributes = [['', token.target]].concat( token.orderedArgs ); |
| 75 | + var attributes = [[{ type: 'TEXT', value: '' } , token.target ]].concat( token.orderedArgs ); |
74 | 76 | |
75 | | - new AttributeTransformManager( this.manager, |
76 | | - this._returnAttributes.bind( this, templateTokenTransformData ) |
| 77 | + //console.log( 'before AttributeTransformManager: ' + JSON.stringify( attributes, null, 2 ) ); |
| 78 | + new AttributeTransformManager( |
| 79 | + this.manager, |
| 80 | + this._returnAttributes.bind( this, templateTokenTransformData ) |
77 | 81 | ).process( attributes ); |
78 | 82 | |
| 83 | + // Unblock finish |
| 84 | + templateTokenTransformData.outstanding--; |
79 | 85 | if ( templateTokenTransformData.outstanding === 0 ) { |
80 | | - console.log( 'direct call'); |
| 86 | + //console.log( 'direct call'); |
81 | 87 | return this._expandTemplate ( templateTokenTransformData ); |
82 | 88 | } else { |
83 | 89 | templateTokenTransformData.isAsync = true; |
— | — | @@ -85,7 +91,7 @@ |
86 | 92 | }; |
87 | 93 | |
88 | 94 | TemplateHandler.prototype._returnAttributes = function ( templateTokenTransformData, attributes ) { |
89 | | - console.log( '_returnAttributes' + JSON.stringify(attributes) ); |
| 95 | + //console.log( 'TemplateHandler._returnAttributes: ' + JSON.stringify(attributes) ); |
90 | 96 | // Remove the target from the attributes |
91 | 97 | templateTokenTransformData.target = attributes[0][1]; |
92 | 98 | attributes.shift(); |
— | — | @@ -100,8 +106,8 @@ |
101 | 107 | * target were expanded in frame. |
102 | 108 | */ |
103 | 109 | TemplateHandler.prototype._expandTemplate = function ( templateTokenTransformData ) { |
104 | | - console.log('TemplateHandler.expandTemplate: ' + |
105 | | - JSON.stringify( templateTokenTransformData, null, 2 ) ); |
| 110 | + //console.log('TemplateHandler.expandTemplate: ' + |
| 111 | + // JSON.stringify( templateTokenTransformData, null, 2 ) ); |
106 | 112 | // First, check the target for loops |
107 | 113 | this.manager.loopCheck.check( templateTokenTransformData.target ); |
108 | 114 | |
— | — | @@ -115,14 +121,16 @@ |
116 | 122 | templateTokenTransformData.expandedArgs |
117 | 123 | ); |
118 | 124 | |
119 | | - // Hook up the AsyncTokenTransformManager output events to call back our |
120 | | - // parentCB. |
| 125 | + // Hook up the inputPipeline output events to call back our parentCB. |
121 | 126 | this.inputPipeline.addListener( 'chunk', this._onChunk.bind ( this ) ); |
122 | 127 | this.inputPipeline.addListener( 'end', this._onEnd.bind ( this ) ); |
123 | 128 | |
124 | 129 | |
125 | 130 | // Resolve a possibly relative link |
126 | | - var templateName = this.manager.env.resolveTitle( this.manager.env.tokensToString( this.target ), 'Template' ); |
| 131 | + var templateName = this.manager.env.resolveTitle( |
| 132 | + this.manager.env.tokensToString( templateTokenTransformData.target ), |
| 133 | + 'Template' |
| 134 | + ); |
127 | 135 | this._fetchTemplateAndTitle( templateName, this._processTemplateAndTitle.bind( this ) ); |
128 | 136 | |
129 | 137 | // Set up a pipeline: |
— | — | @@ -144,6 +152,13 @@ |
145 | 153 | // recursion depth check |
146 | 154 | // fetch from DB or interwiki |
147 | 155 | // infinte loop check |
| 156 | + |
| 157 | + // Always asynchronous.. |
| 158 | + if ( this.isAsync ) { |
| 159 | + return {}; |
| 160 | + } else { |
| 161 | + return this.result; |
| 162 | + } |
148 | 163 | }; |
149 | 164 | |
150 | 165 | |
— | — | @@ -161,14 +176,27 @@ |
162 | 177 | TemplateHandler.prototype._onEnd = function( ) { |
163 | 178 | // Encapsulate the template in a single token, which contains all the |
164 | 179 | // information needed for the editor. |
165 | | - var res = { |
166 | | - type: 'container', |
167 | | - tokens: this.resultTokens, // The editor needs HTML serialization instead |
168 | | - args: this.manager.args, // Here, the editor needs wikitext. |
169 | | - attribs: this.origToken.attribs // Hmm.. |
| 180 | + var res = |
| 181 | + [{ |
| 182 | + type: 'TAG', |
| 183 | + name: 'div', |
| 184 | + attribs: [['data-source', 'template']], |
| 185 | + args: this.manager.args // Here, the editor needs wikitext. |
| 186 | + }].concat( |
| 187 | + // XXX: Mark source in attribute on result tokens, so that |
| 188 | + // the visual editor can detect structures from templates! |
| 189 | + this.resultTokens, |
| 190 | + [{ type: 'ENDTAG', name: 'div' }] |
| 191 | + ); |
| 192 | + //console.log( 'TemplateHandler._onEnd: ' + JSON.stringify( res, null, 2 ) ); |
170 | 193 | |
171 | | - }; |
172 | | - this.parentCB( res, false ); |
| 194 | + if ( this.isAsync ) { |
| 195 | + this.parentCB( res, false ); |
| 196 | + this.reset(); |
| 197 | + } else { |
| 198 | + this.result = { tokens: res }; |
| 199 | + this.reset(); |
| 200 | + } |
173 | 201 | }; |
174 | 202 | |
175 | 203 | |
— | — | @@ -178,6 +206,7 @@ |
179 | 207 | */ |
180 | 208 | TemplateHandler.prototype._processTemplateAndTitle = function( src, title ) { |
181 | 209 | // Feed the pipeline. XXX: Support different formats. |
| 210 | + //console.log( 'TemplateHandler._processTemplateAndTitle: ' + src ); |
182 | 211 | this.inputPipeline.process ( src ); |
183 | 212 | }; |
184 | 213 | |
— | — | @@ -188,13 +217,13 @@ |
189 | 218 | */ |
190 | 219 | TemplateHandler.prototype._fetchTemplateAndTitle = function( title, callback ) { |
191 | 220 | // @fixme normalize name? |
192 | | - if (title in this.pageCache) { |
| 221 | + if (title in this.manager.env.pageCache) { |
193 | 222 | // @fixme should this be forced to run on next event? |
194 | | - callback( this.pageCache[title], title ); |
| 223 | + callback( this.env.manager.pageCache[title], title ); |
195 | 224 | } else { |
196 | 225 | // whee fun hack! |
197 | | - console.log(title); |
198 | | - console.log(this.pageCache); |
| 226 | + //console.log(title); |
| 227 | + //console.log(this.manager.env.pageCache); |
199 | 228 | $.ajax({ |
200 | 229 | url: this.manager.env.wgScriptPath + '/api' + this.manager.env.wgScriptExtension, |
201 | 230 | data: { |
— | — | @@ -202,7 +231,7 @@ |
203 | 232 | action: 'query', |
204 | 233 | prop: 'revisions', |
205 | 234 | rvprop: 'content', |
206 | | - titles: name |
| 235 | + titles: title |
207 | 236 | }, |
208 | 237 | success: function(data, xhr) { |
209 | 238 | var src = null, title = null; |
— | — | @@ -213,13 +242,15 @@ |
214 | 243 | } |
215 | 244 | }); |
216 | 245 | if (typeof src !== 'string') { |
217 | | - callback(null, null, 'Page not found'); |
| 246 | + //console.log( 'Page ' + title + 'not found!' ); |
| 247 | + callback( 'Page ' + title + ' not found' ); |
218 | 248 | } else { |
219 | 249 | callback(src, title); |
220 | 250 | } |
221 | 251 | }, |
222 | 252 | error: function(msg) { |
223 | | - callback(null, null, 'Page/template fetch failure'); |
| 253 | + //console.log( 'Page/template fetch failure for title ' + title ); |
| 254 | + callback('Page/template fetch failure for title ' + title); |
224 | 255 | }, |
225 | 256 | dataType: 'json', |
226 | 257 | cache: false // @fixme caching, versions etc? |