dirty-helpers/wiki-upload

38 lines
915 B
Text
Raw Normal View History

2015-06-27 17:30:17 +02:00
#!/usr/bin/perl
# Upload a file to a recent MediaWiki using the API.
use strict;
use IO::File;
2015-06-27 17:30:17 +02:00
use MediaWiki::API 0.39;
use constant API_URL => 'https://entropia.de/wiki/api.php';
my $wikiuser = $ARGV[0];
my $wikipass = $ARGV[1];
my $file = $ARGV[2];
my $comment = $ARGV[3];
# usage
if (!defined($comment)) {
print "Usage: $0 <wikiuser> <wikipass> <file> <comment>\n";
exit;
}
# log in to the wiki
my $mw = MediaWiki::API->new({api_url => API_URL});
2015-06-27 17:30:17 +02:00
$mw->login( { lgname => $wikiuser, lgpassword => $wikipass } )
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# upload file
my $fh = IO::File->new($file, 'r');
$fh->binmode();
2015-06-27 17:30:17 +02:00
my ($buffer, $data);
while ( read($fh, $buffer, 65536) ) {
2015-06-27 17:30:17 +02:00
$data .= $buffer;
}
close($fh);
2015-06-27 17:30:17 +02:00
$mw->upload( { title => $file,
summary => $comment,
data => $data } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};