jenkins-bot has submitted this change and it was merged. 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, 43 insertions(+), 40 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/api/routes.js b/api/routes.js index 7182a66..42a65ba 100644 --- a/api/routes.js +++ b/api/routes.js @@ -398,13 +398,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 ) { + MWParserEnv.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..53a49d2 100644 --- a/lib/mediawiki.parser.environment.js +++ b/lib/mediawiki.parser.environment.js @@ -3,7 +3,8 @@ var WikiConfig = require( './mediawiki.WikiConfig.js' ).WikiConfig, ParsoidConfig = require( './mediawiki.ParsoidConfig.js' ).ParsoidConfig, ConfigRequest = require( './mediawiki.ApiRequest.js' ).ConfigRequest, - Util = require( './mediawiki.Util.js').Util, + Util = require('./mediawiki.Util.js').Util, + JSUtils = require('./jsutils.js').JSUtils, Title = require('./mediawiki.Title.js').Title, ParserPipelineFactory = require( './mediawiki.parser.js' ).ParserPipelineFactory, Linter = require('./linter.js').Linter, @@ -235,20 +236,21 @@ * @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 || {}; + cb = JSUtils.mkPromised(cb); + + 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 ); }); + + return cb.promise; }; /** 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..377d192 100644 --- a/tests/mocha/lintertest.js +++ b/tests/mocha/lintertest.js @@ -9,15 +9,14 @@ Util = require('../../lib/mediawiki.Util.js').Util, ParsoidConfig = require('../../lib/mediawiki.ParsoidConfig' ).ParsoidConfig; -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 MWParserEnvironment.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..4efb501 100644 --- a/tests/mocha/parse.js +++ b/tests/mocha/parse.js @@ -18,18 +18,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 MWParserEnvironment.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..79edf7a 100755 --- a/tests/parse.js +++ b/tests/parse.js @@ -17,8 +17,6 @@ fs = require('fs'), path = require('path'); -var getParserEnv = Promise.promisify( ParserEnv.getParserEnv, false, ParserEnv ); - process.on('SIGUSR2', function() { var heapdump = require('heapdump'); console.error('SIGUSR2 received! Writing snapshot.'); @@ -173,7 +171,10 @@ }; var parse = exports.parse = function( input, argv, parsoidConfig, prefix ) { - return getParserEnv( parsoidConfig, null, prefix, argv.page || null, null ).then(function( env ) { + return ParserEnv.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: merged Gerrit-Change-Id: I52f571e82aa503b885f61ad6823f927c189142cf Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <[email protected]> Gerrit-Reviewer: Arlolra <[email protected]> Gerrit-Reviewer: Cscott <[email protected]> Gerrit-Reviewer: Marcoil <[email protected]> Gerrit-Reviewer: Subramanya Sastry <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
