jenkins-bot has submitted this change and it was merged. Change subject: Update thumbnail property in feed endpoint responses ......................................................................
Update thumbnail property in feed endpoint responses The feed will need both small, list-item sized images and larger "hero" images, depending on the card. In particular, 320px images are too small for cards with larger images on larger, higher-res phones. Since a list of four thumb URLs per page item is excessive, I've changed the output format here as follows: Feed endpoints return one (1) thumbnail URL per page/item. This thumbnail is requested from the MW API at the size of the larger of the thumbnail sizes used by the two mobile apps for the type of card in question: 640px for an article feature card, vs. 320px for an article list card. The larger size is requested since it's safe to rewrite a thumb URL downward in size but not necessarily upward. Clients may accept the thumb URL as provided or rewrite the size downward as they see fit. I've also introduced symbols to refer to various image widths in mwapi.js. Bug: T129079 Change-Id: I4ae8e6bbaeb221872b1bc1d07be92f33002ff606 --- M lib/feed/featured.js M lib/feed/most-read.js M lib/mwapi.js M spec.yaml M test/features/featured/pagecontent.js 5 files changed, 22 insertions(+), 28 deletions(-) Approvals: BearND: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/feed/featured.js b/lib/feed/featured.js index 8219335..9831d90 100644 --- a/lib/feed/featured.js +++ b/lib/feed/featured.js @@ -77,9 +77,7 @@ function buildResponse(pageTitle, extractPageObj) { return { title: pageTitle, - thumbnail: extractPageObj.thumbnail - && extractPageObj.thumbnail.source - && mwapi.buildListThumbUrls(extractPageObj.thumbnail.source), + thumbnail: extractPageObj.thumbnail, description: extractPageObj.terms && extractPageObj.terms.description[0], extract: extractPageObj.extract }; diff --git a/lib/feed/most-read.js b/lib/feed/most-read.js index c5973cd..bb644ce 100644 --- a/lib/feed/most-read.js +++ b/lib/feed/most-read.js @@ -75,10 +75,7 @@ description: entry.terms && entry.terms.description && entry.terms.description[0], - thumbnail: entry.thumbnail - && entry.thumbnail.source - ? mwapi.buildListThumbUrls(entry.thumbnail.source) - : undefined, + thumbnail: entry.thumbnail, article: undefined, ns: undefined, terms: undefined, diff --git a/lib/mwapi.js b/lib/mwapi.js index 300d95e..d1588f7 100644 --- a/lib/mwapi.js +++ b/lib/mwapi.js @@ -10,8 +10,16 @@ var HTTPError = sUtil.HTTPError; var API_QUERY_MAX_TITLES = 50; -var DEFAULT_LEAD_IMAGE_WIDTH = 1024; var DEFAULT_THUMB_WIDTH = 320; + +var CARD_THUMB_LIST_ITEM_SIZE = 320; +var CARD_THUMB_FEATURE_SIZE = 640; + +var LEAD_IMAGE_S = 320; +var LEAD_IMAGE_M = 640; +var LEAD_IMAGE_L = 800; +var LEAD_IMAGE_XL = 1024; + var WIDTH_IN_IMAGE_URL_REGEX = /\/(\d+)px-/; @@ -69,7 +77,7 @@ formatversion: 2, page: req.params.title, prop: 'languagecount|thumb|image|id|revision|description|lastmodified|normalizedtitle|displaytitle|protection|editable', - thumbsize: DEFAULT_LEAD_IMAGE_WIDTH + thumbsize: LEAD_IMAGE_XL }; return api.mwApiGet(app, req.params.domain, query) .then(function (response) { @@ -95,7 +103,7 @@ sections: 'all', sectionprop: 'toclevel|line|anchor', noheadings: true, - thumbsize: DEFAULT_LEAD_IMAGE_WIDTH + thumbsize: LEAD_IMAGE_XL }; return api.mwApiGet(app, req.params.domain, query) .then(function (response) { @@ -144,7 +152,7 @@ exsentences: 5, // see T59669 + T117082 explaintext: true, piprop: 'thumbnail', - pithumbsize: 320, + pithumbsize: CARD_THUMB_FEATURE_SIZE, wbptterms: 'description', titles: req.params.title }; @@ -159,7 +167,7 @@ prop: 'pageimages|pageterms', piprop: 'thumbnail', pilimit: API_QUERY_MAX_TITLES, - pithumbsize: DEFAULT_THUMB_WIDTH, + pithumbsize: CARD_THUMB_LIST_ITEM_SIZE, wbptterms: 'description', meta: 'siteinfo', siprop: 'general', @@ -208,21 +216,14 @@ * Builds a set of URLs for lead images with different sizes based on common bucket widths: 320, 640, 800, 1024. */ function buildLeadImageUrls(initialUrl) { - return buildImageUrlSet(initialUrl, [ 320, 640, 800, 1024 ]); -} - -/** - * Builds a set of URLs for small thumbnails suitable for list items. - */ -function buildListThumbUrls(initialUrl) { - return buildImageUrlSet(initialUrl, [ 60, 120, 320 ]); + return buildImageUrlSet(initialUrl, [ LEAD_IMAGE_S, LEAD_IMAGE_M, + LEAD_IMAGE_L, LEAD_IMAGE_XL ]); } module.exports = { getMetadata: getMetadata, getAllSections: getAllSections, buildLeadImageUrls: buildLeadImageUrls, - buildListThumbUrls: buildListThumbUrls, checkForQueryPagesInResponse: checkForQueryPagesInResponse, requestExtract: requestExtract, requestExtractAndDescription: requestExtractAndDescription, diff --git a/spec.yaml b/spec.yaml index 32df958..6244cc2 100644 --- a/spec.yaml +++ b/spec.yaml @@ -101,9 +101,9 @@ description: /.+/ extract: /.+/ thumbnail: - 60: /.+/ - 120: /.+/ - 320: /.+/ + source: /.+/ + width: /.+/ + height: /.+/ # from routes/most-read.js /{domain}/v1/page/most-read/{yyyy}/{mm}/{dd}: get: diff --git a/test/features/featured/pagecontent.js b/test/features/featured/pagecontent.js index 9f2dde8..a81fd27 100644 --- a/test/features/featured/pagecontent.js +++ b/test/features/featured/pagecontent.js @@ -15,16 +15,14 @@ 'application/json'); }); - it('featured article of 4/15/2016 should have title "Cosmic Stories and Stirring Science Stories"', function() { + it('featured article of 4/15/2016 should have expected properties', function() { return preq.get({ uri: server.config.uri + 'en.wikipedia.org/v1/page/featured/2016/04/15' }) .then(function(res) { assert.status(res, 200); // the page id should be stable but not the revision: assert.ok(res.headers.etag.indexOf('50089449/') == 0); assert.equal(res.body.title, 'Cosmic Stories and Stirring Science Stories'); - assert.equal(res.body.thumbnail['60'], 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/60px-Cosmic_Science-Fiction_May_1941.jpg'); - assert.equal(res.body.thumbnail['120'], 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/120px-Cosmic_Science-Fiction_May_1941.jpg'); - assert.equal(res.body.thumbnail['320'], 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Cosmic_Science-Fiction_May_1941.jpg/226px-Cosmic_Science-Fiction_May_1941.jpg'); + assert.equal(res.body.thumbnail.source, 'https://upload.wikimedia.org/wikipedia/commons/1/19/Cosmic_Science-Fiction_May_1941.jpg'); assert.ok(res.body.extract.indexOf('Cosmic Stories ') >= 0); }); }); -- To view, visit https://gerrit.wikimedia.org/r/294399 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4ae8e6bbaeb221872b1bc1d07be92f33002ff606 Gerrit-PatchSet: 9 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: Jhernandez <jhernan...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits