Index: trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js |
— | — | @@ -0,0 +1,39 @@ |
| 2 | +/** |
| 3 | + * Simple noinclude / onlyinclude implementation. Strips all tokens in |
| 4 | + * noinclude sections. |
| 5 | + * |
| 6 | + * @author Gabriel Wicke <gwicke@wikimedia.org> |
| 7 | + */ |
| 8 | + |
| 9 | +var TokenCollector = require( './ext.util.TokenCollector.js' ).TokenCollector; |
| 10 | + |
| 11 | +function NoInclude( manager ) { |
| 12 | + new TokenCollector( |
| 13 | + manager, |
| 14 | + function ( tokens ) { |
| 15 | + //manager.env.dp( 'noinclude stripping', tokens ); |
| 16 | + return {}; |
| 17 | + }, // just strip it all.. |
| 18 | + true, // match the end-of-input if </noinclude> is missing |
| 19 | + 0.01, // very early in stage 1, to avoid any further processing. |
| 20 | + 'tag', |
| 21 | + 'noinclude' |
| 22 | + ); |
| 23 | +} |
| 24 | + |
| 25 | +function OnlyInclude( manager ) { |
| 26 | + new TokenCollector( |
| 27 | + manager, |
| 28 | + function ( ) { return {} }, // just strip it all.. |
| 29 | + true, // match the end-of-input if </noinclude> is missing |
| 30 | + 0.01, // very early in stage 1, to avoid any further processing. |
| 31 | + 'tag', |
| 32 | + 'onlyinclude' |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +if (typeof module == "object") { |
| 38 | + module.exports.NoInclude = NoInclude; |
| 39 | + module.exports.OnlyInclude = OnlyInclude; |
| 40 | +} |
Property changes on: trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 41 | + native |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -956,17 +956,17 @@ |
957 | 957 | */ |
958 | 958 | LoopAndDepthCheck.prototype.check = function ( title ) { |
959 | 959 | // XXX: set limit really low for testing! |
960 | | - if ( this.depth > 6 ) { |
| 960 | + if ( this.depth > 40 ) { |
961 | 961 | // too deep |
962 | 962 | //console.log( 'Loopcheck: ' + JSON.stringify( this, null, 2 ) ); |
963 | | - return 'Template expansion depth limit exceeded at '; |
| 963 | + return 'Expansion depth limit exceeded at '; |
964 | 964 | } |
965 | 965 | var elem = this; |
966 | 966 | do { |
967 | 967 | //console.log( 'loop check: ' + title + ' vs ' + elem.title ); |
968 | 968 | if ( elem.title === title ) { |
969 | 969 | // Loop detected |
970 | | - return 'Template expansion loop detected at '; |
| 970 | + return 'Expansion loop detected at '; |
971 | 971 | } |
972 | 972 | elem = elem.parent; |
973 | 973 | } while ( elem ); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -15,6 +15,9 @@ |
16 | 16 | path = require('path'), |
17 | 17 | PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer, |
18 | 18 | TokenTransformManager = require('./mediawiki.TokenTransformManager.js'), |
| 19 | + |
| 20 | + NoInclude = require('./ext.core.NoOnlyInclude.js').NoInclude, |
| 21 | + OnlyInclude = require('./ext.core.NoOnlyInclude.js').OnlyInclude, |
19 | 22 | QuoteTransformer = require('./ext.core.QuoteTransformer.js').QuoteTransformer, |
20 | 23 | PostExpandParagraphHandler = require('./ext.core.PostExpandParagraphHandler.js') |
21 | 24 | .PostExpandParagraphHandler, |
— | — | @@ -154,6 +157,9 @@ |
155 | 158 | var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env ); |
156 | 159 | tokenPreProcessor.listenForTokensFrom ( wikiTokenizer ); |
157 | 160 | |
| 161 | + // Add noinclude transform for now |
| 162 | + new NoInclude( tokenPreProcessor ); |
| 163 | + |
158 | 164 | var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager ( |
159 | 165 | { |
160 | 166 | 'input': this.makeInputPipeline.bind( this ), |
— | — | @@ -202,6 +208,8 @@ |
203 | 209 | * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
204 | 210 | */ |
205 | 211 | var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env ); |
| 212 | + new NoInclude( tokenPreProcessor ); |
| 213 | + |
206 | 214 | var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager ( |
207 | 215 | { |
208 | 216 | 'input': this.makeInputPipeline.bind( this ), |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js |
— | — | @@ -137,7 +137,11 @@ |
138 | 138 | */ |
139 | 139 | MWParserEnvironment.prototype.dp = function ( ) { |
140 | 140 | if ( this.debug ) { |
141 | | - console.log( JSON.stringify( arguments, null, 2 ) ); |
| 141 | + if ( arguments.length > 1 ) { |
| 142 | + console.log( JSON.stringify( arguments, null, 2 ) ); |
| 143 | + } else { |
| 144 | + console.log( arguments[0] ); |
| 145 | + } |
142 | 146 | } |
143 | 147 | }; |
144 | 148 | |
Index: trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js |
— | — | @@ -5,6 +5,8 @@ |
6 | 6 | * stages (SyncTokenTransformManager), as async out-of-order expansions |
7 | 7 | * would wreak havoc with this kind of collector. |
8 | 8 | * |
| 9 | + * @author Gabriel Wicke <gwicke@wikimedia.org> |
| 10 | + * |
9 | 11 | * Calls the passed-in callback with the collected tokens. |
10 | 12 | * |
11 | 13 | * @class |
— | — | @@ -14,7 +16,7 @@ |
15 | 17 | * transform( tokens, cb, manager ) with |
16 | 18 | * tokens: chunk of tokens |
17 | 19 | * cb: function, returnTokens ( tokens, notYetDone ) with notYetDone |
18 | | - * indicating the last chunk of an async return. |
| 20 | + * indicating the last chunk of an async return. |
19 | 21 | * manager: TokenTransformManager, provides the args etc. |
20 | 22 | * @param {Boolean} Match the 'end' tokens as closing tag as well (accept |
21 | 23 | * unclosed sections). |
— | — | @@ -23,8 +25,8 @@ |
24 | 26 | * @param {String} (optional, only for token type 'tag'): tag name. |
25 | 27 | */ |
26 | 28 | |
27 | | -function TokenCollector ( manager, transformer, toEnd, rank, type, name ) { |
28 | | - this.transformer = transformer; |
| 29 | +function TokenCollector ( manager, transformation, toEnd, rank, type, name ) { |
| 30 | + this.transformation = transformation; |
29 | 31 | this.manager = manager; |
30 | 32 | this.rank = rank; |
31 | 33 | this.type = type; |
— | — | @@ -48,8 +50,9 @@ |
49 | 51 | * Handle the delimiter token. |
50 | 52 | * XXX: Adjust to sync phase callback when that is modified! |
51 | 53 | */ |
52 | | -TokenCollector.prototype._onDelimiterToken ( token, cb, frame ) { |
53 | | - this.manager.addTransform( this._anyToken.bind ( this ), rank + this._anyDelta, 'any' ); |
| 54 | +TokenCollector.prototype._onDelimiterToken = function ( token, cb, frame ) { |
| 55 | + this.manager.addTransform( this._onAnyToken.bind ( this ), |
| 56 | + this.rank + this._anyDelta, 'any' ); |
54 | 57 | this.tokens.push ( token ); |
55 | 58 | if ( ! this.isActive ) { |
56 | 59 | this.isActive = true; |
— | — | @@ -57,12 +60,13 @@ |
58 | 61 | return { async: true }; |
59 | 62 | } else if ( token.type !== 'end' || this.toEnd ) { |
60 | 63 | // end token |
| 64 | + var res = this.transformation ( this.tokens, this.cb, this.manager ); |
61 | 65 | this.tokens = []; |
62 | 66 | this.manager.removeTransform( this.rank + this._anyDelta, 'any' ); |
63 | 67 | this.isActive = false; |
64 | | - // Transformer can be either sync or async, but receives all collected |
| 68 | + // Transformation can be either sync or async, but receives all collected |
65 | 69 | // tokens instead of a single token. |
66 | | - return this.transformer ( this.tokens, this.cb, this.manager ); |
| 70 | + return res; |
67 | 71 | // XXX sync version: return tokens |
68 | 72 | } else if ( token.type === 'end' && ! this.toEnd ) { |
69 | 73 | // Did not encounter a matching end token before the end, and are not |
— | — | @@ -78,10 +82,13 @@ |
79 | 83 | * encountering the delimiter token, and collects all tokens until the end |
80 | 84 | * token is reached. |
81 | 85 | */ |
82 | | -TokenCollector.prototype._onAnyToken ( token, cb, frame ) { |
| 86 | +TokenCollector.prototype._onAnyToken = function ( token, cb, frame ) { |
83 | 87 | // Simply collect anything ordinary in between |
84 | 88 | this.tokens.push( token ); |
85 | 89 | return { }; |
86 | | -} |
| 90 | +}; |
87 | 91 | |
88 | 92 | |
| 93 | +if (typeof module == "object") { |
| 94 | + module.exports.TokenCollector = TokenCollector; |
| 95 | +} |