Search code examples
mediawikiwikimediawiki-templatestransclusion

In a MediaWiki page, how do I include a link to both a file and the file's description page


In a MediaWiki page, I want to have a link to both the file and the file's description page. I've seen this done before, but I can't find it now... it looked something like

{{file|MyFileName|pdf|This is my PDF file}}

It ended up with the page showing "This is my PDF file" as a direct link, and a little PDF icon next to it that was actually a link to the description page. This worked with pdf, doc, docx, ppt, pptx, and more, I believe. The prefix at the beginning was always "file" and the 2nd option was where you put the file type.

Of course, I just tried this on my MediaWiki 1.19.0 installation and it doesn't work.

It looks like some kind of template transclusion, and either my configuration is wrong or I don't have the template or my MediaWiki version is too old. I have the File template, though because I can get half of it working like this:

[[:File:MyFileName.pdf|This is my PDF file]]

I even remember seeing a page describing these two formats as the "old" and "new" ways of linking to files, but I can't find that page now either.


Solution

  • To elaborate, the template would probably have a structure like this:

    template:file

    [[Media:{{{1|}}}.{{{2|}}}|{{{3|}}}]]<!--
    -->[[File:{{{2|}}} icon.png|link=File:{{{1|}}}.{{{2|}}}]]
    

    The go ahead and load an icon image for each file type you plan on using. (If the image isn't icon-sized, you'll want to add a width modifier in there as well.) With this template, {{file|MyFileName|pdf|This is my PDF file}} should generate exactly the output you describe: a direct link to MyFileName.pdf called "This is my PDF file", followed by an embedded image File:Pdf icon.png that is also a link to the description page for MyFileName.pdf.