jenkins-bot has submitted this change and it was merged.
Change subject: Allow configuration of the "domain" separate from the MW API URL
......................................................................
Allow configuration of the "domain" separate from the MW API URL
This prevents functionality regression compared to the v1 API.
Change-Id: Idcc969d7c27e850b54707b4aadc8447b6ec9d98e
---
M api/routes.js
M lib/mediawiki.ParsoidConfig.js
M tests/roundtrip-test.js
3 files changed, 30 insertions(+), 18 deletions(-)
Approvals:
Subramanya Sastry: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/routes.js b/api/routes.js
index d512b2f..8f12594 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -47,7 +47,7 @@
var iwp = parsoidConfig.reverseMwApiMap.get(req.params.domain);
if (!iwp) {
- return errOut('Invalid domain.');
+ return errOut('Invalid domain: ' + req.params.domain);
}
res.local('iwp', iwp);
@@ -463,7 +463,7 @@
var revid = env.page.meta.revision.revid;
var path = [
'/v2',
-
url.parse(env.conf.parsoid.mwApiMap.get(ret.prefix).uri).host,
+
env.conf.parsoid.mwApiMap.get(ret.prefix).domain,
v2.format,
encodeURIComponent(ret.target),
revid,
diff --git a/lib/mediawiki.ParsoidConfig.js b/lib/mediawiki.ParsoidConfig.js
index 4652052..88a80c0 100644
--- a/lib/mediawiki.ParsoidConfig.js
+++ b/lib/mediawiki.ParsoidConfig.js
@@ -401,28 +401,40 @@
/**
* @method
*
- * Set an mw api prefix.
+ * Set an mw api configuration.
*
* @param {String} prefix
- * @param {String|Object} apiConf If a string, apiConf is the apiURI.
- * @param {String} apiConf.uri The URL to the wiki's api.php.
- * @param {Object} apiConf.proxy
- * @param {String} apiConf.proxy.uri The URL of a proxy to use for API
requests,
- * or null to explicitly disable API request proxying for this wiki. Will fall
- * back to ParsoidConfig.defaultAPIProxyURI if undefined (default value).
- * @param {Object} apiConf.proxy.headers Headers to add when proxying.
+ * An arbitrary unique identifier for this wiki.
+ * @param {String|Object} apiConf
+ * If a string, apiConf is the wiki's Action API URL.
+ * @param {String} apiConf.uri
+ * The URL to the wiki's Action API (`api.php`).
+ * @param {String} [apiConf.domain]
+ * The "domain" used to identify this wiki when using the Parsoid v2 API.
+ * It defaults to the hostname portion of `apiConf.uri`.
+ * @param {Object} [apiConf.proxy]
+ * A proxy configuration object.
+ * @param {String|null} [apiConf.proxy.uri]
+ * The URL of a proxy to use for API requests, or null to explicitly
+ * disable API request proxying for this wiki. Will fall back to
+ * {@link ParsoidConfig#defaultAPIProxyURI} if `undefined` (default value).
+ * @param {Object} [apiConf.proxy.headers]
+ * Headers to add when proxying.
*/
ParsoidConfig.prototype.setInterwiki = // Alias for backwards compat.
ParsoidConfig.prototype.setMwApi = function(prefix, apiConf) {
if (typeof apiConf === 'string') {
apiConf = { uri: apiConf };
}
+ if (!apiConf.domain) {
+ apiConf.domain = url.parse(apiConf.uri).host;
+ }
if (this.mwApiMap.has(prefix)) {
-
this.reverseMwApiMap.delete(url.parse(this.mwApiMap.get(prefix).uri).host);
+ this.reverseMwApiMap.delete(this.mwApiMap.get(prefix).domain);
}
this.mwApiMap.set(prefix, apiConf);
- this.reverseMwApiMap.set(url.parse(apiConf.uri).host, prefix);
+ this.reverseMwApiMap.set(apiConf.domain, prefix);
if (this.mwApiRegexp.match('(^|\\|)' + prefix + '(\\||$)') === null) {
this.mwApiRegexp += (this.mwApiRegexp ? '|' : '') + prefix;
@@ -441,8 +453,8 @@
if (!this.mwApiMap.has(prefix)) {
return;
}
- var u = url.parse(this.mwApiMap.get(prefix).uri);
- this.reverseMwApiMap.delete(u.host);
+ var domain = this.mwApiMap.get(prefix).domain;
+ this.reverseMwApiMap.delete(domain);
this.mwApiMap.delete(prefix);
this.mwApiRegexp = this.mwApiRegexp.replace(
new RegExp('(^|\\|)' + prefix + '(\\||$)'), function() {
diff --git a/tests/roundtrip-test.js b/tests/roundtrip-test.js
index b932ac5..8be36f8 100755
--- a/tests/roundtrip-test.js
+++ b/tests/roundtrip-test.js
@@ -546,11 +546,11 @@
// If prefix is present, use that.
prefix = options.prefix;
// Get the domain from the mw api map.
- var apiURL = parsoidConfig.mwApiMap.get(prefix).uri;
- if (!apiURL) {
- err = new Error('Couldn\'t find the domain for prefix '
+ prefix);
+ if (parsoidConfig.mwApiMap.has(prefix)) {
+ domain = parsoidConfig.mwApiMap.get(prefix).domain;
+ } else {
+ err = new Error('Couldn\'t find the domain for prefix:
' + prefix);
}
- domain = url.parse(apiURL).hostname;
} else if (options.domain) {
domain = options.domain;
prefix = parsoidConfig.reverseMwApiMap.get(domain);
--
To view, visit https://gerrit.wikimedia.org/r/232840
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idcc969d7c27e850b54707b4aadc8447b6ec9d98e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Alex Monk <[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