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

Change subject: Hygiene: remove mobile-text route
......................................................................

Hygiene: remove mobile-text route

This route has been deprecated for a while and will be removed on
May 8, 2017.

Bug: T158128
Change-Id: I7ba009731e807311ff232fe54902bcfb71dd1d7b
---
M README.md
D routes/mobile-text.js
M spec.yaml
D test/features/mobile-text/pagecontent.js
4 files changed, 0 insertions(+), 244 deletions(-)


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

diff --git a/README.md b/README.md
index b7e0ffb..455cbf1 100644
--- a/README.md
+++ b/README.md
@@ -67,9 +67,6 @@
 Example:
 * `http://localhost:6927/en.wikipedia.org/v1/page/mobile-sections/Cat`
 
-There is also a route for the mobile lite app:
-* `http://localhost:6927/{domain}/v1/page/mobile-text/{title}`
-
 And a route for definitions from Wiktionary:
 * `http://localhost:6927/{language 
code}.wiktionary.org/v1/page/definition/{title}`
 
diff --git a/routes/mobile-text.js b/routes/mobile-text.js
deleted file mode 100644
index 109325f..0000000
--- a/routes/mobile-text.js
+++ /dev/null
@@ -1,158 +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 more transformations that currently are being done by the apps
- */
-
-'use strict';
-
-const domino = require('domino');
-const sUtil = require('../lib/util');
-const mUtil = require('../lib/mobile-util');
-const mwapi = require('../lib/mwapi');
-
-
-/**
- * The main router object
- */
-const router = sUtil.router();
-
-/**
- * The main application object reported when this module is require()d
- */
-let app;
-
-
-function rmSelectorAll(doc, selector) {
-    const ps = doc.querySelectorAll(selector) || [];
-    for (let idx = 0; idx < ps.length; idx++) {
-        const node = ps[idx];
-        node.parentNode.removeChild(node);
-    }
-}
-
-function structureThumbnail(thumbDiv) {
-    const thumb = {};
-    const thumbimg = thumbDiv.querySelector("img");
-    if (thumbimg) {
-        thumb.src = thumbimg.getAttribute("src");
-    }
-    const videoDiv = thumbDiv.querySelector("div.PopUpMediaTransform");
-    if (videoDiv && thumbimg) {
-        thumb.type = "video";
-        thumb.name = thumbimg.alt;
-    } else {
-        thumb.type = "image";
-        const alink = thumbDiv.querySelector("a");
-        if (alink) {
-            thumb.name = alink.href;
-        }
-    }
-    const 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) {
-    const doc = domino.createDocument(section.text);
-    rmSelectorAll(doc, 'div.noprint');
-    rmSelectorAll(doc, 'div.infobox');
-    rmSelectorAll(doc, 'div.metadata');
-    rmSelectorAll(doc, 'table');
-
-
-    // and break it down into items...
-    section.items = [];
-    let itemIndex = 0;
-    let thumb;
-    let thumbnails;
-    let tid;
-
-    const hatnotes = doc.querySelectorAll("div.hatnote") || [];
-    for (let hid = 0; hid < hatnotes.length; hid++) {
-        section.items[itemIndex] = {};
-        section.items[itemIndex].type = "hatnote";
-        section.items[itemIndex].text = hatnotes[hid].innerHTML;
-        itemIndex++;
-    }
-
-    const ps = doc.querySelectorAll("p") || [];
-    for (let pid = 0; pid < ps.length; pid++) {
-        const 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', (req, res) => {
-    return mwapi.getAllSections(app, req)
-    // and then return it
-    .then((apiRes) => {
-        // transform all sections
-        const sections = apiRes.body.mobileview.sections;
-        for (let idx = 0; idx < sections.length; idx++) {
-            const section = sections[idx];
-            // run DOM transforms on the section...
-            runDomTransforms(section);
-        }
-
-        res.status(200);
-        mUtil.setETag(res, apiRes.body.mobileview.revision);
-        res.json(apiRes.body.mobileview).end();
-    });
-});
-
-module.exports = function(appObj) {
-    app = appObj;
-    return {
-        path: '/page',
-        api_version: 1,
-        router
-    };
-};
diff --git a/spec.yaml b/spec.yaml
index f27040d..b795f7b 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -650,16 +650,6 @@
         - application/json
       x-monitor: false
 
-  # 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-monitor: false
-
 definitions:
   # A https://tools.ietf.org/html/draft-nottingham-http-problem
   problem:
diff --git a/test/features/mobile-text/pagecontent.js 
b/test/features/mobile-text/pagecontent.js
deleted file mode 100644
index a9bfb35..0000000
--- a/test/features/mobile-text/pagecontent.js
+++ /dev/null
@@ -1,73 +0,0 @@
-'use strict';
-
-const assert = require('../../utils/assert.js');
-const preq   = require('preq');
-const server = require('../../utils/server.js');
-const headers = require('../../utils/headers.js');
-
-describe('mobile-text', function() {
-
-    this.timeout(20000); // eslint-disable-line no-invalid-this
-
-    before(() => { return server.start(); });
-
-    it('should respond to GET request with expected headers, incl. CORS and 
CSP headers', () => {
-        const uri = 
`${server.config.uri}en.wikipedia.org/v1/page/mobile-text/Foobar`;
-        return headers.checkHeaders(uri, 'application/json');
-    });
-    it('should have the right meta fields in the JSON response', () => {
-        return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/page/mobile-text/Foobar` })
-            .then((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', () => {
-        return preq.get({ uri: 
`${server.config.uri}en.wikipedia.org/v1/page/mobile-text/Foobar` })
-            .then((res) => {
-                assert.deepEqual(res.status, 200);
-                assert.notDeepEqual(res.body.sections, undefined);
-                for (let 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', () => {
-        const uri = 
`${server.config.uri}test.wikipedia.org/v1/page/mobile-text/LiteTest`;
-        return preq.get({ uri })
-            .then((res) => {
-                assert.deepEqual(res.status, 200);
-                let numParagraphs = 0;
-                let numImages = 0;
-                let numVideos = 0;
-                for (let i = 0; i < res.body.sections.length; i++) {
-                    const section = res.body.sections[i];
-                    for (let j = 0; j < section.items.length; j++) {
-                        const 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/352299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ba009731e807311ff232fe54902bcfb71dd1d7b
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