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

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
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