MediaWiki-API
From Bjoern Hassler
Mediawiki mirroring and synchronisation - Mirroring - moving - Offline mediawiki (mvs, MWEclipse) - API/Mirroring - Mwlib - OAI - [Edit]
Contents |
[edit] 1 The mediawiki API
Mediawiki has an API http://www.mediawiki.org/wiki/API.
There are also some enhancements one could do to the API, such as being able to
- request diffs and page hashes. (So that you can build really low bandwidth interfaces, that only request or submit diffs to cached page versions.)
- Get pages in 'gz' format, i.e. change the format options to include 'gz', i.e. xml, xmlfm, xmlgz, json, jsonfm, jsongz, ...
- Handle images and uploads (possible with the perl mediawiki::api, but built in as extra feature not using the api)
- add Special:Export as an export format
From a Mediawiki mirroring and synchronisation point of view, the main issue with the API is that it's not easy to get a list of 'everything that happened since a certain date'. It's of course possible to get this information, but it's not readily available. Many api calls are required to construct the relevant information, see MWAPI/Mirroring. Another approach to this is to use the OAI extension, see Mediawiki/OAI mirror.
[edit] 2 About the API
From http://www.mediawiki.org/wiki/API:
MediaWiki at present has three interfaces:
- MediaWiki API - the new API described on these pages.
- Special:Export feature (bulk export of XML formatted data)
- Regular web-based interface, see http://www.mediawiki.org/wiki/Manual:Parameters_to_index.php
Finding out about the API:
- Short help and parameter guide can be obtained from api.php itself
- Mailing List for notifications and questions: API mailing list
- Low-traffic mailing list for announcements only (all posts to this list are posted to mediawiki-api as well): mediawiki-api-announce
- View and report API bugs: BugZilla (When reporting new bugs, don't forget to set Component=API)
[edit] 3 MediaWiki::API (perl)
MediaWiki::API - Provides a Perl interface to the MediaWiki API (http://www.mediawiki.org/wiki/API), v. 0.24, 13 Jan 2009.
This isn't really an offline/online tool, but it's just a perl interface to the API. However, if you wanted to write an offline/online tool, you could write it in perl, using this API.
- http://search.cpan.org/~exobuzz/MediaWiki-API/
- http://search.cpan.org/dist/MediaWiki-API/lib/MediaWiki/API.pm
- http://search.cpan.org/~exobuzz/MediaWiki-API/lib/MediaWiki/API.pm
- http://annocpan.org/~EXOBUZZ/MediaWiki-API-0.24/lib/MediaWiki/API.pm#2
Installation:
sudo perl -MCPAN -e 'install MediaWiki::API'
Once installed, info via
perldoc MediaWiki::API
It's quite straight forward to use (if you know perl), and the perldoc has got plenty of examples. On OS X, there's FileMerge/opendiff,
opendiff open -a /Developer/Applications/Utilities/FileMerge.app
and one could envisage downloading some text, modifying it, uploading it again. If the upload fails (because of an intermediate revision by somebody else), then opendiff is called, and you can merge the two versions. Cf. also Mvs.
The offline mirror described above uses php/curl to retrieve pages. However, one could rewrite this using MediaWiki::Api in perl, which would make it more flexible, because the API could be leveraged with MediaWiki::Api. (Otherwise one would have to create php bindings for the API from scratch: Making requests, and parsing results.)
[edit] 3.1 Questions
https://rt.cpan.org/Ticket/Display.html?id=44396 This query api.php?action=query&generator=allpages&prop=revisions&rvprop=timestamp|user works (on MW 1.14.0), but
my $articles = $mw->list ( {
action => 'query',
generator => 'allpages' ,
prop => 'revisions',
rvprop => 'timestamp|user',
gaplimit => 'max' })
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
throws this error: "Use of uninitialized value in hash element at .../5.8.8/MediaWiki/API.pm line 543." and returns $articles as empty.
Answer: Use the more general $mw->api call instead.
[edit] 4 Links
Client code: http://www.mediawiki.org/wiki/API:Client_Code
http://cpanratings.perl.org/user/BjoernH
[edit] 4.1 Java API
There also is a Java API, see MWEclipse.
[edit] 4.2 Deki wiki
Also see comment about Deki wiki on MW Other approaches.