Arlolra has uploaded a new change for review. https://gerrit.wikimedia.org/r/178265
Change subject: Move environment options further up the call chain ...................................................................... Move environment options further up the call chain * As suggested in, https://gerrit.wikimedia.org/r/#/c/177878/3/lib/mediawiki.parser.environment.js Change-Id: I52f571e82aa503b885f61ad6823f927c189142cf --- M api/routes.js M lib/mediawiki.parser.environment.js M tests/fetch-wt.js M tests/mocha/lintertest.js M tests/mocha/parse.js M tests/parse.js M tests/parserTests.js M tests/roundtrip-test.js 8 files changed, 42 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/65/178265/1 diff --git a/api/routes.js b/api/routes.js index 7182a66..d8f9461 100644 --- a/api/routes.js +++ b/api/routes.js @@ -24,7 +24,8 @@ Diff = require( mp + 'mediawiki.Diff.js' ).Diff; var ParsoidCacheRequest = ApiRequest.ParsoidCacheRequest, - TemplateRequest = ApiRequest.TemplateRequest; + TemplateRequest = ApiRequest.TemplateRequest, + getParserEnv = Promise.promisify( MWParserEnv.getParserEnv, false, MWParserEnv ); module.exports = function( parsoidConfig ) { @@ -398,13 +399,11 @@ } return Promise.resolve().nodify(callback); } - Promise.promisify( MWParserEnv.getParserEnv, false, MWParserEnv )( - parsoidConfig, - null, - res.local('iwp'), - res.local('pageName'), - req.headers.cookie - ).then(function( env ) { + getParserEnv(parsoidConfig, null, { + prefix: res.local('iwp'), + pageName: res.local('pageName'), + cookie: req.headers.cookie + }).then(function( env ) { env.logger.registerBackend(/fatal(\/.*)?/, errBack.bind(this, env)); res.local('env', env); next(); diff --git a/lib/mediawiki.parser.environment.js b/lib/mediawiki.parser.environment.js index b6815e8..0fee07d 100644 --- a/lib/mediawiki.parser.environment.js +++ b/lib/mediawiki.parser.environment.js @@ -235,16 +235,14 @@ * @param {Error} cb.err * @param {MWParserEnvironment} cb.env The finished environment object */ -MWParserEnvironment.getParserEnv = function ( parsoidConfig, wikiConfig, prefix, pageName, cookie, cb ) { - var env = new MWParserEnvironment(parsoidConfig, wikiConfig, { - pageName: pageName, - cookie: cookie, - prefix: prefix - }); +MWParserEnvironment.getParserEnv = function( parsoidConfig, wikiConfig, options, cb ) { + options = options || {}; + + var env = new MWParserEnvironment(parsoidConfig, wikiConfig, options); // Get that wiki's config - env.switchToConfig(prefix, function( err ) { - if ( !err && !pageName ) { + env.switchToConfig(options.prefix, function( err ) { + if ( !err && !options.pageName ) { env.initializeForPageName( env.conf.wiki.mainpage, true ); } cb( err, env ); diff --git a/tests/fetch-wt.js b/tests/fetch-wt.js index e612fba..2b2db47 100755 --- a/tests/fetch-wt.js +++ b/tests/fetch-wt.js @@ -58,7 +58,10 @@ parsoidConfig.setInterwiki( 'customwiki', options.apiURL ); } - MWParserEnvironment.getParserEnv( parsoidConfig, null, prefix, page, null, envCb ); + MWParserEnvironment.getParserEnv( parsoidConfig, null, { + prefix: prefix, + pageName: page + }, envCb ); }; var usage = 'Usage: $0 [options] <page-title or rev-id>\n' + diff --git a/tests/mocha/lintertest.js b/tests/mocha/lintertest.js index c6f5f87..fc116d1 100644 --- a/tests/mocha/lintertest.js +++ b/tests/mocha/lintertest.js @@ -12,12 +12,13 @@ var getParserEnv = Promise.promisify(MWParserEnvironment.getParserEnv, false, MWParserEnvironment); describe( 'Linter Tests', function() { - var parsoidConfig = new ParsoidConfig( null, { defaultWiki: 'enwiki' } ); - parsoidConfig.linting = true; - + var parsoidConfig = new ParsoidConfig( null, { defaultWiki: 'enwiki', linting: true } ); var parseWT = function( wt ) { - return getParserEnv( parsoidConfig, null, 'enwiki', 'Main_Page', null).then(function(env) { + return getParserEnv(parsoidConfig, null, { + prefix: 'enwiki', + pageName: 'Main_Page' + }).then(function(env) { env.setPageSrcInfo( wt ); var pipeline = env.pipelineFactory; diff --git a/tests/mocha/parse.js b/tests/mocha/parse.js index c0bc0f9..40c83f4 100644 --- a/tests/mocha/parse.js +++ b/tests/mocha/parse.js @@ -11,6 +11,8 @@ Util = require('../../lib/mediawiki.Util.js').Util, ParsoidConfig = require('../../lib/mediawiki.ParsoidConfig' ).ParsoidConfig; +var getParserEnv = Promise.promisify(MWParserEnvironment.getParserEnv, false, MWParserEnvironment); + describe( 'ParserPipelineFactory', function() { var parsoidConfig = new ParsoidConfig( null, { defaultWiki: 'enwiki' } ); @@ -18,18 +20,18 @@ var parse = function(src, options) { options = options || {}; - return new Promise(function(resolve, reject) { - MWParserEnvironment.getParserEnv( parsoidConfig, null, options.prefix || 'enwiki', options.page_name || 'Main_Page', null, function ( err, env ) { - if (err) { return reject(err); } - if (options.tweakEnv) { - env = options.tweakEnv(env) || env; - } - env.setPageSrcInfo(src); - var pipeline = env.pipelineFactory; - Promise.promisify( pipeline.parse, false, pipeline )( - env, env.page.src, options.expansions - ).then( resolve, reject ); - }); + return getParserEnv(parsoidConfig, null, { + prefix: options.prefix || 'enwiki', + pageName: options.page_name || 'Main_Page' + }).then(function(env) { + if (options.tweakEnv) { + env = options.tweakEnv(env) || env; + } + env.setPageSrcInfo(src); + var pipeline = env.pipelineFactory; + return Promise.promisify( pipeline.parse, false, pipeline )( + env, env.page.src, options.expansions + ); }); }; diff --git a/tests/parse.js b/tests/parse.js index 659325a..3b1609d 100755 --- a/tests/parse.js +++ b/tests/parse.js @@ -173,7 +173,10 @@ }; var parse = exports.parse = function( input, argv, parsoidConfig, prefix ) { - return getParserEnv( parsoidConfig, null, prefix, argv.page || null, null ).then(function( env ) { + return getParserEnv(parsoidConfig, null, { + prefix: prefix, + pageName: argv.page + }).then(function( env ) { // fetch templates from enwiki by default. if ( argv.wgScriptPath ) { diff --git a/tests/parserTests.js b/tests/parserTests.js index cfa9224..3bad932 100755 --- a/tests/parserTests.js +++ b/tests/parserTests.js @@ -1636,7 +1636,7 @@ } // Create a new parser environment - MWParserEnvironment.getParserEnv( parsoidConfig, null, 'enwiki', null, null, function ( err, env ) { + MWParserEnvironment.getParserEnv( parsoidConfig, null, { prefix: 'enwiki' }, function( err, env ) { // For posterity: err will never be non-null here, because we expect the WikiConfig // to be basically empty, since the parserTests environment is very bare. this.env = env; diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js index 4bb28c7..1a3fa34 100755 --- a/tests/roundtrip-test.js +++ b/tests/roundtrip-test.js @@ -617,7 +617,7 @@ Util.setDebuggingFlags( parsoidConfig, options ); } - MWParserEnvironment.getParserEnv( parsoidConfig, null, prefix, page, null, envCb ); + MWParserEnvironment.getParserEnv( parsoidConfig, null, { prefix: prefix, pageName: page }, envCb ); return cb.promise; }; -- To view, visit https://gerrit.wikimedia.org/r/178265 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I52f571e82aa503b885f61ad6823f927c189142cf Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
