Hi,
I have a problem with MediaWiki API when trying to get links of all
files (images, pdfs, etc ..) which are included in given page. With the
MW API I can get the all other links but no links to media files.
Ex.:
I have a MW with Main Page, which contains following links (all links
are working when click on them):
..
[[File:Test.txt]]
[[Test Page]]
[[www.google.com]]
..
I use Perl interface to MediaWiki API.
Variable $page contents the hash with properties of 'Main Page'.
my $query = {
action => 'query',
prop => 'links',
titles => $page->{title},
pllimit => 50,
};
my $mw_links = $mediawiki->api($query);
but when I write out the content of
$mw_links->{query}->{pages}->{$page->{pageid}}->{links}, I get only the
titles of the two following links:
Test Page
Www.google.com
I don't get the name of the link to File:Test.txt.
I tried to play also with the namespaces (option plnamespace, for ex.
plnamespace = 6,) but it doesn't show the link neither.
I get the same result when I write it directly to the url:
http://localhost/mediawiki/api.php?action=query&prop=links&pllimit=50&title…
Am I missing something?
Thank you for response.
Pavel Volek
Hi,
When deleting a file attachment via the Mediawiki::API->edit, how to get
the revision number at that moment?
For example, when i upload a file, i can find it by the query:
*# Find the number of revision of the page which has the id="$id"*
* my $query = {
action => 'query',
prop => 'revisions',
rvprop => 'ids',
pageids => $id,
};
my $result = $mediawiki->api($query);
..........................................................................
*But, when deleting a file, we can't use this mechanism. I wonder if the
API support a function to get this number of revision?
Thanks.
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.
*
*
Hi,
when enumerating file pages (File:...), I need to specify namespace to
be enumarated so when makeing the query I set "apnamespace=6". But my
question is, whether the id of namespace of media files is always the
same (in every instalation of mediawiki), always "6".
Thanks a lot.
Pavel