Module:File link/doc

This module is used to construct wikitext links to files. It is primarily useful for templates and modules that use complicated logic to make file links. Simple file links should be made with wikitext markup directly, as it uses less resources than calling this module. For help with wikitext file markup please refer to the documentation at mediawiki.org.

Usage from wikitext
From wikitext, this module should be called from a template, usually file link. Please see the template page for documentation. However, it can also be called using the syntax &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;.

Usage from Lua
First, you need to import the module.

&#x3c;syntaxhighlight lang="lua"&#x3e; local mFileLink = require('Module:File link') &#x3c;/syntaxhighlight&#x3e;

Then you can make file links using the &#x3c;code&#x3e;_main&#x3c;/code&#x3e; function.

&#x3c;syntaxhighlight lang="lua"&#x3e; mFileLink._main(args) &#x3c;/syntaxhighlight&#x3e;

&#x3c;var&#x3e;args&#x3c;/var&#x3e; is a table of arguments that can have the following keys:
 * &#x3c;code&#x3e;file&#x3c;/code&#x3e; - the filename. (required)
 * &#x3c;code&#x3e;format&#x3c;/code&#x3e; - the file format, e.g. 'thumb', 'thumbnail', 'frame', 'framed', or 'frameless'.
 * &#x3c;code&#x3e;formatfile&#x3c;/code&#x3e; - a filename to specify with the 'thumbnail' format option. The filename specified will be used instead of the automatically generated thumbnail.
 * &#x3c;code&#x3e;border&#x3c;/code&#x3e; - set this to true or "yes" (or any other value recognized as true by Module:Yesno) to set a border for the image.
 * &#x3c;code&#x3e;location&#x3c;/code&#x3e; - the horizontal alignment of the file, e.g. 'right', 'left', 'center', or 'none'.
 * &#x3c;code&#x3e;alignment&#x3c;/code&#x3e; - the vertical alignment of the file, e.g. 'baseline', 'middle', 'sub', 'super', 'text-top', 'text-bottom', 'top', or 'bottom'.
 * &#x3c;code&#x3e;size&#x3c;/code&#x3e; - the size of the image, e.g. '100px', 'x100px' or '100x100px'.
 * &#x3c;code&#x3e;upright&#x3c;/code&#x3e; - the 'upright' parameter, used for setting the size of tall and thin images.
 * &#x3c;code&#x3e;link&#x3c;/code&#x3e; - the page that the file should link to. Use the blank string &#x3c;nowiki&#x3e;''&#x3c;/nowiki&#x3e; to suppress the default link to the file description page.
 * &#x3c;code&#x3e;alt&#x3c;/code&#x3e; - the alt text. Use the blank string &#x3c;nowiki&#x3e;''&#x3c;/nowiki&#x3e; to suppress the default alt text.
 * &#x3c;code&#x3e;caption&#x3c;/code&#x3e; - a caption for the file.
 * &#x3c;code&#x3e;page&#x3c;/code&#x3e; - sets a page number for multi-paged files such as PDFs.
 * &#x3c;code&#x3e;class&#x3c;/code&#x3e; - adds a &#x3c;code&#x3e;class&#x3c;/code&#x3e; parameter to image links. The MediaWiki software adds this parameter to the &#x3c;code&#x3e;class="..."&#x3c;/code&#x3e; attribute of the image's &#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;img /&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e; element when the page is rendered into HTML.
 * &#x3c;code&#x3e;lang&#x3c;/code&#x3e; - adds a language attribute to specify what language to render the file in.
 * &#x3c;code&#x3e;start&#x3c;/code&#x3e; - specifies a start time for audio and video files.
 * &#x3c;code&#x3e;end&#x3c;/code&#x3e; - specifies an end time for audio and video files.
 * &#x3c;code&#x3e;thumbtime&#x3c;/code&#x3e; - specifies the time to use to generate the thumbnail image for video files.

To see the effect of each of these parameters, see the images help page on mediawiki.org.

Examples
With the file only: &#x3c;syntaxhighlight lang="lua"&#x3e; mFileLink.main{file = 'Example.png'} -- Renders as &#x3c;/syntaxhighlight&#x3e;

With format, size, link and caption options: &#x3c;syntaxhighlight lang="lua"&#x3e; mFileLink.main{ file = 'Example.png', format = 'thumb', size = '220px', link = 'Wikipedia:Sandbox', caption = 'An example.' } -- Renders as &#x3c;/syntaxhighlight&#x3e;

With format, size, and border: &#x3c;syntaxhighlight lang="lua"&#x3e; mFileLink.main{ file = 'Example.png', format = 'frameless', size = '220px', border = true } -- Renders as &#x3c;/syntaxhighlight&#x3e;

&#x3c;includeonly&#x3e;&#x3c;/includeonly&#x3e;