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

Change subject: Hygiene: Update media API calls to use formatversion=2
......................................................................


Hygiene: Update media API calls to use formatversion=2

This allows for easier iteration and simpler code. No functional changes
intended.

Bug: T177430
Change-Id: I06a63b23fc58ad1a15a8da356ad1d303ed30ef87
---
M lib/gallery.js
1 file changed, 31 insertions(+), 51 deletions(-)

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



diff --git a/lib/gallery.js b/lib/gallery.js
index ec6941d..af5ca69 100644
--- a/lib/gallery.js
+++ b/lib/gallery.js
@@ -1,15 +1,9 @@
-/**
- * Common DOM transformations for mobile apps.
- * We rearrange some content and remove content that is not shown/needed.
- */
-
 'use strict';
 
 const BBPromise = require('bluebird');
 const mwapi = require('./mwapi');
 const api = require('./api-util');
 
-// gallery constants:
 const MAX_ITEM_COUNT = 256;
 const MIN_IMAGE_SIZE = 64;
 const MAX_IMAGE_WIDTH = 1280;
@@ -80,13 +74,9 @@
     mwapi.checkForQueryPagesInResponse(req, response);
 
     const output = [];
-    const items = response.body.query.pages;
-    for (const key in items) {
-        if ({}.hasOwnProperty.call(items, key)) {
-            output.push(handleGalleryItems(items[key]));
-        }
-    }
-
+    response.body.query.pages.forEach((item) => {
+        output.push(handleGalleryItems(item));
+    });
     return output;
 }
 
@@ -95,6 +85,7 @@
     Object.assign(params, {
         action: 'query',
         format: 'json',
+        formatversion: 2,
         titles,
         continue: ''
     });
@@ -115,49 +106,37 @@
         return {};
     }
 
-    // iterate over all items
-    const items = response.body.query.pages;
-    for (const key in items) {
-        if ({}.hasOwnProperty.call(items, key)) {
-            const item = items[key];
+    // Reject gallery items if they're too small.
+    // Also reject SVG and PNG items by default, because they're likely to be
+    // logos and/or presentational images.
+    const items = response.body.query.pages.filter((page) => {
+        const imageInfo = page.imageinfo && Array.isArray(page.imageinfo) && 
page.imageinfo[0];
+        return imageInfo
+            && imageInfo.width >= MIN_IMAGE_SIZE
+            && imageInfo.height >= MIN_IMAGE_SIZE
+            && !imageInfo.mime.includes('svg')
+            && !imageInfo.mime.includes('png');
+    });
 
-            if (!(item.imageinfo && Array.isArray(item.imageinfo) && 
item.imageinfo.length)) {
-                continue;
-            }
+    items.forEach((item) => {
+        delete item.ns;
+        delete item.imagerepository; // we probably don't care where the repo 
is
+        delete item.imageinfo[0].size;
+        // TODO: instead of deleting properties we probably want to just add 
well-known
+        // properties
 
-            // remove the ones that are too small or are of the wrong type
-            const imageinfo = item.imageinfo[0];  // TODO: why this is an 
array?
+        const mime = item.imageinfo[0].mime;
+        isVideo = mime.indexOf('ogg') > -1 || mime.indexOf('video') > -1;
 
-            // Reject gallery items if they're too small.
-            // Also reject SVG and PNG items by default, because they're 
likely to be
-            // logos and/or presentational images.
-            if (imageinfo.width < MIN_IMAGE_SIZE
-                || imageinfo.height < MIN_IMAGE_SIZE
-                || imageinfo.mime.indexOf('svg') > -1
-                || imageinfo.mime.indexOf('png') > -1
-            ) {
-                delete items[key];
-            } else {
-                delete item.ns;
-                delete item.imagerepository; // we probably don't care where 
the repo is
-                delete imageinfo.size;
-                // TODO: instead of deleting properties we probably want to 
just add well-known
-                // properties
+        // request details individually, to keep the order
+        // detailsPromises.push(galleryItemsPromise(domain, item.title, 
isVideo));
 
-                const mime = imageinfo.mime;
-                isVideo = mime.indexOf('ogg') > -1 || mime.indexOf('video') > 
-1;
-
-                // request details individually, to keep the order
-                // detailsPromises.push(galleryItemsPromise(domain, 
item.title, isVideo));
-
-                if (isVideo) {
-                    videos.push(item.title);
-                } else {
-                    images.push(item.title);
-                }
-            }
+        if (isVideo) {
+            videos.push(item.title);
+        } else {
+            images.push(item.title);
         }
-    }
+    });
 
     // one more request for all videos
     if (videos.length > 0) {
@@ -185,6 +164,7 @@
     const query = {
         action: 'query',
         format: 'json',
+        formatversion: 2,
         titles: req.params.title,
         continue: '',
         prop: 'imageinfo',

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I06a63b23fc58ad1a15a8da356ad1d303ed30ef87
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org>
Gerrit-Reviewer: Ppchelko <ppche...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to