#!/usr/bin/perl -w

use MediaWiki::API;

my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'https://rtime.felk.cvut.cz/rpp/api.php';

chomp($wikiLogin = `git config --get rpp.wikilogin` || die("Set your wiki login with 'git config rpp.wikilogin <login>'\n"));
chomp($wikiPassword = `git config --get rpp.wikipass` || die("Set your wiki password with 'git config rpp.wikipass <password>'\n"));

# log in to the wiki
$mw->login( { lgname => $wikiLogin, lgpassword => $wikiPassword } )
    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

my $filename = $ARGV[0];

my $success = $mw->edit(
    {
	action   => 'upload',
	filename => $filename,
	comment  => "Uploaded by $0",
        file 	 => [$filename],
	ignorewarnings => 1,
    })
    || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

# use Data::Dumper;
# print Dumper($mw->{response}->{_content});

$mw->logout();
