|
|
@ -2,6 +2,7 @@
|
|
|
|
# Upload a file to a recent MediaWiki using the API.
|
|
|
|
# Upload a file to a recent MediaWiki using the API.
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use IO::File;
|
|
|
|
use MediaWiki::API 0.39;
|
|
|
|
use MediaWiki::API 0.39;
|
|
|
|
|
|
|
|
|
|
|
|
use constant API_URL => 'https://entropia.de/wiki/api.php';
|
|
|
|
use constant API_URL => 'https://entropia.de/wiki/api.php';
|
|
|
@ -18,19 +19,18 @@ if (!defined($comment)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# log in to the wiki
|
|
|
|
# log in to the wiki
|
|
|
|
my $mw = MediaWiki::API->new();
|
|
|
|
my $mw = MediaWiki::API->new({api_url => API_URL});
|
|
|
|
$mw->{config}->{api_url} = API_URL;
|
|
|
|
|
|
|
|
$mw->login( { lgname => $wikiuser, lgpassword => $wikipass } )
|
|
|
|
$mw->login( { lgname => $wikiuser, lgpassword => $wikipass } )
|
|
|
|
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
|
|
|
|
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
|
|
|
|
|
|
|
|
|
|
|
|
# upload file
|
|
|
|
# upload file
|
|
|
|
open FILE, $file or die $!;
|
|
|
|
my $fh = IO::File->new($file, 'r');
|
|
|
|
binmode FILE;
|
|
|
|
$fh->binmode();
|
|
|
|
my ($buffer, $data);
|
|
|
|
my ($buffer, $data);
|
|
|
|
while ( read(FILE, $buffer, 65536) ) {
|
|
|
|
while ( read($fh, $buffer, 65536) ) {
|
|
|
|
$data .= $buffer;
|
|
|
|
$data .= $buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(FILE);
|
|
|
|
close($fh);
|
|
|
|
|
|
|
|
|
|
|
|
$mw->upload( { title => $file,
|
|
|
|
$mw->upload( { title => $file,
|
|
|
|
summary => $comment,
|
|
|
|
summary => $comment,
|
|
|
|