Hey all,

Recently there have been several questions about querying SMW using MediaWiki API modules. The SMWAskAPI [0] extension is a nice proof of concept for the usefullness of this, and also indicates there is an actual demand for it. After discussion with several people, I decided to implement such functionality in SMW itself, and currently have an alpha version. The parameters it takes are slightly different from the SMWAskAPI extension, and the output is not the same.

To try this out, get the latest version of SMW from SVN.

There are 2 API modules that differ in how you specify the query, but have identical output of the query results.

The first one is "ask", which supports one parameter, query, which takes the same string you'd feed into an #ask tag, but urlencoded. Example:
api.php?action=ask&query=[[Modification date::%2B]]|%3FModification date|sort%3DModification date|order%3Ddesc&format=jsonfm

The second one is "askargs", which aims to take arguments in unserialized form, so with as little ask-specific syntax as possible. It supports 3 arguments:
* conditions: The query conditions, ie the requirements for a subject to be included
* printeouts: The query printeouts, ie the properties to show per subject
* parameters: The query parameters, ie all non-condition and non-printeout arguments
Example:
api.php?action=askargs&conditions=Modification date::%2B&printeouts=Modification date&parameters=|sort%3DModification date|order%3Ddesc&format=jsonfm

Feedback is very welcome, so the output structure of the API can be fixed in the next release, after which external developers will be able to actually rely on it :)

[0] https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Extension:SMWAskAPI

Cheers

--
Jeroen De Dauw
http://www.bn2vs.com
Don't panic. Don't be evil.
--