jenkins-bot has submitted this change and it was merged.

Change subject: Expose references in a new endpoint
......................................................................


Expose references in a new endpoint

Bug: T146398
Change-Id: I047a05d5bc4d4386f3b606d2f3aed33ee61cd109
---
M routes/mobile-sections.js
M test/features/mobile-sections/pagecontent.js
2 files changed, 43 insertions(+), 0 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/routes/mobile-sections.js b/routes/mobile-sections.js
index 5cb300f..b86a0ef 100644
--- a/routes/mobile-sections.js
+++ b/routes/mobile-sections.js
@@ -128,6 +128,24 @@
 }
 
 /*
+ * Build a response which contains only reference sections
+ * @param {Object} input
+ * @return {Object}
+ */
+function buildReferences(input) {
+    var remaining = buildRemaining(input);
+    var sections = [];
+    remaining.sections.forEach(function (section) {
+        if (section.isReferenceSection) {
+            sections.push(section);
+        }
+    });
+    return {
+        sections: sections
+    };
+}
+
+/*
  * @param {Object} input
  * @param {Boolean} [removeNodes] whether to remove nodes from the lead text
  * @return {Object}
@@ -221,6 +239,21 @@
     });
 });
 
+/**
+ * GET {domain}/v1/page/mobile-sections-references/{title}/{revision:?}
+ * Gets any sections which are part of a reference sections for a given wiki 
page.
+ */
+router.get('/mobile-sections-references/:title/:revision?', function (req, 
res) {
+    return BBPromise.props({
+        page: parsoid.pageContentPromise(app, req)
+    }).then(function (response) {
+        res.status(200);
+        mUtil.setETag(req, res, response.page.revision);
+        mUtil.setContentType(res, mUtil.CONTENT_TYPES.mobileSections);
+        res.json(buildReferences(response)).end();
+    });
+});
+
 if ( process.env.MOBILE_CONTENT_SERVICE_EDGE_VERSION ) {
     /**
     * GET {domain}/v1/page/formatted/{title}/{revision?}
diff --git a/test/features/mobile-sections/pagecontent.js 
b/test/features/mobile-sections/pagecontent.js
index 374e983..714c96c 100644
--- a/test/features/mobile-sections/pagecontent.js
+++ b/test/features/mobile-sections/pagecontent.js
@@ -177,6 +177,15 @@
                 });
             });
     });
+
+    it('Requesting just references returns only sections with references', 
function() {
+        return preq.get({uri: server.config.uri + 
'en.wikipedia.org/v1/page/mobile-sections-references/Barack_Obama'})
+            .then(function (res) {
+                assert.equal(res.status, 200);
+                assert.equal(res.body.sections.length, 4, 'Barack Obama has 4 
reference sections');
+            });
+    });
+
     it('The last section can be marked as a reference section', function() {
         return preq.get({uri: server.config.uri + 
'en.wikipedia.org/v1/page/mobile-sections/Vallejo_(ferry)'})
             .then(function (res) {
@@ -190,6 +199,7 @@
                 });
             });
     });
+
     it('Page with math formulas should load without error', function() {
         return preq.get({uri: server.config.uri + 
'de.wikipedia.org/v1/page/mobile-sections/Verallgemeinerter_Laplace-Operator'})
             .then(function (res) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I047a05d5bc4d4386f3b606d2f3aed33ee61cd109
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org>
Gerrit-Reviewer: GWicke <gwi...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Jhernandez <jhernan...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to