jenkins-bot has submitted this change and it was merged.
Change subject: Make getLocationAgnosticMwApi work if both APIs are on the same
domain
......................................................................
Make getLocationAgnosticMwApi work if both APIs are on the same domain
and CORS is not configured.
Change-Id: I4564f6ba3c342a6365acddb4682b8ed38ea0f650
---
M lib/resources/api/getLocationAgnosticMwApi.js
1 file changed, 25 insertions(+), 13 deletions(-)
Approvals:
Adrian Lang: Looks good to me, but someone else must approve
Thiemo Mättig (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/resources/api/getLocationAgnosticMwApi.js
b/lib/resources/api/getLocationAgnosticMwApi.js
index 0c832f4..dc2cbd9 100644
--- a/lib/resources/api/getLocationAgnosticMwApi.js
+++ b/lib/resources/api/getLocationAgnosticMwApi.js
@@ -6,6 +6,14 @@
'use strict';
/**
+ * @param {string} url
+ * @return {string}
+ */
+function getDomainName( url ) {
+ return url.replace( /.*\/\//, '' ).replace( /\/.*/, '' );
+}
+
+/**
* Returns a mediaWiki.Api instance which can transparently interact with
remote APIs.
* @since 0.5
* @todo Merge this into mw.Api
@@ -17,25 +25,29 @@
var localApiEndpoint = mw.config.get( 'wgServer' )
+ mw.config.get( 'wgScriptPath' )
+ '/api.php';
- var mwApiOptions = {};
- if( localApiEndpoint !== apiEndpoint ) {
+ var mwApiOptions = {
+ ajax: {
+ url: apiEndpoint
+ }
+ };
+
+ if ( getDomainName( localApiEndpoint ) !== getDomainName( apiEndpoint )
) {
+ // Use CORS if the api we want to use is on a different domain.
+ // But don't if it's not: CORS isn't required if we are on the
same domain, thus it
+ // might not be configured and fail.
var corsOrigin = mw.config.get( 'wgServer' );
if ( corsOrigin.indexOf( '//' ) === 0 ) {
// The origin parameter musn't be protocol relative
corsOrigin = document.location.protocol + corsOrigin;
}
- mwApiOptions = {
- ajax: {
- url: apiEndpoint,
- xhrFields: {
- withCredentials: true
- },
- crossDomain: true
- },
- parameters: {
- origin: corsOrigin
- }
+
+ mwApiOptions.ajax.xhrFields = {
+ withCredentials: true
+ };
+ mwApiOptions.ajax.crossDomain = true;
+ mwApiOptions.parameters = {
+ origin: corsOrigin
};
}
--
To view, visit https://gerrit.wikimedia.org/r/167251
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4564f6ba3c342a6365acddb4682b8ed38ea0f650
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits