BearND has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/402913 )

Change subject: Hygiene: extract references endpoint into new module
......................................................................

Hygiene: extract references endpoint into new module

Also fixed/clarified some jsdoc there.

Change-Id: Ia64ab51b1e13be8d06fe2e97d668dd620d2b0b2b
---
M lib/references/extractReferenceLists.js
M routes/mobile-sections.js
A routes/references.js
M test/features/featured/pagecontent.js
4 files changed, 53 insertions(+), 26 deletions(-)


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

diff --git a/lib/references/extractReferenceLists.js 
b/lib/references/extractReferenceLists.js
index 0ff37b2..04a8546 100644
--- a/lib/references/extractReferenceLists.js
+++ b/lib/references/extractReferenceLists.js
@@ -4,8 +4,9 @@
 
 /**
  * Scan the DOM document for reference lists
- * @param {!String} document DOM document
+ * @param {!Document} document DOM document
  * @param {!Logger} logger a logger instance associated with the request
+ * @return { structure, references }
  */
 function extractReferenceLists(document, logger) {
     const structure = [];
diff --git a/routes/mobile-sections.js b/routes/mobile-sections.js
index 75fb024..f8ed15a 100644
--- a/routes/mobile-sections.js
+++ b/routes/mobile-sections.js
@@ -156,16 +156,6 @@
 }
 
 /*
- * Build a response which contains a structure of reference sections
- * @param {!Object} input
- * @param {!Logger} logger
- * @return {!Object}
- */
-function buildReferences(html, logger) {
-    return transforms.extractReferenceLists(html, logger);
-}
-
-/*
  * @param {!Object} input
  * @param {?Boolean} [legacy] whether to perform legacy transformations
  * @return {!Object}
@@ -362,20 +352,6 @@
         mUtil.setETag(res, response.page.revision, response.page.tid);
         mUtil.setContentType(res, mUtil.CONTENT_TYPES.mobileSections);
         res.json(buildRemaining(response)).end();
-    });
-});
-
-/**
- * GET {domain}/v1/page/references/{title}{/revision}{/tid}
- * Gets any sections which are part of a reference sections for a given wiki 
page.
- */
-router.get('/references/:title/:revision?/:tid?', (req, res) => {
-    return parsoid.pageHtmlPromiseForReferences(app, req)
-    .then((response) => {
-        res.status(200);
-        mUtil.setETag(res, response.meta.revision);
-        mUtil.setContentType(res, mUtil.CONTENT_TYPES.references);
-        res.json(buildReferences(response.doc, req.logger)).end();
     });
 });
 
diff --git a/routes/references.js b/routes/references.js
new file mode 100644
index 0000000..d4a6d47
--- /dev/null
+++ b/routes/references.js
@@ -0,0 +1,49 @@
+'use strict';
+
+const mUtil = require('../lib/mobile-util');
+const parsoid = require('../lib/parsoid-access');
+const sUtil = require('../lib/util');
+const transforms = require('../lib/transforms');
+
+/**
+ * The main router object
+ */
+const router = sUtil.router();
+
+/**
+ * The main application object reported when this module is require()d
+ */
+let app;
+
+/*
+ * Build a response which contains a structure of reference sections
+ * @param {!Document} document the page content DOM Document
+ * @param {!Logger} logger a Bunyan logger
+ * @return { structure, references } an Object containing structured data of 
references
+ */
+function buildReferences(document, logger) {
+    return transforms.extractReferenceLists(document, logger);
+}
+
+/**
+ * GET {domain}/v1/page/references/{title}{/revision}{/tid}
+ * Gets any sections which are part of a reference sections for a given wiki 
page.
+ */
+router.get('/references/:title/:revision?/:tid?', (req, res) => {
+    return parsoid.pageHtmlPromiseForReferences(app, req)
+    .then((response) => {
+        res.status(200);
+        mUtil.setETag(res, response.meta.revision);
+        mUtil.setContentType(res, mUtil.CONTENT_TYPES.references);
+        res.json(buildReferences(response.doc, req.logger)).end();
+    });
+});
+
+module.exports = function(appObj) {
+    app = appObj;
+    return {
+        path: '/page',
+        api_version: 1,
+        router
+    };
+};
diff --git a/test/features/featured/pagecontent.js 
b/test/features/featured/pagecontent.js
index 17c3fc7..e44233b 100644
--- a/test/features/featured/pagecontent.js
+++ b/test/features/featured/pagecontent.js
@@ -30,7 +30,8 @@
         return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/page/featured/2016/04/15` })
             .then((res) => {
                 assert.status(res, 200);
-                assert.contains(res.body.$merge[0], 
'v1/page/summary/Cosmic_Stories_and_Stirring_Science_Stories');
+                assert.contains(res.body.$merge[0],
+                    
'v1/page/summary/Cosmic_Stories_and_Stirring_Science_Stories');
             });
     });
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia64ab51b1e13be8d06fe2e97d668dd620d2b0b2b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <bsitzm...@wikimedia.org>

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

Reply via email to