Wikiup:Lua/Modul/FileMedia/en

aus Wikipedia, der freien Enzyklopädie
< Wikiup:Lua‎ | Modul‎ | FileMedia
Dies ist die aktuelle Version dieser Seite, zuletzt bearbeitet am 10. August 2018 um 10:53 Uhr durch imported>PerfektesChaos(310926) (+).
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
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.

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
Version identification: 2018-07-21
Optional additional parameter 1 – requested minimal version identification, or wikidata
Returns:
  • (empty), if minimal version condition not matched
  • version ID (local or @wikidata: 2018-07-21)

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.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

Module:FileMedia/extensions defines mapping of file extensions to file types.

Usage

General library; no limitations.

Dependencies

None.