jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/363654 )

Change subject: T169342: Render missing gallery images the same as plain
......................................................................


T169342: Render missing gallery images the same as plain

Change-Id: I1562c6ef7ec70712eb15110b4fec552c57ba4366
---
M lib/ext/Gallery/index.js
M lib/ext/Gallery/modes.js
M tests/parserTests.txt
3 files changed, 30 insertions(+), 40 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/ext/Gallery/index.js b/lib/ext/Gallery/index.js
index f0b7d28..63ac4be 100644
--- a/lib/ext/Gallery/index.js
+++ b/lib/ext/Gallery/index.js
@@ -159,12 +159,6 @@
                        figcaption.insertBefore(galleryfilename, 
figcaption.firstChild);
                }
 
-               var typeOf = thumb.getAttribute('typeof');
-               if (/\bmw:Error\b/.test(typeOf)) {
-                       while (thumb.firstChild) { thumb.firstChild.remove(); }
-                       thumb.appendChild(doc.createTextNode(text));
-               }
-
                var gallerytext = !/^\s*$/.test(figcaption.innerHTML) && 
figcaption;
                if (gallerytext) {
                        // Store before `migrateChildrenBetweenDocs` in render
@@ -264,7 +258,7 @@
                                var elt = thumb.querySelector('img, video');
                                var resource = null;
                                if (elt) {
-                                       // FIXME: Should we preserve the 
original namespace?
+                                       // FIXME: Should we preserve the 
original namespace?  See T151367
                                        resource = elt.getAttribute('resource');
                                        if (resource !== null) {
                                                content += 
resource.replace(/^\.\//, '');
@@ -274,6 +268,10 @@
                                                }
                                        }
                                } else {
+                                       // TODO: Previously (<=1.5.0), we 
rendered valid titles
+                                       // returning mw:Error 
(apierror-filedoesnotexist) as
+                                       // plaintext.  Continue to serialize 
this content until
+                                       // that version is no longer supported.
                                        content += thumb.textContent;
                                }
                                // The first "a" is for the link, hopefully.
diff --git a/lib/ext/Gallery/modes.js b/lib/ext/Gallery/modes.js
index 8929ff3..230983d 100644
--- a/lib/ext/Gallery/modes.js
+++ b/lib/ext/Gallery/modes.js
@@ -110,11 +110,7 @@
        thumb.setAttribute('style', this.thumbStyle(width, height));
 
        var wrapper = doc.createElement('span');
-       // Only place the attrs if we rendered media.
-       var elt = o.thumb.querySelector('img, video');
-       if (elt) {
-               wrapper.setAttribute('typeof', o.rdfaType);
-       }
+       wrapper.setAttribute('typeof', o.rdfaType);
        DU.migrateChildrenBetweenDocs(o.thumb, wrapper);
        thumb.appendChild(wrapper);
 
@@ -152,19 +148,15 @@
 
 Packed.prototype.scaleMedia = function(opts, wrapper) {
        var elt = wrapper.querySelector('img, video');
-       if (elt) {
-               var width = parseInt(elt.getAttribute('width'), 10);
-               if (Number.isNaN(width)) {
-                       width = opts.imageWidth;
-               } else {
-                       width = Math.trunc(width / this.scale);
-               }
-               elt.setAttribute('width', width);
-               elt.setAttribute('height', opts.imageHeight);
-               return width;
+       var width = parseInt(elt.getAttribute('width'), 10);
+       if (Number.isNaN(width)) {
+               width = opts.imageWidth;
        } else {
-               return opts.imageWidth;
+               width = Math.trunc(width / this.scale);
        }
+       elt.setAttribute('width', width);
+       elt.setAttribute('height', opts.imageHeight);
+       return width;
 };
 
 Packed.prototype.galleryText = function(doc, box, gallerytext, width) {
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index fce7df6..3d7ae81 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -19959,7 +19959,7 @@
 
 !! html/parsoid
 <ul class="gallery mw-gallery-traditional" type="123" 
typeof="mw:Extension/gallery" about="#mwt2" 
data-mw='{"name":"gallery","attrs":{"type":"123","summary":"345"},"body":{"extsrc":"\nFile:File:Foobar.jpg\n"}}'>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>File:File:Foobar.jpg</span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:File:Foobar.jpg"><img resource="./File:File:Foobar.jpg" 
src="./Special:FilePath/File:Foobar.jpg" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
 </ul>
 !! end
 
@@ -20022,12 +20022,12 @@
 
 !! html/parsoid
 <ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" 
about="#mwt3" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>image1.png </span></div><div 
class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>image2.gif</span></div><div 
class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>image3</span></div><div 
class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>image4    </span></div><div 
class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span> image5.svg</span></div><div class="gallerytext"> 
<a rel="mw:ExtLink" href="http://///////";>http://///////</a></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>* image6</span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Image1.png"><img resource="./File:Image1.png" 
src="./Special:FilePath/Image1.png" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Image2.gif"><img resource="./File:Image2.gif" 
src="./Special:FilePath/Image2.gif" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Image3"><img resource="./File:Image3" 
src="./Special:FilePath/Image3" height="120" width="120"/></a></span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Image4"><img resource="./File:Image4" 
src="./Special:FilePath/Image4" height="300" width="300"/></a></span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Image5.svg"><img resource="./File:Image5.svg" 
src="./Special:FilePath/Image5.svg" height="120" 
width="120"/></a></span></div><div class="gallerytext"> <a rel="mw:ExtLink" 
href="http://///////";>http://///////</a></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:*_image6"><img resource="./File:*_image6" 
src="./Special:FilePath/*_image6" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
 </ul>
 !! end
 
@@ -20085,8 +20085,8 @@
 !! html/parsoid
 <ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 
226px;" typeof="mw:Extension/gallery" about="#mwt3" 
data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2"},"body":{}}'>
 <li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" 
title="Main Page">Main Page</a></li>
-<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext">caption</div></li>
-<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="40" 
width="70"/></a></span></div><div class="gallerytext">caption</div></li>
+<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="40" 
width="70"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div class="gallerytext">some 
<b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main 
Page</a></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
alt="This is a foo-bar." resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div 
class="gallerytext">blabla.</div></li>
@@ -20144,10 +20144,10 @@
 </ul>
 
 !! html/parsoid
-<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 
226px;" typeof="mw:Extension/gallery" about="#mwt3" data-parsoid='{}' 
data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2","caption":"Foo
 [[Main 
Page]]"},"body":{"extsrc":"\nFile:Nonexistent.jpg|caption\nFile:Nonexistent.jpg\nimage:foobar.jpg|some
 &#39;&#39;&#39;caption&#39;&#39;&#39; [[Main 
Page]]\nimage:foobar.jpg\nimage:foobar.jpg|Blabla|alt=This is a 
foo-bar.|blabla.\n"}}'>
+<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 
226px;" typeof="mw:Extension/gallery" about="#mwt3" 
data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2","caption":"Foo
 [[Main 
Page]]"},"body":{"extsrc":"\nFile:Nonexistent.jpg|caption\nFile:Nonexistent.jpg\nimage:foobar.jpg|some
 &#39;&#39;&#39;caption&#39;&#39;&#39; [[Main 
Page]]\nimage:foobar.jpg\nimage:foobar.jpg|Blabla|alt=This is a 
foo-bar.|blabla.\n"}}'>
 <li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" 
