Hi, i upload the files to the mediawiki using the API. i use the code bellow: use strict; use MediaWiki::API; use DateTime::Format::ISO8601; #use encoding 'utf8'; 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=""; my $mediawiki; mw_connect_maybe(); # configure the special upload location. $mediawiki->{config}->{upload_url} = "$url/index.php/Special:Upload"; * my @extensionFiles = ("png","gif","jpg","jpeg","doc","xls","mpp","pdf","ppt","tiff","bmp","docx", "xlsx", "pptx","ps","odt","ods","odp","odg","txt");* my %hashFiles = map { $_ => 1} @extensionFiles; #Test with a file .png *my $name="somefile.png"; * if(exists($hashFiles{substr($name,-3)}) || exists($hashFiles{substr($name,-4)})) {
# upload a file to MediaWiki open (my $toi, $name) or die "can't open UTF-8 encoded filename: $!"; binmode $toi; my ($buffer, $data); while (my $n=read($toi, $buffer, 65536) ) { $data .= $buffer; print STDERR "$n bytes read\n"; } close($toi);
$mediawiki->upload( { title => $name, summary => 'This is the summary to go on the Image:file.jpg page', data => $data } ) || die $mediawiki->{error}->{code} . ': ' . $mediawiki->{error}->{details};
} else { print "FILE TYPE NOT SUPPORTED\n";
}
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"; } } }
To test the type of file supported, i have to use this variable: * my @extensionFiles = ("png","gif","jpg","jpeg","doc","xls","mpp","pdf","ppt","tiff","bmp","docx", "xlsx", "pptx","ps","odt","ods","odp","odg","txt");
*if the file name *$name* is not in the array, I'll generate a message error. : *print "FILE TYPE NOT SUPPORTED\n"; *My question is if the user change the type of file supported in the * LocalSettings.php* , this programme is not true any more. How can i get the array *$wgFileExtensions* from the *LocalSettings.php*?
Thank. * *