Wikipedia:Lua/Modul/Sort/en

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Sort – module with auxilary functions to create sortable keys.

Functions for templates

[Quelltext bearbeiten]
  • The sort functions (Tlatin left only) evaluate the first parameter as term to be sorted.
    • If there is no first parameter provided by #invoke the first parameter of surrounding template transclusion will be used.
  • Optional parameters of #invoke specify input and result format and further capabilities.

Return value is always the sort key.

Alphanumeric terms in latin based scripts are reduced to basic characters of ASCII set.

Optional parameters
v
Variant
Default: ISO (simplify all diacritic characters; ligatures of two letters)
  • Various typografic codes for spaces, horizontal dashes and invisible characters are reduced to ASCII.
  • Multiple whitespace is reduced to single space.

Casing (upcased/downcased) will remain; that can be eliminated easily from result.

The value is 1 if the first string is lexical less than second string else empty.

Mandatory parameters, leading whitespace is significant
1
first string
2
second string

Version management

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 »2024-06-14«
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 → »2024-06-14«
  • 2099-01-01 → »«
wikidata version ID of global upstream
  • version ID at Wikidata
  • local, if not found there
»2024-06-14«
item ID of the Wikidata item
  • empty if not defined
Q24205172
~ 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)

[Quelltext bearbeiten]

A test page illustrates results on input formats.

Date and time

[Quelltext bearbeiten]

That is implemented by the module DateTime.

Functions for Lua modules (API)

[Quelltext bearbeiten]

All functions described above can be used by other modules:

local lucky, Sort = pcall( require, "Module:Sort" )
if type( Sort ) == "table" then
    Sort = Sort()
else
    -- In the event of errors, Sort is an error message.
    return "<span class='error'>" .. Sort .. "</span>"
end
Sort.lex( adjust, apply, adapt )
Similar to Tlatin.
adjust
term (string)
mandatory
apply
base script (string)
  • "latin"
  • "cyrillic"
  • "greek"
  • "uni"
currently latin available only
adapt
variant (string, optional)
  • "DIN5007m2"
Sort.failsafe( atleast )
Versioning interface similar to failsafe
atleast
optional
nil or minimum version or wikidata or ~ for synchronisation
returns: Version ID as string or false

Until 2023 Sort = Sort.Sort() has been recommended for initialization.

Installation on other WMF projects

[Quelltext bearbeiten]

Follow the steps:

  1. Copy main module Module:Sort into your project.
    • If possible keep the name Sort.
    • If another name is required due to conflict or naming convention or non-latin script then choose a different one.
  2. Register this module at d:Q24205172.
  3. Copy desired sub modules, and keep the chosen root name.
  4. Ready.
  5. Consider translation of doc page.
  6. Consider Module:Sort/local adaption to local wiki.

Adaption to local wiki

[Quelltext bearbeiten]

Module:Sort/local, if present, permits local configuration.

simpleDatePattern
pattern for #time: – formatting one particular day
Default: j M Y

General library; no limitations.

Dependencies

[Quelltext bearbeiten]

No other than sub modules.

  • Module:Sort/cyrillic – containing collation table for cyrillic based scripts (Ukrainian etc.).
  • Module:Sort/greek – containing collation table for greek scripts (polytonic).
  • Module:Sort/uni – containing collation table for all (letter based?) script systems.

Internationalisation

[Quelltext bearbeiten]

Not necessary.