title="Main Page">Main Page</a></li>
-<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext">caption</div></li>
-<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="40" 
width="70"/></a></span></div><div class="gallerytext">caption</div></li>
+<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="40" 
width="70"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div class="gallerytext">some 
<b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main 
Page</a></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 
100px; height: 70px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
alt="This is a foo-bar." resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="8" width="70"/></a></span></div><div 
class="gallerytext">blabla.</div></li>
@@ -20311,14 +20311,14 @@
 
 !! html/parsoid
 <ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" 
about="#mwt3" 
data-mw='{"name":"gallery","attrs":{"showfilename":""},"body":{}}'>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename 
galleryfilename-truncate" 
title="File:Nonexistent.jpg">File:Nonexistent.jpg</a>caption</div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename 
galleryfilename-truncate" 
title="File:Nonexistent.jpg">File:Nonexistent.jpg</a></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="120" 
width="120"/></a></span></div><div class="gallerytext"><a 
href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" 
title="File:Nonexistent.jpg">File:Nonexistent.jpg</a>caption</div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="120" 
width="120"/></a></span></div><div class="gallerytext"><a 
href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" 
title="File:Nonexistent.jpg">File:Nonexistent.jpg</a></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="14" width="120"/></a></span></div><div class="gallerytext"><a 
href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" 
title="File:Foobar.jpg">File:Foobar.jpg</a>some <b>caption</b> <a 
rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="14" width="120"/></a></span></div><div class="gallerytext"><a 
href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" 
title="File:Foobar.jpg">File:Foobar.jpg</a></div></li>
 </ul>
 !! end
 
-## Should Parsoid be preserving these variations?
+## Should Parsoid be preserving these variations?  See T151367
 !! test
 Gallery (with namespace-less filenames)
 !! options
@@ -20359,8 +20359,8 @@
 
 !! html/parsoid
 <ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" 
about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>File:Nonexistent.jpg</span></div><div 
class="gallerytext"></div></li>
-<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span>Nonexistent.jpg</span></div><div 
class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
+<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Error mw:Image"><a 
href="./File:Nonexistent.jpg"><img resource="./File:Nonexistent.jpg" 
src="./Special:FilePath/Nonexistent.jpg" height="120" 
width="120"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 <li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 
150px; height: 150px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" 
src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
 </ul>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1562c6ef7ec70712eb15110b4fec552c57ba4366
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Esanders <[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

Reply via email to