Wikipedia:Lua/Modul/FileMedia/en
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
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.
- getBasePage
- Retrieve existing file name without “extension” from file name
- 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 videoas well asfile image–fileis appropriate for file namespace andimagealso as single picture.1– yes
- setParSize
- Check or set image width (measured on pixel base) as
pxparameter - Positive integers will be completed by
px. - Also for
xformats combining image height.- nothing – if not recognised
- failsafe
The Failsafe interface is heading for version management of globally distributed Lua modules. It enables modules equipped with this interface to
- ensure, that a library module required by a template or another module available as local copy does support certain functionality, or complain if not.
- administrate global updating and linking of module codes via Wikidata.
The Failsafe interface is present both at template level and for direct Lua access.
The functions in detail are (not all supported yet completely by every library):
| Value | Result | current |
|---|---|---|
nothingfalse
|
local version ID | »2025-07-16« |
| Minimal version | version ID required at least date in ISO format It will be compared whether the current local implementation matches this version or later.
|
|
wikidata
|
version ID of global upstream
|
»2025-07-16« |
item
|
ID of the Wikidata item
|
Q24765326
|
~
|
Corresponding version ID locally and registered at Wikidata
|
»« |
@
|
Is the current (module) page linked correctly with Wikidata item?
|
|
The return value is in template programming empty or under Lua false, otherwis a non-empty string as described.
| ||
Examples (test page)
A test page illustrates practical use.
Functions for Lua modules (API)
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()
else
-- error case; FileMedia contains message
return "<span class=\"error\">" .. FileMedia .. "</span>"
end
Subsequently there are available:
- FileMedia.getBasePage( s )
- 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
commons:Data:FileMediaExt.tab defines mapping of file extensions to file types.
Usage
General library; no limitations.
Dependencies
None.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.