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?
  • 1yes
isType
Does file name match type expectation 2?
File types 2 are: audio data paged pixel program style vector video as well as file imagefile is appropriate for file namespace and image also as single picture.
  • 1yes
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

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):

Parameter
Value Result current
nothing
false
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.

  • empty, if minimal version not achieved
  • 2001-01-01 → »2025-07-16«
  • 2099-01-01 → »«
wikidata version ID of global upstream
  • version ID at Wikidata
  • local, if not found there
»2025-07-16«
item ID of the Wikidata item
  • empty if not defined
Q24765326
~ Corresponding version ID locally and registered at Wikidata
  • empty, if up to date
  • version ID at Wikidata, if not equal
»«
@ Is the current (module) page linked correctly with Wikidata item?
  • empty, if linked to the item which is supposed
  • Iitem ID, if not
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.

  1. 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:
  2. 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.
  3. 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.
  4. 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.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.