volekp | 7 Jun 2012 10:01
Picon
Picon

MW API: Query to list all links on the provided page doesn't return link to files

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
(Continue reading)

Petr Onderka | 7 Jun 2012 11:07
Picon

Re: MW API: Query to list all links on the provided page doesn't return link to files

Hi,

what you're missing is that you don't have a link to the file on your
page, you are including it as an image
(and it doesn't matter that the file is not actually an image).
Because of that, the file won't show with prop=links, but you can see
it with prop=images
(you can get both at the same time by using prop=links|images).

If you actually wanted to link to that file, write [[:File:Test.txt]]
to your page instead.

Also, I think the last link doesn't do what you think it does:
It links to a page named www.google.com on your wiki, it doesn't link to Google.

Petr Onderka
[[en:User:Svick]]

On Thu, Jun 7, 2012 at 10:01 AM, volekp <volekp <at> telesun.imag.fr> wrote:
> 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]]
>
(Continue reading)

Platonides | 7 Jun 2012 18:38
Picon

Re: MW API: Query to list all links on the provided page doesn't return link to files

On 07/06/12 11:07, Petr Onderka wrote:
> Also, I think the last link doesn't do what you think it does:
> It links to a page named www.google.com on your wiki, it doesn't link to Google.
> 
> Petr Onderka
> [[en:User:Svick]]

and if you wanted it to link to google you would write one of these:
http://www.google.com
[http://www.google.com www.google.com]
[http://www.google.com Google]
[http://www.google.com]

It wouldn't be shown in links, either, but as external links.

Gmane