Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/155784

Change subject: WIP: handle local interwiki links.
......................................................................

WIP: handle local interwiki links.

As part of a larger effort to allow transclusions from commons (bug 4547),
the localinterwiki flag has been added to siteinfo
(https://gerrit.wikimedia.org/r/141276).  This allows parsoid to use a
less-hacky way of identifying local links (bug 66709), and also fix a
variety of local-link test cases introduced recently in core (bug 69909).

Note that [[en:Foo]] should render differently than [[Foo]] -- the link
text for the former is `en:Foo` while for the latter it is `Foo`.
This patch fixes that issue as well (bug 45209).

Bug: 45209
Bug: 66709
Bug: 69909
Change-Id: Icf4073cab059246e7d35ccaa50c967a9fc888c9e
---
M lib/ext.core.LinkHandler.js
M tests/parserTests.js
2 files changed, 26 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/84/155784/1

diff --git a/lib/ext.core.LinkHandler.js b/lib/ext.core.LinkHandler.js
index 77e4dda..e9bb6e7 100644
--- a/lib/ext.core.LinkHandler.js
+++ b/lib/ext.core.LinkHandler.js
@@ -95,22 +95,16 @@
                        info.href = hrefBits[2];
                        // Interwiki or language link? If no language info, or 
if it starts
                        // with an explicit ':' (like [[:en:Foo]]), it's not a 
language link.
-                       if ( info.fromColonEscapedText || 
(interwikiInfo.language === undefined && interwikiInfo.extralanglink === 
undefined) ) {
+                       if ( interwikiInfo.localinterwiki !== undefined ) {
+                               // Treat it like an internal link (Bug #45209)
+                               info.title =
+                                       new Title( Util.decodeURI( info.href ), 
0, '', env );
+                       } else if ( info.fromColonEscapedText || 
(interwikiInfo.language === undefined && interwikiInfo.extralanglink === 
undefined) ) {
                                // An interwiki link.
                                info.interwiki = interwikiInfo;
                        } else {
-                               // Bug #45209: Check it's not a prefix for the 
same wiki, in which
-                               // case treat it like a normal internal link, 
not displaying the
-                               // prefix. To check if they are the same, 
remove the 'wiki' postfix
-                               // and compare to the language code.
-                               if ( interwikiInfo.prefix === 
env.conf.wiki.iwp.replace( /wiki/, '' ) ) {
-                                       // Same language, treat it like an 
internal link
-                                       info.title =
-                                               new Title( Util.decodeURI( 
info.href ), 0, '', env );
-                               } else {
-                                       // A language link.
-                                       info.language = interwikiInfo;
-                               }
+                               // A language link.
+                               info.language = interwikiInfo;
                        }
                } else {
                        info.title = new Title( Util.decodeURI(href), 0, '', 
env );
diff --git a/tests/parserTests.js b/tests/parserTests.js
index b42ea3d..d909062 100755
--- a/tests/parserTests.js
+++ b/tests/parserTests.js
@@ -1860,6 +1860,11 @@
                                                        // Hard-code some 
interwiki prefixes, as is done
                                                        // in 
parserTest.inc:setupInterwikis()
                                                        var iwl = {
+                                                               local: {
+                                                                       url: 
'http://doesnt.matter.org/$1',
+                                                                       
protorel: '',
+                                                                       
localinterwiki: ''
+                                                               },
                                                                wikipedia: {
                                                                        url: 
'http://en.wikipedia.org/wiki/$1'
                                                                },
@@ -1875,24 +1880,34 @@
                                                                        prefix: 
'zh',
                                                                        url: 
'http://zh.wikipedia.org/wiki/$1',
                                                                        
language: '\u4e2d\u6587',
+                                                                       local: 
'',
                                                                        
protorel: ''
                                                                },
                                                                es: {
                                                                        prefix: 
'es',
                                                                        url: 
'http://es.wikipedia.org/wiki/$1',
                                                                        
language: 'espa\u00f1ol',
+                                                                       local: 
'',
                                                                        
protorel: ''
                                                                },
                                                                fr: {
                                                                        prefix: 
'fr',
                                                                        url: 
'http://fr.wikipedia.org/wiki/$1',
                                                                        
language: 'fran\u00e7ais',
+                                                                       local: 
'',
                                                                        
protorel: ''
                                                                },
                                                                ru: {
                                                                        prefix: 
'ru',
                                                                        url: 
'http://ru.wikipedia.org/wiki/$1',
                                                                        
language: '\u0440\u0443\u0441\u0441\u043a\u0438\u0439',
+                                                                       local: 
'',
+                                                                       
protorel: ''
+                                                               },
+                                                               mi: {
+                                                                       url: 
'http://mi.wikipedia.org/wiki/$1',
+                                                                       local: 
'',
+                                                                       
localinterwiki: '',
                                                                        
protorel: ''
                                                                },
                                                                mul: {
@@ -1901,19 +1916,23 @@
                                                                        
extralanglink: '',
                                                                        
linktext: 'Multilingual',
                                                                        
sitename: 'WikiSource',
+                                                                       local: 
'',
                                                                        
protorel: ''
+
                                                                },
                                                                // not in PHP 
setupInterwikis(), but needed
                                                                en: {
                                                                        prefix: 
'en',
                                                                        url: 
'http://en.wikipedia.org/wiki/$1',
                                                                        
language: 'English',
+                                                                       local: 
'',
                                                                        
protorel: ''
                                                                },
                                                                ko: {
                                                                        prefix: 
'ko',
                                                                        url: 
'http://ko.wikipedia.org/wiki/$1',
                                                                        
language: '\ud55c\uad6d\uc5b4',
+                                                                       local: 
'',
                                                                        
protorel: ''
                                                                }
                                                        };

-- 
To view, visit https://gerrit.wikimedia.org/r/155784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf4073cab059246e7d35ccaa50c967a9fc888c9e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to