jenkins-bot has submitted this change and it was merged.

Change subject: Add 320px thumbnail URL to lead image response
......................................................................


Add 320px thumbnail URL to lead image response

This will save the app needing to make an extra request for a 320px
thumbnail for saved pages/history entries.

Bug: T130090
Change-Id: Ia528cf2595bf8f714e037c9118afa71736f8ef8a
---
M lib/mwapi.js
M test/features/mobile-sections-lead/pagecontent.js
M test/lib/mwapi/image-test.js
3 files changed, 21 insertions(+), 5 deletions(-)

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



diff --git a/lib/mwapi.js b/lib/mwapi.js
index 49a50ff..8f8de19 100644
--- a/lib/mwapi.js
+++ b/lib/mwapi.js
@@ -167,7 +167,7 @@
 }
 
 /**
- * Builds an array of URLs for lead images with different sizes based on 
common bucket widths: 640, 800, 1024.
+ * Builds an array of URLs for lead images with different sizes based on 
common bucket widths: 320, 640, 800, 1024.
  * @param initialUrl the initial URL for an actual lead image (caller already 
checked for undefined)
  *        example URL: 
//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Cat_poster_1.jpg/640px-Cat_poster_1.jpg
  */
@@ -175,8 +175,9 @@
     var match = WIDTH_IN_IMAGE_URL_REGEX.exec(initialUrl);
     if (match) {
         var initialWidth = match[1];
-        if (initialWidth > 640) {
+        if (initialWidth > 320) {
             return {
+                320: scaledImageUrl(initialUrl, initialWidth, 320),
                 640: scaledImageUrl(initialUrl, initialWidth, 640),
                 800: scaledImageUrl(initialUrl, initialWidth, 800),
                 1024: scaledImageUrl(initialUrl, initialWidth, 1024)
@@ -184,8 +185,9 @@
         }
     }
 
-    // can't get a bigger image size than smallest request size of 640 or 
don't know the original size.
+    // can't get a bigger image size than smallest request size of 320 or 
don't know the original size.
     return {
+        320: initialUrl,
         640: initialUrl,
         800: initialUrl,
         1024: initialUrl
diff --git a/test/features/mobile-sections-lead/pagecontent.js 
b/test/features/mobile-sections-lead/pagecontent.js
index 88372b4..2f28d97 100644
--- a/test/features/mobile-sections-lead/pagecontent.js
+++ b/test/features/mobile-sections-lead/pagecontent.js
@@ -51,6 +51,7 @@
                 assert.deepEqual(lead.image, {
                     "file": "Cat poster 1.jpg",
                     "urls": {
+                        "320": 
"//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Cat_poster_1.jpg/320px-Cat_poster_1.jpg",
                         "640": 
"//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Cat_poster_1.jpg/640px-Cat_poster_1.jpg",
                         "800": 
"//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Cat_poster_1.jpg/800px-Cat_poster_1.jpg",
                         "1024": 
"//upload.wikimedia.org/wikipedia/commons/thumb/0/0b/Cat_poster_1.jpg/1024px-Cat_poster_1.jpg"
diff --git a/test/lib/mwapi/image-test.js b/test/lib/mwapi/image-test.js
index d4f1c0d..c8024da 100644
--- a/test/lib/mwapi/image-test.js
+++ b/test/lib/mwapi/image-test.js
@@ -11,6 +11,7 @@
 
     it('buildLeadImageUrls("a") should return all "a"s', function () {
         assert.deepEqual(mwapi._buildLeadImageUrls('a'), {
+                320: 'a',
                 640: 'a',
                 800: 'a',
                 1024: 'a'
@@ -20,6 +21,7 @@
 
     it('buildLeadImageUrls with size 1024px', function () {
         
assert.deepEqual(mwapi._buildLeadImageUrls('//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/1024px-Sun_in_February.jpg'),
 {
+                320: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/320px-Sun_in_February.jpg',
                 640: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/640px-Sun_in_February.jpg',
                 800: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/800px-Sun_in_February.jpg',
                 1024: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/1024px-Sun_in_February.jpg'
@@ -27,8 +29,9 @@
         );
     });
 
-    it('buildLeadImageUrls with size 555px should return size 555', function 
() {
+    it('buildLeadImageUrls with size 555px should return size 320 for 320 and 
then 555 for rest', function () {
         
assert.deepEqual(mwapi._buildLeadImageUrls('//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/555px-Sun_in_February.jpg'),
 {
+                320: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/320px-Sun_in_February.jpg',
                 640: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/555px-Sun_in_February.jpg',
                 800: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/555px-Sun_in_February.jpg',
                 1024: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/555px-Sun_in_February.jpg'
@@ -36,12 +39,22 @@
         );
     });
 
-    it('buildLeadImageUrls with size 750px should return size 640 for 640 and 
then 750 for rest', function () {
+    it('buildLeadImageUrls with size 750px should return size 320, 640, and 
then 750 for rest', function () {
         
assert.deepEqual(mwapi._buildLeadImageUrls('//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/750px-Sun_in_February.jpg'),
 {
+                320: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/320px-Sun_in_February.jpg',
                 640: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/640px-Sun_in_February.jpg',
                 800: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/750px-Sun_in_February.jpg',
                 1024: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/750px-Sun_in_February.jpg'
             }
         );
     });
+    it('buildLeadImageUrls with size 200px should return size 200 for all 
URLs', function () {
+        
assert.deepEqual(mwapi._buildLeadImageUrls('//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/200px-Sun_in_February.jpg'),
 {
+                320: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/200px-Sun_in_February.jpg',
+                640: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/200px-Sun_in_February.jpg',
+                800: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/200px-Sun_in_February.jpg',
+                1024: 
'//upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Sun_in_February.jpg/200px-Sun_in_February.jpg'
+            }
+        );
+    });
 });

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia528cf2595bf8f714e037c9118afa71736f8ef8a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to