Hi, I'm trying to delete the upload file automatically via the Mediawiki::Api->api For the moment, i'm using the code following:
*use strict; use MediaWiki::API; use DateTime::Format::ISO8601; binmode STDERR, ":utf8"; use URI::Escape; use warnings; use MediaWiki::API;
my $url="http://localhost/mediawiki"; my $wiki_login="nguyenki"; my $wiki_passwd="linh"; my $wiki_domain=""; chomp($wiki_login); chomp($wiki_passwd); chomp($wiki_domain); my $mediawiki; mw_connect_maybe();
my $name="Te5.txt"; my $file="/index.php/File:"; my $path= $url.$file.$name; #my $path= $url.$name # the url to the file: http://localhost/mediawiki/index.php/File:Te5.txt print "$path\n";
#delete a file via mediawiki::API->api $mediawiki->edit({ action => 'delete', title => $path, reason => 'no longer nedded' }) || die $mediawiki-> {error}->{code} . ':' . $mediawiki->{error}->{details};
# Methode to login to mediawiki sub mw_connect_maybe {
if ($mediawiki) { return; } $mediawiki = MediaWiki::API->new; $mediawiki->{config}->{api_url} = "$url/api.php";
if ($wiki_login) { if (!$mediawiki->login({ lgname => $wiki_login, lgpassword => $wiki_passwd, lgdomain => $wiki_domain, })) { print STDERR "Failed to log in mediawiki user "$wiki_login" on $url\n"; print STDERR "(error " . $mediawiki->{error}->{code} . ': ' . $mediawiki->{error}->{details} . ")\n"; exit 1; } else { print STDERR "Logged in with user "$wiki_login".\n"; } } }
* But it generated the error:
*5:Unable to delete page 'http://localhost/mediawiki/index.php/File:Te5.txt'. Page does not exist. at delete.pl line 26.*
Maybe the path to the file doesn't exact but i don't know how to correct it. Hope somebody can give me the ideas. Thank.