Last modified: 2008-02-07 01:58:57 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T14951, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 12951 - format=jsonvar
format=jsonvar
Status: RESOLVED WORKSFORME
Product: MediaWiki
Classification: Unclassified
API (Other open bugs)
unspecified
All All
: Normal enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-07 01:34 UTC by Andrew Dunbar
Modified: 2008-02-07 01:58 UTC (History)
1 user (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Andrew Dunbar 2008-02-07 01:34:19 UTC
Current api.php returns JSON as an anonymous object. This works great when accessing api.php via Ajax.

It does not work for accessing api.php via the <script> tag.

The reason for accessing api.php via the <script> tag is because it is not subject to the same-domain security policy. It would provide a way to access de.wiktionary.org from en.wiktionary.org. This is not possible with Ajax / XmlHttpRequest.

Most people think of the <script> tag as a way to import executable JavaScript code, but it can just as well include data in the form of a variable declaration.

Api.php in its current form is not usable for this since the JavaScript returned via JSON is not a valid JavaScript statement on its own:

{ "query": { "pages": { ... } } } }

But it can be trivially transformed into an independent statement thus:

var wgApiJsonResult = { "query": { "pages": { ... } } } };

Ideally an implementation would take as a parameter the variable name to assign to, but a standard variable name could easily be reused  if this is nontrivial to achieve.
Comment 1 Brion Vibber 2008-02-07 01:44:04 UTC
Isn't the typical way of doing this to specify a json callback function, which I believe is already supported?
Comment 2 Andrew Dunbar 2008-02-07 01:58:57 UTC
Thanks Brion I think that's just what I need. The api.php documentation is so minimal it's easy to miss things.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links