MediaWiki-API

From Bjoern Hassler's website
(Redirected from MWAPI)
Jump to: navigation, search
"Mediawiki mirroring and synchronisation"

Mediawiki mirroring and synchronisation - Mirroring - moving - Offline mediawiki (mvs, MWEclipse) - API/Mirroring - Mwlib - OAI - [Edit]

1 The mediawiki API[edit]

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.

2 About the API[edit]

From http://www.mediawiki.org/wiki/API:

MediaWiki at present has three interfaces:

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)

3 MediaWiki::API (perl)[edit]

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.

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.)

3.1 Questions[edit]

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.

4 Links[edit]

Client code: http://www.mediawiki.org/wiki/API:Client_Code

http://cpanratings.perl.org/user/BjoernH

4.1 Java API[edit]

There also is a Java API, see MWEclipse.

4.2 Deki wiki[edit]

Also see comment about Deki wiki on MW Other approaches.

4.3 Organicdesign[edit]

http://organicdesign.co.nz/MediaWiki_automation