Arlolra has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/397648 )

Change subject: Stop emitting isIW in dp
......................................................................

Stop emitting isIW in dp

Change-Id: I22fb1d8bdf1cceea6855d67feacf158f127243c6
---
M lib/html2wt/LinkHandler.js
M lib/wt2html/tt/LinkHandler.js
M tests/parserTests-blacklist.js
M tests/parserTests.txt
4 files changed, 22 insertions(+), 19 deletions(-)


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

diff --git a/lib/html2wt/LinkHandler.js b/lib/html2wt/LinkHandler.js
index b9f4f06..c5ba776 100644
--- a/lib/html2wt/LinkHandler.js
+++ b/lib/html2wt/LinkHandler.js
@@ -89,16 +89,21 @@
                tail: dp.tail || '',
                prefix: dp.prefix || '',
                content: {},  // string or tokens
+               isInterwiki: false,
        };
+
+       var isIW = false;
 
        // Figure out the type of the link
        var rel = node.getAttribute('rel');
        if (rel) {
-               // Parsoid only emits and recognizes ExtLink, WikiLink, and 
PageProp rel values.
-               // Everything else defaults to ExtLink during serialization 
(unless it is
-               // serializable to a wikilink)
+               // Parsoid only emits and recognizes ExtLink, WikiLink, Media, 
and
+               // PageProp rel values.  Everything else defaults to ExtLink 
during
+               // serialization (unless it is serializable to a wikilink).
                var typeMatch = 
rel.match(/\b(mw:(WikiLink|ExtLink|Media|PageProp)[^\s]*)\b/);
                if (typeMatch) {
+                       // Note this before stripping the subtype
+                       isIW = (typeMatch[0] === 'mw:WikiLink/Interwiki');
                        rtData.type = typeMatch[1];
                        // Strip link subtype info
                        if (/^mw:(Wiki|Ext)Link\//.test(rtData.type)) {
@@ -193,9 +198,8 @@
                        && !/^#|\?./.test(interWikiMatch[1])
                                // ExtLinks should have content to convert.
                        && (rtData.type !== 'mw:ExtLink' || 
rtData.content.string || rtData.contentNode)
-                       && (dp.isIW || target.modified || 
rtData.contentModified)) {
+                       && (isIW || target.modified || rtData.contentModified)) 
{
                        // External link that is really an interwiki link. 
Convert it.
-                       // TODO: Leaving this for backwards compatibility, 
remove when 1.5 is no longer bound
                        if (rtData.type === 'mw:ExtLink') {
                                rtData.type = 'mw:WikiLink';
                        }
diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js
index 5aea514..9faf0ae 100644
--- a/lib/wt2html/tt/LinkHandler.js
+++ b/lib/wt2html/tt/LinkHandler.js
@@ -633,8 +633,7 @@
 
        // Change the rel to be mw:ExtLink
        Util.lookupKV(newTk.attribs, 'rel').v = 'mw:WikiLink/Interwiki';
-       // Remember that this was using wikitext syntax though
-       newTk.dataAttribs.isIW = true;
+
        // Add title unless it's just a fragment (and trim off fragment)
        // (The normalization here is similar to what Title#getPrefixedDBKey() 
does.)
        if (target.href[0] !== "#") {
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index f10fdc9..1a37b1f 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -59,7 +59,7 @@
 add("wt2html", "Self-link to numeric title", "<p 
data-parsoid='{\"dsr\":[0,5,0,0]}'><a rel=\"mw:WikiLink\" href=\"./0\" 
title=\"0\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./0\"},\"sa\":{\"href\":\"0\"},\"dsr\":[0,5,2,2]}'>0</a></p>");
 add("wt2html", "<nowiki> inside a link", "<p 
data-parsoid='{\"dsr\":[0,96,0,0]}'><a rel=\"mw:WikiLink\" href=\"./Main_Page\" 
title=\"Main Page\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Main_Page\"},\"sa\":{\"href\":\"Main&lt;nowiki>
 Page&lt;/nowiki>\"},\"dsr\":[0,30,2,2]}'>Main Page</a> <a rel=\"mw:WikiLink\" 
href=\"./Main_Page\" title=\"Main Page\" 
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Main_Page\"},\"sa\":{\"href\":\"Main
 Page\"},\"dsr\":[31,96,12,2]}'>the main page <span typeof=\"mw:Nowiki\" 
data-parsoid='{\"dsr\":[57,94,8,9]}'>[it's not very good]</span></a></p>");
 add("wt2html", "Interlanguage link with spacing", "<p 
data-parsoid='{\"dsr\":[0,14,0,0]}'>Blah blah blah</p>\n<link 
rel=\"mw:PageProp/Language\" 
href=\"http://zh.wikipedia.org/wiki/%20%20%20%20Chinese%20%20%20%20%20\"; 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"http://zh.wikipedia.org/wiki/%20%20%20%20Chinese%20%20%20%20%20\"},\"sa\":{\"href\":\";
   zh  :    Chinese     \"},\"dsr\":[15,43,null,null]}'/>");
-add("wt2html", "Escaping of interlanguage links (T129218, T156308)", "<p 
data-parsoid='{\"dsr\":[0,51,0,0]}'>Blah blah blah\n<a 
rel=\"mw:WikiLink/Interwiki\" href=\"http://es.wikipedia.org/wiki/Spanish\"; 
title=\"es:Spanish\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"http://es.wikipedia.org/wiki/Spanish\"},\"sa\":{\"href\":\":es:Spanish\"},\"isIW\":true,\"dsr\":[15,30,2,2]}'>es:Spanish</a>\n<a
 rel=\"mw:WikiLink\" href=\"./Zh_:_Chinese\" title=\"Zh : Chinese\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Zh_:_Chinese\"},\"sa\":{\"href\":\"
 : zh : Chinese \"},\"dsr\":[31,51,2,2]}'> : zh : Chinese </a></p>");
+add("wt2html", "Escaping of interlanguage links (T129218, T156308)", "<p 
data-parsoid='{\"dsr\":[0,51,0,0]}'>Blah blah blah\n<a 
rel=\"mw:WikiLink/Interwiki\" href=\"http://es.wikipedia.org/wiki/Spanish\"; 
title=\"es:Spanish\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"http://es.wikipedia.org/wiki/Spanish\"},\"sa\":{\"href\":\":es:Spanish\"},\"dsr\":[15,30,2,2]}'>es:Spanish</a>\n<a
 rel=\"mw:WikiLink\" href=\"./Zh_:_Chinese\" title=\"Zh : Chinese\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Zh_:_Chinese\"},\"sa\":{\"href\":\"
 : zh : Chinese \"},\"dsr\":[31,51,2,2]}'> : zh : Chinese </a></p>");
 add("wt2html", "Space and question mark encoding in interlanguage links 
(T95473)", "<p data-parsoid='{\"dsr\":[0,14,0,0]}'>Blah blah blah</p>\n<link 
rel=\"mw:PageProp/Language\" href=\"http://es.wikipedia.org/wiki/Foo%20bar?\"; 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"http://es.wikipedia.org/wiki/Foo%20bar?\"},\"sa\":{\"href\":\"es:Foo
 bar?\"},\"dsr\":[15,30,null,null]}'/>");
 add("wt2html", "2. Lists with start-of-line-transparent tokens before bullets: 
Template close", "<ul about=\"#mwt1\" typeof=\"mw:Transclusion\" 
data-parsoid='{\"dsr\":[0,18,0,0],\"firstWikitextNode\":\"UL\",\"pi\":[[{\"k\":\"1\"}]]}'
 data-mw='{\"parts\":[\"*foo 
\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"bar\\n\"}},\"i\":0}}]}'><li>foo
 bar</li></ul><span about=\"#mwt1\">\n</span><p 
data-parsoid='{\"dsr\":[18,22,0,0]}'>*baz</p>");
 add("wt2html", "Multiple list tags generated by templates", "<li 
about=\"#mwt1\" typeof=\"mw:Transclusion\" 
data-parsoid='{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[0,44,null,null],\"pi\":[[{\"k\":\"1\"}],[{\"k\":\"1\"}],[{\"k\":\"1\"}]]}'
 
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&lt;li>\"}},\"i\":0}},\"a\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&lt;li>\"}},\"i\":1}},\"b\\n\",{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&lt;li>\"}},\"i\":2}},\"c\"]}'>a\n</li><li
 about=\"#mwt1\">b\n</li><li about=\"#mwt1\" 
data-parsoid='{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[null,44,null,0]}'>c</li>");
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 281b6ad..bb12be8 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -8721,7 +8721,7 @@
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./Main_Page#Is_this_great?" 
data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#Is_this_great?"},"sa":{"href":"#Is
 this great?"}}'>#Is this great?</a>
 <a rel="mw:WikiLink" href="./Foo#Is_this_great?" title="Foo" 
data-parsoid='{"stx":"simple","a":{"href":"./Foo#Is_this_great?"},"sa":{"href":"Foo#Is
 this great?"}}'>Foo#Is this great?</a>
-<a rel="mw:WikiLink/Interwiki" 
href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great?"; 
title="meatball:Foo" 
data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great?"},"sa":{"href":"meatball:Foo#Is
 this great?"},"isIW":true}'>meatball:Foo#Is this great?</a></p>
+<a rel="mw:WikiLink/Interwiki" 
href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great?"; 
title="meatball:Foo" 
data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great?"},"sa":{"href":"meatball:Foo#Is
 this great?"}}'>meatball:Foo#Is this great?</a></p>
 !! end
 
 !! test
@@ -8761,19 +8761,19 @@
 
 [[  wikiPEdia :Foo]]
 !! html/parsoid
-<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" 
data-parsoid='{"stx":"simple","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"},"isIW":true}'
 title="en:Foo">en:Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" 
data-parsoid='{"stx":"simple","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"}}'
 title="en:Foo">en:Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" 
data-parsoid='{"stx":"piped","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"},"isIW":true}'
 title="en:Foo">Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" 
data-parsoid='{"stx":"piped","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"}}'
 title="en:Foo">Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"isIW":true}'
 title="wikipedia:Foo">wikipedia:Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"}}'
 title="wikipedia:Foo">wikipedia:Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":":wikipedia:Foo"},"isIW":true}'
 title="wikipedia:Foo">Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":":wikipedia:Foo"}}'
 title="wikipedia:Foo">Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":"wikipedia:en:Foo"},"isIW":true}'
 title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":"wikipedia:en:Foo"}}'
 title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":":wikipedia:en:Foo"},"isIW":true}'
 title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":":wikipedia:en:Foo"}}'
 title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>
 
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":";
  wikiPEdia :Foo"},"isIW":true}' title="wikipedia:Foo">  wikiPEdia :Foo</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":";
  wikiPEdia :Foo"}}' title="wikipedia:Foo">  wikiPEdia :Foo</a></p>
 !! end
 
 !! test
@@ -8808,7 +8808,7 @@
 <p><a href="http://en.wikipedia.org/wiki/Foo"; class="extiw" 
title="wikipedia:Foo">Bar</a>
 </p>
 !! html/parsoid
-<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"isIW":true,"tail":"r"}'
 title="wikipedia:Foo">Bar</a></p>
+<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo"; 
data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"tail":"r"}'
 title="wikipedia:Foo">Bar</a></p>
 !! end
 
 !! test
@@ -15291,7 +15291,7 @@
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a 
MeatBall:Link in it"><img alt="text with a MeatBall:Link in it" 
src="http://example.com/images/3/3a/Foobar.jpg"; width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><figure-inline class="mw-default-size" typeof="mw:Image" 
data-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[MeatBall:Link]] 
in it"}]}' data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink/Interwiki\" 
href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\"; title=\"meatball:Link\" 
data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"isIW\":true,\"dsr\":[30,47,2,2]}&#39;>MeatBall:Link&lt;/a>
 in it"}'><a href="./File:Foobar.jpg" 
data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941" 
data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></figure-inline></p>
+<p><figure-inline class="mw-default-size" typeof="mw:Image" 
data-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[MeatBall:Link]] 
in it"}]}' data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink/Interwiki\" 
href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\"; title=\"meatball:Link\" 
data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"dsr\":[30,47,2,2]}&#39;>MeatBall:Link&lt;/a>
 in it"}'><a href="./File:Foobar.jpg" 
data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941" 
data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></figure-inline></p>
 !! end
 
 !! test
@@ -15302,7 +15302,7 @@
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a link in 
it"><img alt="text with a link in it" 
src="http://example.com/images/3/3a/Foobar.jpg"; width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><figure-inline class="mw-default-size" typeof="mw:Image" 
data-parsoid='{"optList":[{"ck":"caption","ak":"text with a 
[[MeatBall:Link|link]] in it"}]}' data-mw='{"caption":"text with a &lt;a 
rel=\"mw:WikiLink/Interwiki\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\"; 
title=\"meatball:Link\" 
data-parsoid=&#39;{\"stx\":\"piped\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"isIW\":true,\"dsr\":[30,52,16,2]}&#39;>link&lt;/a>
 in it"}'><a href="./File:Foobar.jpg" 
data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941" 
data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></figure-inline></p>
+<p><figure-inline class="mw-default-size" typeof="mw:Image" 
data-parsoid='{"optList":[{"ck":"caption","ak":"text with a 
[[MeatBall:Link|link]] in it"}]}' data-mw='{"caption":"text with a &lt;a 
rel=\"mw:WikiLink/Interwiki\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\"; 
title=\"meatball:Link\" 
data-parsoid=&#39;{\"stx\":\"piped\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"dsr\":[30,52,16,2]}&#39;>link&lt;/a>
 in it"}'><a href="./File:Foobar.jpg" 
data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941" 
data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></figure-inline></p>
 !! end
 
 !! test

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22fb1d8bdf1cceea6855d67feacf158f127243c6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <abrea...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to