Wikipedia:Lua/Modul/Sort/en

Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation
Weiterleitung der Diskussionsseite fehlt

Sort – module with auxilary functions to create sortable keys.

Functions for templates Werkeln

  • All functions 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.

Tlatin Werkeln

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.

failsafe Werkeln

Purpose
Version ID (local): 2019-10-29
Optional parameter:
  • 1 – Minimum version or wikidata
{{#invoke:Sort|failsafe}} yields 2019-10-29
With a parameter as ISO date it is compared whether the current module satisfies this version or later.
  • {{#invoke:Sort|failsafe|2001-01-01}} returns: »2019-10-29«
  • {{#invoke:Sort|failsafe|2099-01-01}} returns: »« – (empty), if minimal version condition not matched
  • If keyword is wikidata, result is version ID registered on Wikidata (2024-01-01) or local if not found there.
  • If keyword is ~, result is empty if local and Wikidata version are the same: (2024-01-01).
Returns:
  • Empty, if minimal version condition not matched, or ~ and local version is synchronized.
  • Version ID if no parameter, or if wikidata, or local if not found there, or not synchronized.

Examples (test page) Werkeln

A test page illustrates results on input formats.

Date and time Werkeln

That is implemented by the module DateTime.

Functions for Lua modules (API) Werkeln

All functions described above can be used by other modules:

local lucky, Sort = pcall( require, "Module:Sort" )
if type( Sort ) == "table" then
    Sort = 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

Installation on other WMF projects Werkeln

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.

General library; no limitations.

Dependencies Werkeln

No other than sub modules.

Sub modules Werkeln

Envisioned Werkeln

  • 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 Werkeln

Not necessary.