chnm / Scripto

Scripto is an open source documentary transcription tool library written in PHP.
34 stars 6 forks source link

Request JSON instead of XML in all Scripto_Service_MediaWiki methods #6

Closed jimsafley closed 13 years ago

jimsafley commented 13 years ago

Loading XML responses into SimpleXMLElement slows things down unnecessarily when a JSON response format is available. JSON would also simplify data traversal.

jimsafley commented 13 years ago

Partially fixed: https://github.com/chnm/Scripto/commit/cfc0df7152c10e36d37c064d239a9cdf577efbe5

getPageWikitext() is not available in JSON format. Its relatively straightforward to switch getPageHtml() to JSON, but the getPreview() JSON syntax is difficult to traverse. Because of this, I decided not to convert these from XML, at least for now.

jimsafley commented 13 years ago

Remember to always decode JSON using json_decode($json, true). The true flag returns an array instead of the default stdClass object. An array is much easier to traverse than an object, particularly when using current() to get the first element of an array.

jimsafley commented 13 years ago

Fixed in several commits.