Wikia/app — pull request #3838 by hakubo (2014-06-05 23:29:32+00:00)
Title: Hg 5 abstract media from article

Please do not merge - this is a RFC. This is not meant to be merged to dev at that point.

This is a work to abstract media (and eventually more) from plain HTML
to something more structured. So it is easier to work with on app side.
Currently there is support for images and galleries.

The way it works is by hooking in before media is being rendered and instead of HTML for it
it returns a small marker (currently script tag) with an ID that points to media object that is being sent to app as well. With some massaging we could probably make an array of it like:
```js
['content', 'media:id', 'more content', 'media:id']
```
But having a marker inside content gives us enough of flexibility on creating UI.

All this ends up in the parser cache (as a JSON) so we can be sure that if article changes its JSON representation will be updated too. It has it's own parser cache key for this representation as this is totally separate representation of an article. This means that we will have another version of the same article (wikiamobile, oasis, and this), but goal for it is to replace both aforementioned skins and that would actually ~half the memory for cache.
HTML is based on WikiaMobile skin as this already does some things that we desire ie. stripping inline styles, grouping images into galleries.

1. Why script tag?
It is hidden by default, and makes it easy to work with it via DOM API.

2. Is media object sorted?
No, Parser does not work linearly so there is no guarantee that media object is sorted. You can achieve it by looking into article content and grabbing all markers and use this to sort media object.

This is not final shape of the object but this is the direction I am heading.
Example:

```json
{
"payload":
{
"title": "Test",
"article": "

<\/script>\n<\/p>\n

The Church of Light

.... ",
"user":4083617,
"media":[
{
"type":"image",
"url":"http:\/\/static.jolek.wikia-dev.com\/__cb20140513105054\/glee\/images\/b\/b4\/Wikia-Visualization-Main%2Cglee.png",
"fileUrl":"http:\/\/glee.jolek.wikia-dev.com\/wiki\/File:Wikia-Visualization-Main,glee.png","title":"Wikia-Visualization-Main,glee.png",
"caption":"Test 3",
"user":4991249,
"embed":"",
"views":0
}
],
"users":{
"119245": {
"name":"Macbre",
"avatar":"http:\/\/static.jolek.wikia- dev.com\/__cb1392640068\/common\/avatars\/thumb\/f\/fc\/119245.png\/16px-119245.png",
"url":"\/wiki\/User:Macbre"},
"4991249":{
"name":"NeptuNooo",
"avatar":"http:\/\/static.jolek.wikia-dev.com\/__cb1390904033\/common\/avatars\/thumb\/f\/fb\/4991249.png\/16px-4991249.png",
"url":"\/wiki\/User:NeptuNooo"
}
},
"categories":[
{
"title":"Test",
"url":"\/wiki\/Category:Test"
},
{
"title":"Meat",
"url":"\/wiki\/Category:Meat"
}
]
},
"baseUrl":"http:\/\/glee.jolek.wikia-dev.com"
}
```

Please have a look and tell me what do you think.
I am mostly interested if this idea is go or no go.

@federico-lox @michalroszka @kenkouot @aquilax