MWM/Getting SpecialExport data with LWP/Get Pages in Category.pl

From Bjoern Hassler's website
Jump to: navigation, search
[ View code | Edit code | Download ]
use MediaWiki::API;

my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://.../api.php';

$mw->{config}->{on_error} = \&on_error;

sub on_error {
    print "Error code: " . $mw->{error}->{code} . "\n";
    print $mw->{error}->{stacktrace}."\n";
    die;
};

# get a list of articles in category                                                                                                                                                                    
my $articles = $mw->list ( {
    action => 'query',
    list => 'categorymembers',
    cmtitle => 'Category:Access2OER',
    cmlimit => 'max' } )
    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

# and print the article titles                                                                                                                                                                          
foreach (@{$articles}) {
    print "$_->{title}\n";
}