Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Improve: Follow up on task T335086
Browse files Browse the repository at this point in the history
  • Loading branch information
AnYiEE committed Apr 21, 2023
1 parent 742d1c4 commit 83a3142
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions conf/wiki-sub.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ subs_filter mapServer=mw\.config\.get\(('|\")wgKartographerMapServer\1\) mapSer
subs_filter phab\.wmfusercontent\.org phab.example.org ir;
subs_filter recommend\.wmflabs\.org recommend.wikimirror.net ir;
subs_filter wma\.wmcloud\.org wma.example.org ir;
subs_filter xtools\.wmcloud\.org\/api\/ xtools-api.example.org/ ir;
subs_filter xtools\.wmflabs\.org\/api\/ xtools-api.example.org/ ir;
############bug fix
subs_filter (?:m\.www\.|www\.m\.)(mediawiki|wikidata)\.org m.$1.example.org r;
Expand Down
6 changes: 3 additions & 3 deletions conf/wiki.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,16 @@ server {
}
error_page 404 = @errors;
include /path/to/wikimirror/conf/wiki.conf;
proxy_pass https://xtools.wmflabs.org/api/;
proxy_pass https://xtools.wmcloud.org/api/;
proxy_hide_header access-control-allow-headers;
proxy_hide_header access-control-allow-methods;
proxy_hide_header access-control-allow-origin;
proxy_hide_header set-cookie;
proxy_hide_header x-clacks-overhead;
proxy_intercept_errors on;
proxy_set_header Accept-Encoding "";
proxy_set_header Host xtools.wmflabs.org;
proxy_set_header Referer https://xtools.wmflabs.org$request_uri;
proxy_set_header Host xtools.wmcloud.org;
proxy_set_header Referer https://xtools.wmcloud.org$request_uri;
}
location @errors {
return 204;
Expand Down
17 changes: 6 additions & 11 deletions static/wikimirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const WikiMirrorStartup = async function WikiMirrorStartup() {
},
regexps: {
noDarkmode: /developer|techblog/,
xtools_api: /xtools\.(wmcloud|wmflabs)\.org\/api\//i,
},
};
const privateMethod = new WikiMirrorPrivateMethod(config);
Expand Down Expand Up @@ -97,11 +98,7 @@ const WikiMirrorStartup = async function WikiMirrorStartup() {
},
onResponse: (response, handler) => {
const contentType = response.headers['content-type'] ?? response.headers['Content-Type'];
if (
contentType &&
/json|text|xml/i.test(contentType) &&
!/css|(ecma|java)script/i.test(contentType)
) {
if (contentType && /json|text|xml/i.test(contentType) && !/css|(ecma|java)script/i.test(contentType)) {
response = privateMethod.ahCallback_Response(response);
}
handler.next(response);
Expand Down Expand Up @@ -316,9 +313,8 @@ const WikiMirrorPrivateMethod = class WikiMirrorPrivateMethod {
if (domHref.match(RegexUrlRoot)) {
dom.href = this.getRealText(domHref);
}
const XTOOLS_API = 'xtools.wmflabs.org/api/';
if (domHref.includes(XTOOLS_API)) {
dom.href = domHref.replace(XTOOLS_API, `xtools-api.${this.MIRROR_DOMAIN}/`);
if (this.regexps.xtools_api.test(domHref)) {
dom.href = domHref.replace(this.regexps.xtools_api, `xtools-api.${this.MIRROR_DOMAIN}/`);
}
}
for (const dom of [
Expand Down Expand Up @@ -365,7 +361,7 @@ const WikiMirrorPrivateMethod = class WikiMirrorPrivateMethod {
} else {
value = value
.replace(new RegExp(`phab\\.${this.MIRROR_DOMAIN}`, 'gi'), 'phab.wmfusercontent.org')
.replace(new RegExp(`xtools-api\\.${this.MIRROR_DOMAIN}\\/`, 'gi'), 'xtools.wmflabs.org/api/')
.replace(new RegExp(`xtools-api\\.${this.MIRROR_DOMAIN}\\/`, 'gi'), 'xtools.wmcloud.org/api/')
.replace(new RegExp(`wma\\.${this.MIRROR_DOMAIN_REGEX}`, 'gi'), 'wma.wmcloud.org')
.replace(new RegExp(`recommend\\.${this.MIRROR_DOMAIN_REGEX}`, 'gi'), 'recommend.wmflabs.org')
.replace(RegexUrlLatex, 'wikimedia.org/api/rest_v1/media/math/render/$1')
Expand Down Expand Up @@ -1753,8 +1749,7 @@ const WikiMirrorPrivateMethod = class WikiMirrorPrivateMethod {
getObj.host = `wma.${this.MIRROR_DOMAIN}`;
}
const urlWithPath = `${getObj.host}${getObj.pathname}`;
const XTOOLS_API = 'xtools.wmflabs.org/api/';
if (urlWithPath.includes(XTOOLS_API)) {
if (this.regexps.xtools_api.test(urlWithPath)) {
const path = this.getRealText(getObj.pathname);
getObj.host = `xtools-api.${this.MIRROR_DOMAIN}`;
getObj.pathname = path.replace('/api/', '/');
Expand Down

0 comments on commit 83a3142

Please sign in to comment.