jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/351559 )
Change subject: T136653: Handle interwiki shortcuts
......................................................................
T136653: Handle interwiki shortcuts
* This accepts ./de:Foo style interwiki shortcuts in the href.
* Added parser tests to spec the shortcut behavior.
Change-Id: Ib6731407360f82bc0e1269d1a2eaf916a3912664
---
M lib/config/WikiConfig.js
M lib/html2wt/LinkHandler.js
M tests/parserTests.txt
3 files changed, 33 insertions(+), 8 deletions(-)
Approvals:
C. Scott Ananian: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/config/WikiConfig.js b/lib/config/WikiConfig.js
index 2c2442d..a86f8b9 100644
--- a/lib/config/WikiConfig.js
+++ b/lib/config/WikiConfig.js
@@ -233,13 +233,15 @@
var keys = [];
var patterns = [];
conf.interwikiMap.forEach(function(val, key) {
- keys.push(key);
var url = val.url;
var protocolRelative = url.startsWith('//');
if (val.protorel !== undefined) {
url = url.replace(/^https?:/, '');
protocolRelative = true;
}
+
+ // full-url match pattern
+ keys.push(key);
patterns.push(
// Support protocol-relative URLs
(protocolRelative ? '(?:https?:)?' : '') +
@@ -248,6 +250,14 @@
// Now convert placeholder to group match
.replace('%1', '(.*?)')
);
+
+ if (val.local !== undefined) {
+ // interwiki-prefix:title style shortcuts
+ // are recognized and the local wiki forwards
+ // these shortcuts to the remote wiki
+ keys.push(key);
+ patterns.push('^\\.\\/' + val.prefix +
':(.*?)');
+ }
});
var reString = '^(?:' + patterns.join('|') + ')$';
var regExp = new RegExp(reString);
@@ -257,16 +267,13 @@
var groups = matches.slice(1);
for (var i = 0; i < groups.length; i++) {
if (groups[i] !== undefined) {
- // The interwiki prefix: 'en',
'de' etc
var key = keys[i];
+ // The interwiki prefix: 'en',
'de' etc
if
(conf.interwikiMap.get(key).language) {
// Escape language
interwikis with a colon
key = ':' + key;
}
- return [
- key,
- groups[i],
- ];
+ return [ key, groups[i] ];
}
}
}
diff --git a/lib/html2wt/LinkHandler.js b/lib/html2wt/LinkHandler.js
index 1f0750f..4cfbc4c 100644
--- a/lib/html2wt/LinkHandler.js
+++ b/lib/html2wt/LinkHandler.js
@@ -221,6 +221,8 @@
if (target.fromsrc && !target.modified) {
// Leave the target alone!
+ } else if
(/\bmw:PageProp\/Language\b/.test(rtData.type)) {
+ target.value =
interWikiMatch.join(':').replace(/^:/, '');
} else if (oldPrefix && // Should we preserve the old
prefix?
(oldPrefix[1].toLowerCase() ===
interWikiMatch[0].toLowerCase() ||
// Check if the old prefix mapped to
the same URL as
@@ -234,9 +236,11 @@
// Modified, update target.value.
target.value = localPrefix +
oldPrefix[1] + ':' + interWikiMatch[1];
}
+ // Ensure that we generate an interwiki link
and not a language link!
+ if (rtData.isInterwikiLang &&
!/^:/.test(target.value)) {
+ target.value = ':' + target.value;
+ }
// Else: preserve old encoding
- } else if
(/\bmw:PageProp\/Language\b/.test(rtData.type)) {
- target.value =
interWikiMatch.join(':').replace(/^:/, '');
} else if (rtData.isLocal) {
// - interwikiMatch will be ":en", ":de", etc.
// - This tests whether the interwiki-like link
is actually
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index bcc6cb8..37e86cb 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -25911,6 +25911,20 @@
[[Foo]]
!! end
+!! test
+Parsoid should accept interwiki shortcuts
+!! options
+parsoid=html2wt
+!! html/parsoid
+<a rel='mw:WikiLink' href='./fr:Foo'>Foo</a>
+<a rel='mw:ExtLink' href='./fr:Foo'>Foo</a>
+<a href='./fr:Foo'>Foo</a>
+!! wikitext
+[[:fr:Foo|Foo]]
+[[:fr:Foo|Foo]]
+[[:fr:Foo|Foo]]
+!! end
+
# See T93839
!! test
New wikilinks should be serialized properly
--
To view, visit https://gerrit.wikimedia.org/r/351559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib6731407360f82bc0e1269d1a2eaf916a3912664
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Jforrester <[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