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

Change subject: Hygiene: extract method for when to return 204
......................................................................

Hygiene: extract method for when to return 204

Change-Id: I97a3464f5f9f1eccef2831f6189fa2c4c450846f
---
M lib/summary.js
1 file changed, 28 insertions(+), 26 deletions(-)


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

diff --git a/lib/summary.js b/lib/summary.js
index 9549204..24a9e4a 100644
--- a/lib/summary.js
+++ b/lib/summary.js
@@ -22,23 +22,6 @@
     };
 }
 
-/**
- * Get the page summary type.
- * @param {!Object} meta page metadata from MW API
- * return {!String} the summary type (one of 'standard', 'disambiguation', or 
'mainpage')
- */
-function getSummaryType(meta) {
-    const isDisambiguationPage = meta.pageprops
-        && {}.hasOwnProperty.call(meta.pageprops, 'disambiguation');
-    if (meta.mainpage) {
-        return 'mainpage';
-    }
-    if (isDisambiguationPage) {
-        return 'disambiguation';
-    }
-    return 'standard';
-}
-
 function buildContentUrls(domain, title, meta) {
     const mobileBaseUrl = meta.mobileHost;
     return {
@@ -70,6 +53,33 @@
     };
 }
 
+/**
+ * @param {!Object} meta page metadata from MW API
+ * return {!boolean} true if a '204: No Content' should be returned, false 
otherwise
+ */
+function shouldReturn204(meta) {
+    return !SUMMARY_NS_WHITELIST.includes(meta.ns)
+        || meta.redirect
+        || meta.contentmodel !== 'wikitext';
+}
+
+/**
+ * Get the page summary type.
+ * @param {!Object} meta page metadata from MW API
+ * return {!String} the summary type (one of 'standard', 'disambiguation', or 
'mainpage')
+ */
+function getSummaryType(meta) {
+    const isDisambiguationPage = meta.pageprops
+        && {}.hasOwnProperty.call(meta.pageprops, 'disambiguation');
+    if (meta.mainpage) {
+        return 'mainpage';
+    }
+    if (isDisambiguationPage) {
+        return 'disambiguation';
+    }
+    return 'standard';
+}
+
 /*
  * Build a page summary
  * @param {!String} domain the request domain
@@ -80,15 +90,7 @@
  * @return {!Object} a summary 2.0 spec-compliant page summary object
  */
 function buildSummary(domain, title, html, revTid, meta) {
-    if (!SUMMARY_NS_WHITELIST.includes(meta.ns)) {
-        return { code: 204 };
-    }
-
-    if (meta.redirect) {
-        return { code: 204 };
-    }
-
-    if (meta.contentmodel !== 'wikitext') {
+    if (shouldReturn204(meta)) {
         return { code: 204 };
     }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I97a3464f5f9f1eccef2831f6189fa2c4c450846f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to