[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Hygiene: move news templates to separate file

2016-10-19 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: move news templates to separate file
..


Hygiene: move news templates to separate file

so we can also use it for the tests.

This is a follow-up of a comment in
Iac6c156a242b1cb545ed671338bf525a07e105b4.

Change-Id: I1c3c85f44e914be8e48a179a40609c8ef9ea5289
---
A etc/feed/news-sites.js
M lib/feed/news.js
M test/features/news/news.js
3 files changed, 39 insertions(+), 25 deletions(-)

Approvals:
  Mholloway: Looks good to me, approved
  jenkins-bot: Verified
  Niedzielski: Looks good to me, but someone else must approve



diff --git a/etc/feed/news-sites.js b/etc/feed/news-sites.js
new file mode 100644
index 000..0cc07f9
--- /dev/null
+++ b/etc/feed/news-sites.js
@@ -0,0 +1,32 @@
+/**
+ * A hash map of (Wikipedia site) languages codes to objects with
+ * information to control how to get news items for this particular
+ * Wikipedia site.
+ * The object consists of a title and a selector.
+ * 1) The title is the page title used to scrape the news items from.
+ * 2) The selector is used to find a parent HTML element for  elements.
+ *In most cases simply the first 'ul' suffices but there are exceptions,
+ *often because the first  contains template instructions instead
+ *of the actual news items, or instead of a  Parsoid uses a .
+ */
+const NEWS_TEMPLATES = {
+en: {title: 'Template:In_the_news', selector: 'ul[id^=mw]'},
+
+da: {title: 'Skabelon:Forside_aktuelle_begivenheder', selector: 'div'},
+de: {title: 'Wikipedia:Hauptseite/Aktuelles', selector: 'ul'},
+el: {title: 'Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', selector: 'ul'},
+es: {title: 'Portal:Actualidad', selector: 'ul'},
+fi: {title: 'Malline:Uutisissa', selector: 'ul'},
+fr: {title: 'Modèle:Accueil_actualité', selector: 'ul[id^=mw]'},
+he: {title: 'תבנית:חדשות_ואקטואליה', selector: 'ul'},
+ko: {title: '틀:새로_들어온_소식', selector: 'ul'},
+no: {title: 'Mal:Aktuelt', selector: 'ul'},
+pl: {title: 'Szablon:Aktualności', selector: 'ul:last-of-type'},
+pt: {title: 'Portal:Eventos_atuais', selector: 'ul'},
+ru: {title: 'Шаблон:Актуальные_события', selector: 'ul'},
+sv: {title: 'Portal:Huvudsida/Aktuella händelser', selector: 'ul'},
+vi: {title: 'Bản_mẫu:Tin_tức', selector: 'ul'},
+zh: {title: 'Portal:新聞動態', selector: 'ul'}
+};
+
+module.exports = NEWS_TEMPLATES;
diff --git a/lib/feed/news.js b/lib/feed/news.js
index 55e9c5d..95ac537 100644
--- a/lib/feed/news.js
+++ b/lib/feed/news.js
@@ -7,26 +7,7 @@
 var mwapi = require('../mwapi');
 var parsoid = require('../parsoid-access');
 var HTTPError = require('../util').HTTPError;
-
-var newsTemplates = {
-en: {title: 'Template:In_the_news', selector: 'ul[id^=mw]'},
-
-da: {title: 'Skabelon:Forside_aktuelle_begivenheder', selector: 'div'},
-de: {title: 'Wikipedia:Hauptseite/Aktuelles', selector: 'ul'},
-el: {title: 'Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', selector: 'ul'},
-es: {title: 'Portal:Actualidad', selector: 'ul'},
-fi: {title: 'Malline:Uutisissa', selector: 'ul'},
-fr: {title: 'Modèle:Accueil_actualité', selector: 'ul[id^=mw]'},
-he: {title: 'תבנית:חדשות_ואקטואליה', selector: 'ul'},
-ko: {title: '틀:새로_들어온_소식', selector: 'ul'},
-no: {title: 'Mal:Aktuelt', selector: 'ul'},
-pl: {title: 'Szablon:Aktualności', selector: 'ul:last-of-type'},
-pt: {title: 'Portal:Eventos_atuais', selector: 'ul'},
-ru: {title: 'Шаблон:Актуальные_события', selector: 'ul'},
-sv: {title: 'Portal:Huvudsida/Aktuella händelser', selector: 'ul'},
-vi: {title: 'Bản_mẫu:Tin_tức', selector: 'ul'},
-zh: {title: 'Portal:新聞動態', selector: 'ul'}
-};
+var NEWS_TEMPLATES = require('../../etc/feed/news-sites');
 
 function removeFragment(href) {
 if (href.indexOf('#') > -1) {
@@ -49,7 +30,7 @@
 function promise(app, req) {
 var lang = req.params.domain.split('.')[0];
 var aggregated = !!req.query.aggregated;
-if (!newsTemplates[lang]) {
+if (!NEWS_TEMPLATES[lang]) {
 if (aggregated) {
 return BBPromise.resolve({ payload: undefined, meta: undefined });
 }
@@ -65,14 +46,14 @@
 payload: [],
 meta: {}
 };
-req.params.title = newsTemplates[lang].title;
+req.params.title = NEWS_TEMPLATES[lang].title;
 return parsoid.getParsoidHtml(app, req)
 .then(function (response) {
 result.meta.etag = parsoid.getRevisionFromEtag(response.headers);
 
 var linkTitles = [];
 var doc = domino.createDocument(response.body);
-var newsList = doc.querySelector(newsTemplates[lang].selector);
+var newsList = doc.querySelector(NEWS_TEMPLATES[lang].selector);
 var stories = newsList.getElementsByTagName('li');
 
 for (var j = 0, m = stories.length; j < m; j++) {
diff --git a/test/features/news/news.js b/test/features/news/news.js
index f2478fc..1f13982 

[MediaWiki-commits] [Gerrit] mediawiki...mobileapps[master]: Hygiene: move news templates to separate file

2016-10-18 Thread BearND (Code Review)
BearND has uploaded a new change for review.

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

Change subject: Hygiene: move news templates to separate file
..

Hygiene: move news templates to separate file

so we can also use it for the tests.

This is a follow-up of a comment in
Iac6c156a242b1cb545ed671338bf525a07e105b4.

Change-Id: I1c3c85f44e914be8e48a179a40609c8ef9ea5289
---
A etc/feed/news-sites.js
M lib/feed/news.js
M test/features/news/news.js
3 files changed, 39 insertions(+), 25 deletions(-)


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

diff --git a/etc/feed/news-sites.js b/etc/feed/news-sites.js
new file mode 100644
index 000..0cc07f9
--- /dev/null
+++ b/etc/feed/news-sites.js
@@ -0,0 +1,32 @@
+/**
+ * A hash map of (Wikipedia site) languages codes to objects with
+ * information to control how to get news items for this particular
+ * Wikipedia site.
+ * The object consists of a title and a selector.
+ * 1) The title is the page title used to scrape the news items from.
+ * 2) The selector is used to find a parent HTML element for  elements.
+ *In most cases simply the first 'ul' suffices but there are exceptions,
+ *often because the first  contains template instructions instead
+ *of the actual news items, or instead of a  Parsoid uses a .
+ */
+const NEWS_TEMPLATES = {
+en: {title: 'Template:In_the_news', selector: 'ul[id^=mw]'},
+
+da: {title: 'Skabelon:Forside_aktuelle_begivenheder', selector: 'div'},
+de: {title: 'Wikipedia:Hauptseite/Aktuelles', selector: 'ul'},
+el: {title: 'Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', selector: 'ul'},
+es: {title: 'Portal:Actualidad', selector: 'ul'},
+fi: {title: 'Malline:Uutisissa', selector: 'ul'},
+fr: {title: 'Modèle:Accueil_actualité', selector: 'ul[id^=mw]'},
+he: {title: 'תבנית:חדשות_ואקטואליה', selector: 'ul'},
+ko: {title: '틀:새로_들어온_소식', selector: 'ul'},
+no: {title: 'Mal:Aktuelt', selector: 'ul'},
+pl: {title: 'Szablon:Aktualności', selector: 'ul:last-of-type'},
+pt: {title: 'Portal:Eventos_atuais', selector: 'ul'},
+ru: {title: 'Шаблон:Актуальные_события', selector: 'ul'},
+sv: {title: 'Portal:Huvudsida/Aktuella händelser', selector: 'ul'},
+vi: {title: 'Bản_mẫu:Tin_tức', selector: 'ul'},
+zh: {title: 'Portal:新聞動態', selector: 'ul'}
+};
+
+module.exports = NEWS_TEMPLATES;
diff --git a/lib/feed/news.js b/lib/feed/news.js
index 55e9c5d..95ac537 100644
--- a/lib/feed/news.js
+++ b/lib/feed/news.js
@@ -7,26 +7,7 @@
 var mwapi = require('../mwapi');
 var parsoid = require('../parsoid-access');
 var HTTPError = require('../util').HTTPError;
-
-var newsTemplates = {
-en: {title: 'Template:In_the_news', selector: 'ul[id^=mw]'},
-
-da: {title: 'Skabelon:Forside_aktuelle_begivenheder', selector: 'div'},
-de: {title: 'Wikipedia:Hauptseite/Aktuelles', selector: 'ul'},
-el: {title: 'Πύλη:Τρέχοντα_γεγονότα/Επικεφαλίδες', selector: 'ul'},
-es: {title: 'Portal:Actualidad', selector: 'ul'},
-fi: {title: 'Malline:Uutisissa', selector: 'ul'},
-fr: {title: 'Modèle:Accueil_actualité', selector: 'ul[id^=mw]'},
-he: {title: 'תבנית:חדשות_ואקטואליה', selector: 'ul'},
-ko: {title: '틀:새로_들어온_소식', selector: 'ul'},
-no: {title: 'Mal:Aktuelt', selector: 'ul'},
-pl: {title: 'Szablon:Aktualności', selector: 'ul:last-of-type'},
-pt: {title: 'Portal:Eventos_atuais', selector: 'ul'},
-ru: {title: 'Шаблон:Актуальные_события', selector: 'ul'},
-sv: {title: 'Portal:Huvudsida/Aktuella händelser', selector: 'ul'},
-vi: {title: 'Bản_mẫu:Tin_tức', selector: 'ul'},
-zh: {title: 'Portal:新聞動態', selector: 'ul'}
-};
+var NEWS_TEMPLATES = require('../../etc/feed/news-sites');
 
 function removeFragment(href) {
 if (href.indexOf('#') > -1) {
@@ -49,7 +30,7 @@
 function promise(app, req) {
 var lang = req.params.domain.split('.')[0];
 var aggregated = !!req.query.aggregated;
-if (!newsTemplates[lang]) {
+if (!NEWS_TEMPLATES[lang]) {
 if (aggregated) {
 return BBPromise.resolve({ payload: undefined, meta: undefined });
 }
@@ -65,14 +46,14 @@
 payload: [],
 meta: {}
 };
-req.params.title = newsTemplates[lang].title;
+req.params.title = NEWS_TEMPLATES[lang].title;
 return parsoid.getParsoidHtml(app, req)
 .then(function (response) {
 result.meta.etag = parsoid.getRevisionFromEtag(response.headers);
 
 var linkTitles = [];
 var doc = domino.createDocument(response.body);
-var newsList = doc.querySelector(newsTemplates[lang].selector);
+var newsList = doc.querySelector(NEWS_TEMPLATES[lang].selector);
 var stories = newsList.getElementsByTagName('li');
 
 for (var j = 0, m = stories.length; j < m; j++) {
diff --git a/test/features/news/news.js b/test/features/news/news.js
index f2478fc..1f13982 100644
---