Page MenuHomePhabricator

mediawiki.api: Serialize { foo: [1,2] } as "foo=1|2" instead of "foo[]=1&foo[]=2"
Closed, ResolvedPublic

Description

When passing an array to mw.Api as part of the parameters, is it passed unchanged to jQuery.ajax which translates it into the format used when encoding form fields into GET URLs, that is, name[]=value1&name=value2&...

The MediaWiki API does not understands this format; instead, arrays should be joined with a | character.


Version: unspecified
Severity: enhancement
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=10262
https://bugzilla.wikimedia.org/show_bug.cgi?id=64057

Details

Reference
bz64570

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:13 AM
bzimport set Reference to bz64570.
Tgr created this task.Apr 28 2014, 8:34 PM

I could have sworn it already does :o. It really doesn't. Huh.

Hm.. hinging on invalid/wontfix but will leave open for now.

When an mw.Api plugin provides a dedicated interface for a particular property, it should support a plain array as input and do the join('|') for you.

mediawiki.api.watch is an example where this is handled, and that works fine. There is no problem here.

The generic ajax interface in mw.Api (mw.Api.get) has no contract that it does array joining for you. That could be a feature (reclassified this as an enhancement for that reason), but it certainly isn't something you should expect to work. It is documented as taking query string key/value pairs. If anything, it could reject non-string values before passing to $.param, but that seems a bit of an exaggeration for such a minor detail and not in style with how we generally write our interfaces flexibly.

*** This bug has been marked as a duplicate of bug 48903 ***

This isn't a duplicate of bug 48903. That one is about the API accepting &foo[]=1&foo[]=2 as input, this is about the mw.Api Javascript library not generating that when passed an array from Javascript.

(In reply to Brad Jorsch from comment #4)

This isn't a duplicate of bug 48903. That one is about the API accepting
&foo[]=1&foo[]=2 as input, this is about the mw.Api Javascript library not
generating that when passed an array from Javascript.

On further reflection, that bug is titled as "API should accept this" but its comment 0 is more wishy-washy, to the point where it's a duplicate of both this and bug 10262. So let's keep this one open and close the other since this has a clearer focus.

Change 164886 had a related patch set uploaded by Krinkle:
mediawiki.api: Transform arrays with join('|') in query parameters

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

Change 164886 merged by jenkins-bot:
mediawiki.api: Transform arrays with join('|') in query parameters

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