Page MenuHomePhabricator

API mobileview "protection" sometimes returns object, sometimes returns empty array in JSON output
Closed, ResolvedPublic

Description

A protected page returns an object/map/dictionary/associative array for the 'protection' property:
http://en.wikipedia.org/w/api.php?action=mobileview&page=Barack_Obama&prop=protection|editable&format=json
{"mobileview":{"sections":[],"protection":{"edit":["autoconfirmed"],"move":["sysop"]},"editable":false}}

But an unprotected page seems to return an empty array instead of an object:

http://en.wikipedia.org/w/api.php?action=mobileview&page=Katakana&prop=protection|editable&format=json
{"mobileview":{"sections":[],"protection":[],"editable":true}}

PHP may consider those the same type, but JSON/JavaScript, Java, Objective-C, etc consider them distinct types and we should be consistent in output to avoid surprises in the clients.


Version: unspecified
Severity: normal

Details

Reference
bz67054

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:37 AM
bzimport set Reference to bz67054.
bzimport added a subscriber: Unknown Object (MLST).
brion created this task.Jun 24 2014, 8:42 PM

bingle-admin wrote:

Prioritization and scheduling of this bug is tracked on Trello card https://trello.com/c/B5Hl0VhY

brion added a comment.Jun 24 2014, 8:47 PM

Note I can work around this on the client, it's just a pain. :)

Any suggestions how to do it short of rewriting the API in a saner language? :P

brion added a comment.Jun 24 2014, 8:51 PM

Adding the general bug 10887 as a dep.

Change 141842 had a related patch set uploaded by MaxSem:
Make mobileview always return protection as an object

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

Change 141842 abandoned by MaxSem:
Make mobileview always return protection as an object

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

Not there is a FIXME in PageApi.js for exactly this reason, would be good to remove that in the fix.

Jdlrobson moved this task from Upcoming to Epics/Goals on the Readers-Web-Backlog board.

@MaxSem why was https://gerrit.wikimedia.org/r/#/c/141842/1 abandoned? It seems this could be done conditionally e.g. if xml do this if not do that...

Anomie's ApiResult should make the fixage possible more reasonably once it's merged.

@MaxSem could you add that as a blocking task?

Anomie added a subscriber: Anomie.Apr 15 2015, 9:41 PM

@MaxSem why was https://gerrit.wikimedia.org/r/#/c/141842/1 abandoned? It seems this could be done conditionally e.g. if xml do this if not do that...

API modules shouldn't care which output format is being used unless it's something like opensearch or RSS feeds where a particular format is required by the relevant standard.

The correct solution is to use ApiResult::setArrayType() or $result->addArrayType() (being added in Gerrit change 182858).

It doesn't seem to have a dedicated task, just watch https://gerrit.wikimedia.org/r/#/c/182858/

So I guess this is actionable now?

Jhernandez triaged this task as Normal priority.Aug 18 2015, 4:00 PM
Jhernandez edited projects, added MobileFrontend; removed Readers-Web-Backlog.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 18 2015, 4:00 PM
MaxSem removed a subscriber: MaxSem.Aug 18 2015, 4:55 PM
bearND added a subscriber: bearND.Aug 20 2015, 10:56 PM

I second this request. It would make parsing the protection information much easier for the apps, too. I'm currently implementing Json Parsing or the page content responses using the Gson for Java, and this part was painful enough to warrant a Phab search.
I had to resort to writing a custom deserializer class[1] just for this part, which is a lot of ugly and fragile code on the client side. JSON parsing with Gson should be just writing very simple POJOs.
I'm sure other API users run into the same problem.

[1] https://gerrit.wikimedia.org/r/#/c/232682/4/app/src/main/java/org/wikipedia/page/server/mw/MwPageLead.java L203

kaldari removed a subscriber: kaldari.Aug 21 2015, 8:47 PM

Change 288257 had a related patch set uploaded (by Mholloway):
Make API mobileview return empty 'protection' result as a JSON-style object

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

Change 288257 merged by jenkins-bot:
Make API mobileview return empty 'protection' result as a JSON-style object

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

phuedx closed this task as Resolved.May 12 2016, 9:03 AM
phuedx claimed this task.
phuedx added a subscriber: phuedx.

For example:

curl -k https://en.wikipedia.beta.wmflabs.org/w/api.php?action=mobileview&page=0.007405684603700724&prop=protection|editable&format=json
{"mobileview":{"sections":[],"protection":{},"editable":true}}