Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/234682

Change subject: Add pronunciation to lead response
......................................................................

Add pronunciation to lead response

Provide a link to the audio file for the pronunciation of the article
title when available.

Bug: T108371
Change-Id: Ib7bdd26e71b58737982f7458b54f2506297eae27
---
M lib/transforms.js
M routes/mobile-html-sections.js
M spec.yaml
M test/features/mobile-html-sections-lead/pagecontent.js
4 files changed, 37 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/82/234682/1

diff --git a/lib/transforms.js b/lib/transforms.js
index 8aee968..3311096 100644
--- a/lib/transforms.js
+++ b/lib/transforms.js
@@ -54,6 +54,11 @@
     return mUtil.defaultVal(mUtil.filterEmpty(table));
 }
 
+function parsePronunciation(doc) {
+    var anchor = doc.querySelector('span.IPA a[href]');
+    return anchor && { 'url': anchor.href };
+}
+
 function moveFirstParagraphUpInLeadSection(text) {
     var doc = domino.createDocument(text);
     // TODO: mhurd: feel free to add your lead section magic here
@@ -95,6 +100,7 @@
     runDomTransforms: runDomTransforms,
     moveFirstParagraphUpInLeadSection: moveFirstParagraphUpInLeadSection,
     parseInfobox: parseInfobox,
+    parsePronunciation: parsePronunciation,
 
     // visible for testing only:
     _rmBracketSpans: rmBracketSpans
diff --git a/routes/mobile-html-sections.js b/routes/mobile-html-sections.js
index 00f501e..e0f8ebe 100644
--- a/routes/mobile-html-sections.js
+++ b/routes/mobile-html-sections.js
@@ -98,6 +98,7 @@
         })),
         media: input.media,
         infobox: transforms.parseInfobox(lead),
+        pronunciation: transforms.parsePronunciation(lead),
         sections: buildLeadSections(input.page.sections)
     };
 }
diff --git a/spec.yaml b/spec.yaml
index 8d56234..d2f88c6 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -132,6 +132,28 @@
                 items: [ /.+/ ]
               infobox: [ [ /.+/ ] ]
               sections: [ /.+/ ]
+        - title: retrieve lead section of en.wp Barack Obama page via 
mobile-html-sections-lead
+          request:
+            params:
+              title: Barack_Obama
+          response:
+            status: 200
+            headers:
+              content-type: application/json
+            body:
+              id: /.+/
+              revision: /.+/
+              lastmodified: /.+/
+              displaytitle: /.+/
+              protection: /.+/
+              editable: /.+/
+              languagecount: /.+/
+              media:
+                items: [ /.+/ ]
+              infobox: [ [ /.+/ ] ]
+              pronunciation:
+                url: /.+/
+              sections: [ /.+/ ]
   /{domain}/v1/page/mobile-html-sections-remaining/{title}:
     get:
       tags:
diff --git a/test/features/mobile-html-sections-lead/pagecontent.js 
b/test/features/mobile-html-sections-lead/pagecontent.js
index b66548f..876ef73 100644
--- a/test/features/mobile-html-sections-lead/pagecontent.js
+++ b/test/features/mobile-html-sections-lead/pagecontent.js
@@ -78,6 +78,14 @@
                 assert.ok(lead.media.items.length > 3, 'Expected many media 
items');
             });
     });
+    it('Barack Obama should have a pronunciation', function() {
+        return preq.get({ uri: server.config.uri + 
'en.wikipedia.org/v1/page/mobile-html-sections-lead/Barack_Obama' })
+            .then(function(res) {
+                var lead = res.body;
+                assert.deepEqual(res.status, 200);
+                assert.deepEqual(lead.pronunciation.url, 
'/wiki/File:En-us-Barack-Hussein-Obama.ogg');
+            });
+    });
     it('en Main page should have at least one image', function() {
         return preq.get({ uri: server.config.uri + 
'en.wikipedia.org/v1/page/mobile-html-sections-lead/Main_Page' })
             .then(function(res) {

-- 
To view, visit https://gerrit.wikimedia.org/r/234682
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7bdd26e71b58737982f7458b54f2506297eae27
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to