jenkins-bot has submitted this change and it was merged.
Change subject: Remove instances of env.conf.parsoid.apiURI
......................................................................
Remove instances of env.conf.parsoid.apiURI
* All these uses look like mistakes that should have been set on the
wiki config, which has a apiURI field.
* Also, freeze parsoid config to prevent further issues where it gets
used across requests.
* The FIXME removal from parserTests should have been cleared with
35a3a5b135b6392af17f1c5f363d0532bc76304f.
Change-Id: Ie1e357883c33202ba7f6df260de9149c17987e0c
---
M lib/ext.core.ExtensionHandler.js
M lib/ext.core.TemplateHandler.js
M lib/mediawiki.ParsoidConfig.js
M lib/mediawiki.parser.environment.js
M tests/fetch-wt.js
M tests/parse.js
M tests/parserTests.js
M tests/roundtrip-test.js
8 files changed, 33 insertions(+), 16 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/ext.core.ExtensionHandler.js b/lib/ext.core.ExtensionHandler.js
index fe1b2a3..dee7204 100644
--- a/lib/ext.core.ExtensionHandler.js
+++ b/lib/ext.core.ExtensionHandler.js
@@ -26,7 +26,7 @@
ExtensionHandler.prototype.register = function() {
this.usePHPPreProcessor = this.env.conf.parsoid.usePHPPreProcessor &&
- (this.env.conf.parsoid.apiURI !== null);
+ (this.env.conf.wiki.apiURI !== null);
// Native extension handlers
var nativeExts = this.env.conf.parsoid.nativeExtensions;
diff --git a/lib/ext.core.TemplateHandler.js b/lib/ext.core.TemplateHandler.js
index 5f733b9..2ab8616 100644
--- a/lib/ext.core.TemplateHandler.js
+++ b/lib/ext.core.TemplateHandler.js
@@ -109,8 +109,7 @@
this.convertAttribsToString(state, token.attribs, cb);
return;
}
- if ( env.conf.parsoid.usePHPPreProcessor &&
- env.conf.parsoid.apiURI !== null ) {
+ if (env.conf.parsoid.usePHPPreProcessor && env.conf.wiki.apiURI !==
null) {
if ( this.options.wrapTemplates ) {
// Use MediaWiki's action=expandtemplates preprocessor
// We'll never get to frame depth beyond 1 in this
scenario
diff --git a/lib/mediawiki.ParsoidConfig.js b/lib/mediawiki.ParsoidConfig.js
index b646fe5..dc6ed1f 100644
--- a/lib/mediawiki.ParsoidConfig.js
+++ b/lib/mediawiki.ParsoidConfig.js
@@ -8,6 +8,7 @@
var url = require('url');
var Cite = require('./ext.Cite.js').Cite;
var Util = require('./mediawiki.Util.js').Util;
+var JSUtils = require('./jsutils.js').JSUtils;
var sitematrix = require('./sitematrix.json').sitematrix;
@@ -56,6 +57,14 @@
if ( this.useDefaultPerformanceTimer ) {
this.performanceTimer = new Util.StatsD( this.txstatsdHost,
this.txstatsdPort );
}
+
+ // ParsoidConfig is used across requests. Freeze it to avoid mutation.
+ // The option to remain unfrozen is for specific use cases (think
+ // parserTests) but we should work towards eliminating those (with
+ // the possible introduction of a clone() method).
+ if (!this.unfrozen) {
+ JSUtils.deepFreeze(this);
+ }
}
/**
diff --git a/lib/mediawiki.parser.environment.js
b/lib/mediawiki.parser.environment.js
index 34326c7..5fb32f2 100644
--- a/lib/mediawiki.parser.environment.js
+++ b/lib/mediawiki.parser.environment.js
@@ -295,7 +295,6 @@
prefix + '; defaulting to
enwiki');
uri = parsoid.interwikiMap.get('enwiki');
}
- parsoid.apiURI = uri;
if (env.confCache[prefix]) {
env.conf.wiki = env.confCache[prefix];
diff --git a/tests/fetch-wt.js b/tests/fetch-wt.js
index 0cd2d69..9fe5f5e 100755
--- a/tests/fetch-wt.js
+++ b/tests/fetch-wt.js
@@ -52,11 +52,13 @@
prefix = 'customwiki';
}
- var parsoidConfig = new ParsoidConfig( options, { defaultWiki: prefix }
);
+ options.setup = function(parsoidConfig) {
+ if (options.apiURL) {
+ parsoidConfig.setInterwiki('customwiki',
options.apiURL);
+ }
+ };
- if ( options.apiURL ) {
- parsoidConfig.setInterwiki( 'customwiki', options.apiURL );
- }
+ var parsoidConfig = new ParsoidConfig(options, { defaultWiki: prefix });
MWParserEnvironment.getParserEnv( parsoidConfig, null, {
prefix: prefix,
diff --git a/tests/parse.js b/tests/parse.js
index 33af5f0..aa64197 100755
--- a/tests/parse.js
+++ b/tests/parse.js
@@ -311,7 +311,10 @@
local = require( p );
}
- var parsoidConfig = new ParsoidConfig( local, { defaultWiki:
prefix } );
+ var parsoidConfig = new ParsoidConfig(local, {
+ defaultWiki: prefix,
+ unfrozen: true // FIXME: refactor the mutations below
+ });
Util.setTemplatingAndProcessingFlags( parsoidConfig, argv );
Util.setDebuggingFlags( parsoidConfig, argv );
return parse( null, argv, parsoidConfig, prefix
).then(function( res ) {
diff --git a/tests/parserTests.js b/tests/parserTests.js
index d7888a3..8cdd8f3 100755
--- a/tests/parserTests.js
+++ b/tests/parserTests.js
@@ -26,6 +26,7 @@
var ParsoidLogger = require('../lib/ParsoidLogger.js').ParsoidLogger;
var PEG = require('pegjs');
var Util = require('../lib/mediawiki.Util.js').Util;
+var JSUtils = require('../lib/jsutils.js').JSUtils;
var Diff = require('../lib/mediawiki.Diff.js').Diff;
// Fetch up some of our wacky parser bits...
@@ -409,10 +410,6 @@
* @param {string/null} processWikitextCB.res
*/
ParserTests.prototype.convertHtml2Wt = function( options, mode, item, body,
processWikitextCB ) {
- // SSS FIXME: SelSer clobbers this flag -- need a better fix for this.
- // Maybe pass this as an option, or clone the entire environment.
- this.env.conf.parsoid.rtTestMode = options.rtTestMode;
-
var startsAtWikitext = mode === 'wt2wt' || mode === 'wt2html' || mode
=== 'selser';
try {
if (startsAtWikitext) {
@@ -1660,6 +1657,9 @@
options.expandExtensions = true;
+ // TODO: Refactor to eliminate the mutations below.
+ options.unfrozen = true;
+
var parsoidConfig = new ParsoidConfig( null, options );
parsoidConfig.interwikiMap.forEach(function( val, key ) {
parsoidConfig.interwikiMap.set(key, mockAPIServerURL);
@@ -1672,6 +1672,11 @@
Util.setDebuggingFlags(parsoidConfig, options);
Util.setTemplatingAndProcessingFlags( parsoidConfig, options );
+ parsoidConfig.rtTestMode = options.rtTestMode;
+
+ // See the todo above.
+ JSUtils.deepFreeze(parsoidConfig);
+
// Create a new parser environment
MWParserEnvironment.getParserEnv( parsoidConfig, null, { prefix:
'enwiki' }, function( err, env ) {
// For posterity: err will never be non-null here, because we
expect the WikiConfig
@@ -1683,8 +1688,6 @@
logger.registerLoggingBackends(["fatal", "error"],
parsoidConfig);
env.setLogger(logger);
}
-
- this.env.conf.parsoid.rtTestMode = options.rtTestMode;
// Enable <ref> and <references> tags since we want to
// test Parsoid's native implementation of these tags.
diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index 393a242..7c64393 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -584,7 +584,9 @@
function runTests(title, options, formatter, cb) {
// options are ParsoidConfig options if module.parent, otherwise they
// are CLI options (so use the Util.set* helpers to process them)
- var parsoidConfig = new ParsoidConfig(module.parent ? options : null);
+ var parsoidConfig = new ParsoidConfig(module.parent ? options : null, {
+ unfrozen: true // FIXME: refactor the mutations below
+ });
if (!module.parent) {
// only process CLI flags if we're running as a CLI program.
Util.setTemplatingAndProcessingFlags(parsoidConfig, options);
--
To view, visit https://gerrit.wikimedia.org/r/206487
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie1e357883c33202ba7f6df260de9149c17987e0c
Gerrit-PatchSet: 4
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: GWicke <[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