jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403575 )
Change subject: Feed: Always use a POTD caption as the featured image description ...................................................................... Feed: Always use a POTD caption as the featured image description Images featured as Picture of the Day on Wikimedia Commons are given a special set of captions that are suited to summarizing the featured work. These are included in a page via the Picture of the Day template, and are formatted in a consistent way in Parsoid HTML. We should use them exclusively rather than as a fallback after attempting to get a file meta- data description via the MediaWiki API. Bug: T184669 Change-Id: I502a2b03109686d6a23c124b814eff92b75bb8c1 --- M lib/feed/featured-image.js M test/features/featured-image/pagecontent.js A test/lib/feed/featured-image-unit.js 3 files changed, 48 insertions(+), 30 deletions(-) Approvals: BearND: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/feed/featured-image.js b/lib/feed/featured-image.js index fd04030..a67fc72 100644 --- a/lib/feed/featured-image.js +++ b/lib/feed/featured-image.js @@ -43,7 +43,7 @@ prop: 'imageinfo|revisions', iiextmetadatafilter: 'ImageDescription', iiextmetadatamultilang: true, - iiprop: 'url|extmetadata|dimensions', + iiprop: 'url|dimensions', iiurlwidth: mwapi.CARD_THUMB_FEATURE_SIZE, rawcontinue: '', titles: `Template:Potd/${isoDate}` @@ -69,11 +69,19 @@ } return page; } - -/** @param {!Object.<string, string>} descriptions Map of languages to descriptions - @param {!string} lang Preferred language - @return {?string} Language */ +/** + * POTD description language from Parsoid HTML, if available. + * @param {?Object} descriptions POTD descriptions via the Picture of the Day template, + * parsed from the page HTML. Requires that the input be an object of the form + * { "en": "foo", "de": "bar" }. + * @param {!String} lang the desired description language + * @return {?String} the description language to use + */ function pickDescriptionLang(descriptions, lang) { + if (!(descriptions && typeof (descriptions) === 'object')) { + return; + } + const fallbackLang = 'en'; if (descriptions[lang]) { @@ -106,22 +114,13 @@ width: imageinfo.width, height: imageinfo.height }; + payload.thumbnail = { source: imageinfo.thumburl, width: imageinfo.thumbwidth, height: imageinfo.thumbheight }; - // extmetadata is an empty array when data is unavailable - if (!imageinfo.extmetadata || Array.isArray(imageinfo.extmetadata)) { - return payload; - } - - const descriptions = imageinfo.extmetadata.ImageDescription.value; - const resolvedLang = descriptions && pickDescriptionLang(descriptions, lang); - if (resolvedLang) { - payload.description = new Description(resolvedLang, descriptions[resolvedLang]); - } return payload; } @@ -188,7 +187,7 @@ // todo: should we just send all langs like parsoid does? const resolvedLang = pickDescriptionLang(descriptions, lang); - if (resolvedLang && (resolvedLang === lang || !ret.payload.description)) { + if (resolvedLang) { ret.payload.description = new Description(resolvedLang, descriptions[resolvedLang]); } return ret; @@ -210,5 +209,8 @@ } module.exports = { - promise + promise, + testing: { + pickDescriptionLang + } }; diff --git a/test/features/featured-image/pagecontent.js b/test/features/featured-image/pagecontent.js index 57264c5..8467d32 100644 --- a/test/features/featured-image/pagecontent.js +++ b/test/features/featured-image/pagecontent.js @@ -32,19 +32,6 @@ }); }); - it('featured image with no extmetadata should have expected properties', () => { - const uri = `${server.config.uri}en.wikipedia.org/v1/media/image/featured/2016/05/06`; - return preq.get({ uri }) - .then((res) => { - assert.status(res, 200); - assert.equal(res.body.title, 'File:Kazakhstan Altay 3.jpg'); - assert.equal(res.body.thumbnail.source, 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Kazakhstan_Altay_3.jpg/640px-Kazakhstan_Altay_3.jpg'); - assert.equal(res.body.image.source, 'https://upload.wikimedia.org/wikipedia/commons/9/99/Kazakhstan_Altay_3.jpg'); - assert.contains(res.body.description.text, 'Altai Mountains'); - assert.equal(res.body.description.lang, 'en'); - }); - }); - it('incomplete date should return 404', () => { const uri = `${server.config.uri}en.wikipedia.org/v1/media/image/featured/2016/04`; return preq.get({ uri }) diff --git a/test/lib/feed/featured-image-unit.js b/test/lib/feed/featured-image-unit.js new file mode 100644 index 0000000..df30b5a --- /dev/null +++ b/test/lib/feed/featured-image-unit.js @@ -0,0 +1,29 @@ +'use strict'; + +const assert = require('../../utils/assert'); +const featuredImage = require('../../../lib/feed/featured-image'); // module under test +const pickDescriptionLang = featuredImage.testing.pickDescriptionLang; + +describe('featured-image-unit', () => { + + it('pickDescriptionLang resolves to lang if present', () => { + const result = pickDescriptionLang({ 'en': 'foo', 'de': 'bar' }, 'de'); + assert.deepEqual(result, 'de'); + }); + + it('pickDescriptionLang falls back to en if lang not present', () => { + const result = pickDescriptionLang({ 'en': 'foo', 'de': 'bar' }, 'ja'); + assert.deepEqual(result, 'en'); + }); + + it('pickDescriptionLang returns undefined for non-object input', () => { + const result = pickDescriptionLang("<span>lol</span>", 'zh'); + assert.deepEqual(result, undefined); + }); + + it('pickDescriptionLang returns undefined for undefined input', () => { + const result = pickDescriptionLang(undefined, 'es'); + assert.deepEqual(result, undefined); + }); + +}); -- To view, visit https://gerrit.wikimedia.org/r/403575 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I502a2b03109686d6a23c124b814eff92b75bb8c1 Gerrit-PatchSet: 13 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@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