Mholloway has uploaded a new change for review. https://gerrit.wikimedia.org/r/279612
Change subject: Fix loading for irregular Spoken Wikipedia sections ...................................................................... Fix loading for irregular Spoken Wikipedia sections This removes an assumption about the number of audio files present in a Spoken Wikipedia-([2-5]) section that occasionally led to a page load failure. Change-Id: I9df1f8efb6b8f43bee3ff8504b12a21a572e3694 --- M lib/parseProperty.js M test/features/mobile-sections/pagecontent.js 2 files changed, 10 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps refs/changes/12/279612/1 diff --git a/lib/parseProperty.js b/lib/parseProperty.js index e35f85b..3a8e45d 100644 --- a/lib/parseProperty.js +++ b/lib/parseProperty.js @@ -86,7 +86,7 @@ * https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Spoken_Wikipedia/Template_guidelines */ function parseSpokenWikipedia(doc, page) { - var dataMW, parsedData, firstPart, template, target, match, maxKey, key, fileName, + var dataMW, parsedData, firstPart, template, target, match, maxKey, key, fileName, keyLength, spokenSectionDiv = doc.querySelector('div#section_SpokenWikipedia'); if (spokenSectionDiv) { @@ -104,11 +104,11 @@ } else { match = /Spoken Wikipedia-([2-5])/.exec(target.wt); if (match) { - maxKey = 2 + parseInt(match[1]); // multiple audio files: skip first param (recording date) page.spoken = {}; page.spoken.files = []; - for (key = 2; key < maxKey; key++) { + keyLength = Object.keys(template.params).length; + for (key = 2; key <= keyLength; key++) { fileName = 'File:' + template.params[key].wt; page.spoken.files.push(fileName); } diff --git a/test/features/mobile-sections/pagecontent.js b/test/features/mobile-sections/pagecontent.js index 3ad4f5a..8d93214 100644 --- a/test/features/mobile-sections/pagecontent.js +++ b/test/features/mobile-sections/pagecontent.js @@ -125,6 +125,13 @@ var leadSection = res.body.lead.sections[0].text; assert.ok(leadSection.indexOf('redlink') > -1, '"redlink" text exists'); assert.deepEqual(leadSection.indexOf('href'), -1, 'no link in present in output'); + }); + }); + it('Page with irregular Spoken Wikipedia template usage should load correctly', function() { + return preq.get({ uri: server.config.uri + 'en.wikipedia.org/v1/page/mobile-sections/Alliterative_verse' }) + .then(function(res) { + assert.deepEqual(res.status, 200); + assert.deepEqual(res.body.lead.spoken.files[0], 'File:En-Alliterative_verse-article.ogg'); }) }) }); -- To view, visit https://gerrit.wikimedia.org/r/279612 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9df1f8efb6b8f43bee3ff8504b12a21a572e3694 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits