Module:File/doc
This is the documentation page for Module:File
Scope
File title and file information. If the code here grows beyond a border line, this should be converted to an interface and the processing code should be outsourced.
Usage
Note that an error is thrown, if the title can't be constructed (e.g. a title containing invalid characters is supplied) or meta data isn't available (e.g. due to missing file or extraction error). It is your responsibility to catch them; in Lua through pcall()
; from Wikitext as {{#iferror: {{#invoke:File|function|file=File:P%bar]baz.qqq}} | meaningful message}}
.
From Wikitext
Search (Lua error in Module:LangSwitch at line 135: attempt to concatenate a nil value.+F) for @exports
.
- Examples:
{{#invoke:File|extension|file=File:Test.jpg}}
→jpg
{{#invoke:File|width|file=File:Test.jpg}}
→414
{{#invoke:File|size|file=File:Test.jpg}}
→6782
{{#invoke:File|mime|file=File:Test.jpg}}
→image/jpeg
deprecated{{#invoke:File|mimeType|file=File:Test.jpg}}
→image/jpeg
{{#invoke:File|dateWorkCreated|file=File:Ballot-sprite.png}}
→{{#invoke:File|fileExists|file=File:Ballot-sprite.png}}
→{{#invoke:File|fileExists|file=File:DOESNOTEXIST-0a8de8c83.png}}
→{{#invoke:File|fileExistsRelaxed|file=File:Ba[!#llot-sprite.png}}
→
From Lua
<source lang="Lua"> local file = require( 'Module:File' ) local fileObj = file.File( 'File:Test.svg' ) local withoutExtension = fileObj.woExtension() -- withoutExtension is now 'Test'
local exists = fileObj.metadata().exists if exists then
mw.log( fileObj.metadata().width )
end </source>