Module:File/doc: Difference between revisions
From Neodyland Wiki
More actions
m updated documentation |
m →Usage |
||
| (23 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
== Scope == | == 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. | 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.{{Clarify|date=October 2024}} | ||
== Usage == | == Usage == | ||
Note that an error is thrown if the title can't be constructed (e.g. a title containing invalid characters is supplied) or metadata isn't available (e.g. due to missing file or extraction error). It is your responsibility to catch them; in Lua through <code>pcall()</code>; from Wikitext as <code><nowiki>{{#iferror: {{#invoke:File|function|file=File:P%bar]baz.qqq}} | meaningful message}}</nowiki></code>. | |||
=== From Wikitext === | === From Wikitext === | ||
=== | Examples: | ||
< | :<code><nowiki>{{#invoke:File|woExtension|file=File:Test.C.JpeG}}</nowiki></code> → <code>{{#invoke:File|woExtension|file=File:Test.C.JpeG}}</code> | ||
:<code><nowiki>{{#invoke:File|extension|file=File:Test.C.JpeG}}</nowiki></code> → <code>{{#invoke:File|extension|file=File:Test.C.JpeG}}</code> | |||
:<code><nowiki>{{#invoke:File|csExtension|file=File:Test.C.JpeG}}</nowiki></code> → <code>{{#invoke:File|csExtension|file=File:Test.C.JpeG}}</code> | |||
:<code><nowiki>{{#invoke:File|mime|file=File:DOESNOTEXIST-0a8de8c83.Png}}</nowiki></code> → <code>{{#invoke:File|mime|file=File:DOESNOTEXIST-0a8de8c83.Png}}</code> '''deprecated (but works even if the file does not exist and has no metadata)''' | |||
-- | :<code><nowiki>{{#invoke:File|mimeType|file=File:DOESNOTEXIST-0a8de8c83.Png}}</nowiki></code> → <code>{{#invoke:File|mimeType|file=File:DOESNOTEXIST-0a8de8c83.Png}}</code> '''preferred (but will not work if the file does not exist to parse its metadata)''' | ||
:<code><nowiki>{{#invoke:File|fileExists|file=File:Commons-logo.png}}</nowiki></code> → <code>{{#invoke:File|fileExists|file=File:Commons-logo.png}}</code> | |||
:<code><nowiki>{{#invoke:File|fileExists|file=File:DOESNOTEXIST-0a8de8c83.png}}</nowiki></code> → <code>{{#invoke:File|fileExists|file=File:DOESNOTEXIST-0a8de8c83.png}}</code> | |||
:<code><nowiki>{{#invoke:File|fileExistsRelaxed|file=File:Ba[!#llot-sprite.png}}</nowiki></code> → <code>{{#invoke:File|fileExistsRelaxed|file=File:Ba[!#llot-sprite.png}}</code> | |||
:<code><nowiki>{{#invoke:File|width|file=File:Commons-logo.png}}</nowiki></code> → <code>{{#invoke:File|width|file=File:Commons-logo.png}}</code> | |||
:<code><nowiki>{{#invoke:File|height|file=File:Commons-logo.png}}</nowiki></code> → <code>{{#invoke:File|height|file=File:Commons-logo.png}}</code> | |||
:<code><nowiki>{{#invoke:File|dimensions|file=File:Commons-logo.png}}</nowiki></code> → <code>{{#invoke:File|dimensions|file=File:Commons-logo.png}}</code> | |||
:<code><nowiki>{{#invoke:File|size|file=File:Commons-logo.png}}</nowiki></code> → <code>{{#invoke:File|size|file=File:Commons-logo.png}}</code> | |||
<includeonly>[[Category:Modules for general use]]</includeonly> | |||
</ | |||
Latest revision as of 03:02, 26 October 2024
Scope
editFile 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.[Please clarify – October 2024]
Usage
editNote that an error is thrown if the title can't be constructed (e.g. a title containing invalid characters is supplied) or metadata 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
editExamples:
{{#invoke:File|woExtension|file=File:Test.C.JpeG}}→File:Test.C{{#invoke:File|extension|file=File:Test.C.JpeG}}→jpeg{{#invoke:File|csExtension|file=File:Test.C.JpeG}}→JpeG{{#invoke:File|mime|file=File:DOESNOTEXIST-0a8de8c83.Png}}→image/pngdeprecated (but works even if the file does not exist and has no metadata){{#invoke:File|mimeType|file=File:DOESNOTEXIST-0a8de8c83.Png}}→preferred (but will not work if the file does not exist to parse its metadata){{#invoke:File|fileExists|file=File:Commons-logo.png}}→true{{#invoke:File|fileExists|file=File:DOESNOTEXIST-0a8de8c83.png}}→{{#invoke:File|fileExistsRelaxed|file=File:Ba[!#llot-sprite.png}}→
{{#invoke:File|width|file=File:Commons-logo.png}}→114{{#invoke:File|height|file=File:Commons-logo.png}}→153{{#invoke:File|dimensions|file=File:Commons-logo.png}}→114 × 153{{#invoke:File|size|file=File:Commons-logo.png}}→5557