LTech
LTech

Reputation: 1761

How to find image path in mediawiki?

I would like find the exact URL for an image in mediawiki to send in my pinterest code. To find the page URL I use urlencode($wgTitle->getFullURL()) but I can't figure out what code to use for image and image description. Thanks

Upvotes: 5

Views: 3455

Answers (3)

Lupina
Lupina

Reputation: 780

You can link to the page /wiki/Special:Filepath/File_name or /wiki/Special:Redirect/file/File_name, that will redirect the request to the full image location, for example: https://en.wikipedia.org/wiki/Special:Filepath/Turtle.jpg redirects to the full image path https://upload.wikimedia.org/wikipedia/commons/6/60/Turtle.jpg

Upvotes: 1

Bergi
Bergi

Reputation: 664237

To get the filepath in a wiki page, you can use [[Special:Filepath]], the {{filepath:...}} parser function or a link to the Media namespace.

To get it programmatically with PHP, you might want to have a look at How does MediaWiki calculate the file path to an image? or the code of the filepath function:

$file = wfFindFile( $filename );
$url = $file->getFullUrl();

(getFullUrl() method in the File class)

For your use case you might also have a look at the Extension:AddThis, they plan to support Pinterest too.

Upvotes: 4

MaxSem
MaxSem

Reputation: 3547

$f = wfFindFile( 'Foo.jpg' );
$imageUrl = $f->getCanonicalUrl(); // http://mywiki.com/images/0/06/Foo.jpg
$descriptionPage = $f->getTitle()->getFullUrl(); // http://mywiki.com/wiki/File.jpg

See the File class and Title class docs for details.

Upvotes: 1

Related Questions