Perl WikiMedia::API

Install

* CPAN WikiMedia::API page
* This module requires the following perl modules

    LWP::UserAgent
    URI::Escape
    JSON
    Encode
    Carp
    and optionally JSON::XS for faster JSON decoding.

* Install

perl -MCPAN -e shell
cpan> install MediaWiki::API

Usage

use strict;
use MediaWiki::API;
 
# Point to your MediaWiki site api.php page
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://mymediawiki.com/api.php';
 
# Login
$mw->login( { lgname => 'me', lgpassword => 'secret' } )
  || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
 
# Edit TestPage
my $pagename = "TestPage";
my $ref = $mw->get_page( { title => $pagename } );
unless ( $ref->{missing} ) {
  my $timestamp = $ref->{timestamp};
  $mw->edit( {
    action => 'edit',
    title => $pagename,
    basetimestamp => $timestamp, # to avoid edit conflicts
    text => $ref->{'*'} . "\nAdditional text 2" } )
    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
}
 
# Retrieve TestPage content
my $page = $mw->get_page( { title => 'TestPage' } );
print $page->{'*'};
This entry was posted in perl. Bookmark the permalink.