r109601 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109600‎ | r109601 | r109602 >
Date:01:46, 20 January 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Add some rudimentary noinclude / includeonly support and fix up
TokenCollector.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.NoOnlyInclude.js (added) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js (modified) (history)

Diff [purge]

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
141 + native
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -956,17 +956,17 @@
957957 */
958958 LoopAndDepthCheck.prototype.check = function ( title ) {
959959 // XXX: set limit really low for testing!
960 - if ( this.depth > 6 ) {
 960+ if ( this.depth > 40 ) {
961961 // too deep
962962 //console.log( 'Loopcheck: ' + JSON.stringify( this, null, 2 ) );
963 - return 'Template expansion depth limit exceeded at ';
 963+ return 'Expansion depth limit exceeded at ';
964964 }
965965 var elem = this;
966966 do {
967967 //console.log( 'loop check: ' + title + ' vs ' + elem.title );
968968 if ( elem.title === title ) {
969969 // Loop detected
970 - return 'Template expansion loop detected at ';
 970+ return 'Expansion loop detected at ';
971971 }
972972 elem = elem.parent;
973973 } while ( elem );
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js
@@ -15,6 +15,9 @@
1616 path = require('path'),
1717 PegTokenizer = require('./mediawiki.tokenizer.peg.js').PegTokenizer,
1818 TokenTransformManager = require('./mediawiki.TokenTransformManager.js'),
 19+
 20+ NoInclude = require('./ext.core.NoOnlyInclude.js').NoInclude,
 21+ OnlyInclude = require('./ext.core.NoOnlyInclude.js').OnlyInclude,
1922 QuoteTransformer = require('./ext.core.QuoteTransformer.js').QuoteTransformer,
2023 PostExpandParagraphHandler = require('./ext.core.PostExpandParagraphHandler.js')
2124 .PostExpandParagraphHandler,
@@ -154,6 +157,9 @@
155158 var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env );
156159 tokenPreProcessor.listenForTokensFrom ( wikiTokenizer );
157160
 161+ // Add noinclude transform for now
 162+ new NoInclude( tokenPreProcessor );
 163+
158164 var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager (
159165 {
160166 'input': this.makeInputPipeline.bind( this ),
@@ -202,6 +208,8 @@
203209 * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations
204210 */
205211 var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env );
 212+ new NoInclude( tokenPreProcessor );
 213+
206214 var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager (
207215 {
208216 'input': this.makeInputPipeline.bind( this ),
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js
@@ -137,7 +137,11 @@
138138 */
139139 MWParserEnvironment.prototype.dp = function ( ) {
140140 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+ }
142146 }
143147 };
144148
Index: trunk/extensions/VisualEditor/modules/parser/ext.util.TokenCollector.js
@@ -5,6 +5,8 @@
66 * stages (SyncTokenTransformManager), as async out-of-order expansions
77 * would wreak havoc with this kind of collector.
88 *
 9+ * @author Gabriel Wicke <gwicke@wikimedia.org>
 10+ *
911 * Calls the passed-in callback with the collected tokens.
1012 *
1113 * @class
@@ -14,7 +16,7 @@
1517 * transform( tokens, cb, manager ) with
1618 * tokens: chunk of tokens
1719 * 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.
1921 * manager: TokenTransformManager, provides the args etc.
2022 * @param {Boolean} Match the 'end' tokens as closing tag as well (accept
2123 * unclosed sections).
@@ -23,8 +25,8 @@
2426 * @param {String} (optional, only for token type 'tag'): tag name.
2527 */
2628
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;
2931 this.manager = manager;
3032 this.rank = rank;
3133 this.type = type;
@@ -48,8 +50,9 @@
4951 * Handle the delimiter token.
5052 * XXX: Adjust to sync phase callback when that is modified!
5153 */
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' );
5457 this.tokens.push ( token );
5558 if ( ! this.isActive ) {
5659 this.isActive = true;
@@ -57,12 +60,13 @@
5861 return { async: true };
5962 } else if ( token.type !== 'end' || this.toEnd ) {
6063 // end token
 64+ var res = this.transformation ( this.tokens, this.cb, this.manager );
6165 this.tokens = [];
6266 this.manager.removeTransform( this.rank + this._anyDelta, 'any' );
6367 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
6569 // tokens instead of a single token.
66 - return this.transformer ( this.tokens, this.cb, this.manager );
 70+ return res;
6771 // XXX sync version: return tokens
6872 } else if ( token.type === 'end' && ! this.toEnd ) {
6973 // Did not encounter a matching end token before the end, and are not
@@ -78,10 +82,13 @@
7983 * encountering the delimiter token, and collects all tokens until the end
8084 * token is reached.
8185 */
82 -TokenCollector.prototype._onAnyToken ( token, cb, frame ) {
 86+TokenCollector.prototype._onAnyToken = function ( token, cb, frame ) {
8387 // Simply collect anything ordinary in between
8488 this.tokens.push( token );
8589 return { };
86 -}
 90+};
8791
8892
 93+if (typeof module == "object") {
 94+ module.exports.TokenCollector = TokenCollector;
 95+}

Status & tagging log