jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/404510 )
Change subject: summary: fix mainpage handling ...................................................................... summary: fix mainpage handling The issue was that several non-English main pages are not in the main name space. In those cases we were returning a 204 HTTP code and no content. Change-Id: Ie15487184a7f9fc08603fc42cfad3aeac6642dcc --- M lib/summary.js M test/features/summary/pagecontent.js 2 files changed, 37 insertions(+), 7 deletions(-) Approvals: jenkins-bot: Verified Mholloway: Looks good to me, approved diff --git a/lib/summary.js b/lib/summary.js index 24a9e4a..62c57ce 100644 --- a/lib/summary.js +++ b/lib/summary.js @@ -7,6 +7,7 @@ const NS_MAIN = 0; const SUMMARY_NS_WHITELIST = [ NS_MAIN ]; +const EMPTY_EXTRACTS = { extract: '', extract_html: '' }; /** * Builds a dictionary containing the various forms of a page title that a client may need. @@ -64,7 +65,7 @@ } /** - * Get the page summary type. + * Gets the page summary type. * @param {!Object} meta page metadata from MW API * return {!String} the summary type (one of 'standard', 'disambiguation', or 'mainpage') */ @@ -80,6 +81,26 @@ return 'standard'; } +/** + * Builds the extract values. + * @param {!Document} doc a DOM Document with the page content + * @param {!boolean} isMainPage if the page is a main page + * return {!Object {extract, extract_html} } the extract values + */ +function buildExtracts(doc, isMainPage) { + if (isMainPage) { + return EMPTY_EXTRACTS; + } else { + const leadSectionDoc = parsoidSections.justLeadSection(doc); + const intro = transforms.extractLeadIntroduction(leadSectionDoc); + if (intro.length) { + return transforms.summarize(intro); + } else { + return EMPTY_EXTRACTS; + } + } +} + /* * Build a page summary * @param {!String} domain the request domain @@ -90,18 +111,16 @@ * @return {!Object} a summary 2.0 spec-compliant page summary object */ function buildSummary(domain, title, html, revTid, meta) { - if (shouldReturn204(meta)) { + if (!meta.mainpage && shouldReturn204(meta)) { return { code: 204 }; } const doc = domino.createDocument(html); - const leadSectionDoc = parsoidSections.justLeadSection(doc); - const intro = transforms.extractLeadIntroduction(leadSectionDoc); - const summary = intro.length ? transforms.summarize(intro) : { extract: '', extract_html: '' }; + const extracts = buildExtracts(doc, meta.mainpage); return Object.assign({ code: 200, - type : getSummaryType(meta), + type: getSummaryType(meta), title: meta.normalizedtitle, displaytitle: meta.displaytitle, namespace: { id: meta.ns, text: meta.nsText }, @@ -121,7 +140,7 @@ }, content_urls: buildContentUrls(domain, title, meta), api_urls: buildApiUrls(domain, title, meta), - }, summary); + }, extracts); } module.exports = { diff --git a/test/features/summary/pagecontent.js b/test/features/summary/pagecontent.js index 3ffa217..35933b8 100644 --- a/test/features/summary/pagecontent.js +++ b/test/features/summary/pagecontent.js @@ -57,6 +57,17 @@ }); }); + it('main page in non-mainspace should also return type: \'mainpage\'', () => { + const uri = localUri('Wikipedia:Hauptseite', 'de.wikipedia.org'); + return preq.get({ uri }) + .then((res) => { + assert.deepEqual(res.status, 200); + assert.deepEqual(res.body.type, 'mainpage', 'type should be \'mainpage\''); + assert.deepEqual(res.body.extract, '', 'should send empty plaintext extract'); + assert.deepEqual(res.body.extract_html, '', 'should send empty html extract'); + }); + }); + function should204(uri) { return preq.get({ uri }) .then((res) => { -- To view, visit https://gerrit.wikimedia.org/r/404510 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie15487184a7f9fc08603fc42cfad3aeac6642dcc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Fjalapeno <cfl...@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