Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/370754 )
Change subject: POC: Send all the links for disambiguation pages in the summary ...................................................................... POC: Send all the links for disambiguation pages in the summary Playing with async functions... :) Bug: T171052 Change-Id: I8272e45b296e7c75adfc82dc0b33b2a9d3ca268b --- M routes/mobile-sections.js 1 file changed, 54 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/54/370754/1 diff --git a/routes/mobile-sections.js b/routes/mobile-sections.js index 9d6684d..625e3ca 100644 --- a/routes/mobile-sections.js +++ b/routes/mobile-sections.js @@ -352,6 +352,32 @@ }); } +/* + * Get disambiguation links for a given page + * @param {!Request} req + * @return {!BBPromise} + */ +function getDisambiguationLinks(req) { + const p = req.params; + const query = { + action: 'query', + titles: p.title, + prop: 'links', + format: 'json', + formatversion: '2' + }; + + return apiUtil.mwApiGet(app, p.domain, query).then((resp) => { + const result = resp.body; + const page = result && result.query && result.query.pages && result.query.pages[0]; + const links = page && page.links; + if (links) { + return links.map((page)=>page.title); + } else { + return []; + } + }); +} /* * Build a summary for the page given in req @@ -360,25 +386,36 @@ * of deprecating. * @return {!BBPromise} */ -function buildSummary(req) { - return buildLeadObject(req, false).then((lead) => { - let summary = {}; - const type = 'standard'; - let code = 200; +async function buildSummary(req) { + const lead = await buildLeadObject(req, false); + let summary = {}; + let disambiguation_links; + let type = 'standard'; + let code = 200; + let d; - if (!lead) { - return false; - } else if (lead.contentmodel || lead.ns !== 0) { - code = 204; - } else if (lead.intro) { - summary = transforms.summarize(lead.intro); + if (!lead) { + return false; + } else if (lead.contentmodel || lead.ns !== 0) { + code = 204; + } else if (lead.intro) { + summary = transforms.summarize(lead.intro); + } + if (lead.disambiguation) { + type = 'disambiguation'; + try { + disambiguation_links = await getDisambiguationLinks(req); + } catch (e) { + console.log(e) + disambiguation_links = []; } - return Object.assign({ - code, - type, - revision: lead.revision - }, summary); - }); + } + return Object.assign({ + code, + disambiguation_links, + type, + revision: lead.revision + }, summary); } /** -- To view, visit https://gerrit.wikimedia.org/r/370754 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8272e45b296e7c75adfc82dc0b33b2a9d3ca268b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits