jenkins-bot has submitted this change and it was merged. Change subject: Hygiene: Remove mobile-text route ......................................................................
Hygiene: Remove mobile-text route This isn't being actively developed and there are no plans to return to it at present. Let's remove it and revive it later if things change. Change-Id: Ica899e375f26ec24cd5448c32f8bc8c10ef1c47e --- D routes/mobile-text.js M spec.yaml D test/features/mobile-text/pagecontent.js 3 files changed, 0 insertions(+), 250 deletions(-) Approvals: BearND: Looks good to me, approved Dbrant: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/routes/mobile-text.js b/routes/mobile-text.js deleted file mode 100644 index c69afa7..0000000 --- a/routes/mobile-text.js +++ /dev/null @@ -1,161 +0,0 @@ -/** - * mobileapp/lite provides page content for a potential lite Mobile App. - * The goal is to avoid having to use a web view and style the content natively inside the app - * using plain TextViews. - * The payload should not have any extra data, and should be easy to consume by the Lite App. - * - * Status: Prototype -- not ready for production - * Currently using the mobileview action MW API, and removing some data we don't display. - * TODO: Split the "text" objects of each section into paragraph and table objects - * TODO: add some transformations that currently are being done by the apps and remove some more unneeded data - */ - -'use strict'; - -//var BBPromise = require('bluebird'); -var preq = require('preq'); -var domino = require('domino'); -var sUtil = require('../lib/util'); -var mUtil = require('../lib/mobile-util'); -var mwapi = require('../lib/mwapi'); - -// shortcut -var HTTPError = sUtil.HTTPError; - - -/** - * The main router object - */ -var router = sUtil.router(); - -/** - * The main application object reported when this module is require()d - */ -var app; - - -function rmSelectorAll(doc, selector) { - var ps = doc.querySelectorAll(selector) || []; - for (var idx = 0; idx < ps.length; idx++) { - var node = ps[idx]; - node.parentNode.removeChild(node); - } -} - -function structureThumbnail(thumbDiv) { - var thumb = {}; - var thumbimg = thumbDiv.querySelector("img"); - if (thumbimg) { - thumb.src = thumbimg.getAttribute("src"); - } - var videoDiv = thumbDiv.querySelector("div.PopUpMediaTransform"); - if (videoDiv && thumbimg) { - thumb.type = "video"; - thumb.name = thumbimg.alt; - } else { - thumb.type = "image"; - var alink = thumbDiv.querySelector("a"); - if (alink) { - thumb.name = alink.href; - } - } - var caption = thumbDiv.querySelector("div.thumbcaption"); - if (caption) { - thumb.caption = caption.innerHTML; - } - return thumb; -} - -/** - * Nuke stuff from the DOM we don't want. - */ -function runDomTransforms(section) { - var doc = domino.createDocument(section.text); - rmSelectorAll(doc, 'div.noprint'); - rmSelectorAll(doc, 'div.infobox'); - rmSelectorAll(doc, 'div.metadata'); - rmSelectorAll(doc, 'table'); // TODO: later we may want to transform some of the tables into a JSON structure - - - // and break it down into items... - section.items = []; - var itemIndex = 0; - var thumbnails, tid, thumb; - - var hatnotes = doc.querySelectorAll("div.hatnote") || []; - for (var hid = 0; hid < hatnotes.length; hid++) { - section.items[itemIndex] = {}; - section.items[itemIndex].type = "hatnote"; - section.items[itemIndex].text = hatnotes[hid].innerHTML; - itemIndex++; - } - - var ps = doc.querySelectorAll("p") || []; - for (var pid = 0; pid < ps.length; pid++) { - var p = ps[pid]; - - if (p.innerHTML.length < 4) { - continue; - } - - section.items[itemIndex] = {}; - section.items[itemIndex].type = "p"; - section.items[itemIndex].text = p.innerHTML; - itemIndex++; - - // find all images in this paragraph, and append them as section items - thumbnails = p.querySelectorAll("div.thumb") || []; - for (tid = 0; tid < thumbnails.length; tid++) { - thumb = thumbnails[tid]; - section.items[itemIndex] = structureThumbnail(thumb); - itemIndex++; - } - - // remove other inline images from this paragraph - rmSelectorAll(p, 'img'); - // and remove this paragraph from the DOM - p.parentNode.removeChild(p); - } - - - // find all images in this section (outside of paragraphs), and append them as section items - thumbnails = doc.querySelectorAll("div.thumb") || []; - for (tid = 0; tid < thumbnails.length; tid++) { - thumb = thumbnails[tid]; - section.items[itemIndex] = structureThumbnail(thumb); - itemIndex++; - } - - delete section.text; -} - -/** - * GET {domain}/v1/page/mobile-text/{title} - * Gets the lite mobile app version of a given wiki page. - */ -router.get('/mobile-text/:title', function (req, res) { - return mwapi.getAllSections(app, req) - // and then return it - .then(function (apiRes) { - // transform all sections - var sections = apiRes.body.mobileview.sections; - for (var idx = 0; idx < sections.length; idx++) { - var section = sections[idx]; - // run DOM transforms on the section... - runDomTransforms(section); - } - - res.status(200); - mUtil.setETag(req, res, apiRes.body.mobileview.revision); - res.json(apiRes.body.mobileview).end(); - }); -}); - -module.exports = function (appObj) { - app = appObj; - return { - path: '/page', - api_version: 1, - router: router - }; -}; diff --git a/spec.yaml b/spec.yaml index 6e719d1..65a8716 100644 --- a/spec.yaml +++ b/spec.yaml @@ -410,21 +410,3 @@ thumbnail: source: /.+/ infobox: [ /.+/ ] - # from routes/mobile-text.js - /{domain}/v1/page/mobile-text/{title}: - get: - tags: - - Page content - description: Gets the lite mobile app version of a given wiki page - produces: - - application/json - x-amples: - - title: retrieve the lite en.wp main page - request: - params: - title: Main_Page - response: - status: 200 - headers: - content-type: application/json - body: /.+/ diff --git a/test/features/mobile-text/pagecontent.js b/test/features/mobile-text/pagecontent.js deleted file mode 100644 index 6e32ee3..0000000 --- a/test/features/mobile-text/pagecontent.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -var assert = require('../../utils/assert.js'); -var preq = require('preq'); -var server = require('../../utils/server.js'); -var headers = require('../../utils/headers.js'); - -describe('mobile-text', function() { - this.timeout(20000); - - before(function () { return server.start(); }); - - it('should respond to GET request with expected headers, incl. CORS and CSP headers', function() { - return headers.checkHeaders(server.config.uri + 'en.wikipedia.org/v1/page/mobile-text/Foobar', - 'application/json'); - }); - it('should have the right meta fields in the JSON response', function() { - return preq.get({ uri: server.config.uri + 'en.wikipedia.org/v1/page/mobile-text/Foobar' }) - .then(function(res) { - assert.deepEqual(res.status, 200); - assert.notDeepEqual(res.body.lastmodified, undefined); - assert.notDeepEqual(res.body.revision, undefined); - assert.notDeepEqual(res.body.languagecount, undefined); - assert.notDeepEqual(res.body.id, undefined); - assert.notDeepEqual(res.body.protection, undefined); - assert.notDeepEqual(res.body.editable, undefined); - assert.deepEqual(res.body.displaytitle, 'Foobar'); - }); - }); - it('should have the right structure of section objects', function() { - return preq.get({ uri: server.config.uri + 'en.wikipedia.org/v1/page/mobile-text/Foobar' }) - .then(function(res) { - assert.deepEqual(res.status, 200); - assert.notDeepEqual(res.body.sections, undefined); - for (var i = 0; i < res.body.sections.length; i++) { - assert.notDeepEqual(res.body.sections[i].id, undefined); - assert.notDeepEqual(res.body.sections[i].items, undefined); - } - }); - }); - it('should have the right structure of paragraph, image, and video objects', function() { - return preq.get({ uri: server.config.uri + 'test.wikipedia.org/v1/page/mobile-text/LiteTest' }) - .then(function(res) { - assert.deepEqual(res.status, 200); - var numParagraphs = 0; - var numImages = 0; - var numVideos = 0; - for (var i = 0; i < res.body.sections.length; i++) { - var section = res.body.sections[i]; - for (var j = 0; j < section.items.length; j++) { - var item = section.items[j]; - if (item.type === 'p') { - assert.notDeepEqual(item.text, undefined); - numParagraphs++; - } else if (item.type === 'image') { - assert.notDeepEqual(item.src, undefined); - assert.notDeepEqual(item.name, undefined); - numImages++; - } else if (item.type === 'video') { - assert.notDeepEqual(item.src, undefined); - assert.notDeepEqual(item.name, undefined); - numVideos++; - } - } - } - assert.notDeepEqual(numParagraphs, 0); - assert.notDeepEqual(numImages, 0); - assert.notDeepEqual(numVideos, 0); - }); - }); -}); -- To view, visit https://gerrit.wikimedia.org/r/295683 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ica899e375f26ec24cd5448c32f8bc8c10ef1c47e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/mobileapps Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@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: Jhernandez <jhernan...@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