| 1 | /** |
| 2 | * Compares the default Uri host, usually `window.location.host`, and `mw.Uri.host`. Equivalence |
| 3 | * tests internal linkage, a mismatch may indicate an external link. Interwiki links are |
| 4 | * considered external. |
| 5 | * |
| 6 | * This function only indicates internal in the sense of being on the same host or not. It has |
| 7 | * no knowledge of [[Link]] vs [Link] links. |
| 8 | * |
| 9 | * On https://meta.wikimedia.org/wiki/Foo, the following links would be considered *internal* |
| 10 | * and return `true`: |
| 11 | * |
| 12 | * https://meta.wikimedia.org/ |
| 13 | * https://meta.wikimedia.org/wiki/Bar |
| 14 | * https://meta.wikimedia.org/w/index.php?title=Bar |
| 15 | * |
| 16 | * Similarly, the following links would be considered *not* internal and return `false`: |
| 17 | * |
| 18 | * https://archive.org/ |
| 19 | * https://foo.wikimedia.org/ |
| 20 | * https://en.wikipedia.org/ |
| 21 | * https://en.wikipedia.org/wiki/Bar |
| 22 | * |
| 23 | * @ignore |
| 24 | * @param {mw.Uri} uri |
| 25 | * @return {boolean} |
| 26 | */ |
| 27 | function isInternal( uri ) { |
| 28 | try { |
| 29 | // mw.Uri can throw exceptions (T264914, T66884) |
| 30 | return uri.host === mw.Uri().host; |
| 31 | } catch ( e ) { |
| 32 | return false; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | module.exports = { |
| 37 | isInternal |
| 38 | }; |