Wikipedia:Lua/Modul/FileMedia/en
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
FileMedia
– Module with functions for Media files (image pages), adjacent description pages and pages with specific content format.
Functions for templates
[Am Gwëntext werkeln]All functions expect one unnamed parameter with file page (which should be provided to get a meaningful answer). Whitespace ahead and after content is ignored. It might be only the title, a description or media page.
The return value is an empty string (“nothing”), if the parameter value does not fulfil the expectations. If there is a result or the query condition is true, at least one visible character will be returned. The result does not begin or end with a space.
- getExtension
- Retrieve downcased “file name extension” from file name
- nothing – if not recognised
- getHeight
- Retrieve image height
- nothing – if not recognised
- getHeightWidth
- Retrieve image height × width like
123x456px
- nothing – if not recognised
- getMimeType
- Retrieve file MimeType
- nothing – if not recognised
- getPageCount
- Retrieve number of file pages (paged media fragments)
0
– existing, but not paged media- nothing – if not recognised
- getSize
- Retrieve file size
- nothing – if not recognised
- getTitle
- Retrieve file page title from page name, iff it could be a file page with or without namespace.
- nothing – if not recognised
- getType
- Retrieve supposed file type from guessed “file name extension”
- File types are:
audio data paged pixel program style vector video
- nothing – if not recognised
- getWidth
- Retrieve image width
- nothing – if not recognised
- isFile
- Is this a valid (existing) file title or file name, with or without namespace?
1
– yes
- isType
- Does file name match type expectation 2?
- File types 2 are:
audio data paged pixel program style vector video
as well asfile image
–file
is appropriate for file namespace andimage
also as single picture.1
– yes
- setParSize
- Check or set image width (measured on pixel base) as
px
parameter - Positive integers will be completed by
px
. - Also for
x
formats combining image height.- nothing – if not recognised
- failsafe
- Version identification:
2023-01-01
- Optional additional parameter
1
– requested minimal version identification, orwikidata
- Returns:
- (empty), if minimal version condition not matched
- version ID (local or @wikidata:
2023-01-01
)
- Returns:
Examples (test page)
[Am Gwëntext werkeln]A test page illustrates practical use.
Functions for Lua modules (API)
[Am Gwëntext werkeln]All functions described above can be used by other modules per require()
:
local lucky, FileMedia = pcall( require, "Module:FileMedia" )
if type( FileMedia ) == "table" then
FileMedia = FileMedia.FileMedia()
else
-- error case; FileMedia contains message
return "<span class=\"error\">" .. FileMedia .. "</span>"
end
Subsequently there are available:
- FileMedia.getExtension( s )
- FileMedia.getHeight( s )
- FileMedia.getHeightWidth( s )
- FileMedia.getMimeType( s )
- FileMedia.getPageCount( s )
- FileMedia.getPages( s )
- Retrieve table of file page height and width for each page (paged media fragments)
- FileMedia.getTitle( s )
- FileMedia.getType( s )
- FileMedia.getWidth( s )
- FileMedia.isFile( s )
- FileMedia.isSpacing( space )
- Is presumed space name not conflicting with files?
- FileMedia.isType( s, supposed )
- FileMedia.setParSize( s )
If succeeding, the FileMedia.get*() return a string or number, the FileMedia.is*() true
(if no exception mentioned); on failure always false
.
Sub-Module
[Am Gwëntext werkeln]Module:FileMedia/extensions defines mapping of file extensions to file types.
Usage
[Am Gwëntext werkeln]General library; no limitations.
Dependencies
[Am Gwëntext werkeln]None.