Modul:Sort: Unterschied zwischen den Versionen
2018-03-22
(Die Seite wurde neu angelegt: „local Serial = "2016-11-24" --[=[ Sort ]=] local Sort = { } Sort.lex = function ( adjust, apply, adapt ) -- Build ASCII sortkey for text value --…“) |
wp>PerfektesChaos (2018-03-22) |
||
Zeile 1: | Zeile 1: | ||
local | local Sort = { suite = "Sort", | ||
serial = "2018-03-22", | |||
item = 24205172 } | |||
--[=[ | --[=[ | ||
Sort | Sort | ||
]=] | ]=] | ||
Zeile 14: | Zeile 13: | ||
-- Precondition: | -- Precondition: | ||
-- adjust -- string to be aligned | -- adjust -- string to be aligned | ||
-- apply -- string with base | -- apply -- string or table, with base | ||
-- "latin" | -- "latin" | ||
-- adapt -- variation, or false | -- adapt -- string or table, with variation, or false | ||
-- "DIN5007m2" -- DIN 5007 mode "2" | -- "DIN5007m2" -- DIN 5007 mode "2" | ||
local r = adjust | local r = adjust | ||
if adapt or not r:match( "^[ -~]*$" ) then | if adapt or not r:match( "^[ -~]*$" ) then | ||
local storage = "Module: | local storage = string.format( "Module:%s/", Sort.suite ) | ||
local collate, lucky, post, pre | local collate, lucky, post, pre | ||
if apply then | if apply then | ||
Zeile 27: | Zeile 26: | ||
collate = "uni" | collate = "uni" | ||
end | end | ||
lucky, collate = pcall( mw.loadData, storage .. collate ) | if type( collate ) == "string" then | ||
lucky, collate = pcall( mw.loadData, storage .. collate ) | |||
end | |||
if adapt and type( collate ) == "table" then | if adapt and type( collate ) == "table" then | ||
local variants = mw.text.split( adapt, "%s+" ) | local variants = type( adapt ) | ||
local n | |||
if variants == "string" then | |||
variants = mw.text.split( adapt, "%s+" ) | |||
elseif variants == "table" then | |||
variants = adapt | |||
else | |||
variants = { } | |||
end | |||
n = #variants | |||
if n == 1 and variants[ 1 ] == "" then | if n == 1 and variants[ 1 ] == "" then | ||
n = 0 | n = 0 | ||
Zeile 121: | Zeile 130: | ||
else | else | ||
r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate | r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate | ||
end | end | ||
end | end | ||
Zeile 264: | Zeile 271: | ||
return r | return r | ||
end -- Sort.num() | end -- Sort.num() | ||
Sort.failsafe = function ( assert ) | |||
-- Retrieve versioning and check for compliance | |||
-- Precondition: | |||
-- assert -- string, with required version or "wikidata", | |||
-- or false | |||
-- Postcondition: | |||
-- Returns string with appropriate version, or false | |||
local since = assert | |||
local r | |||
if since == "wikidata" then | |||
local item = Sort.item | |||
since = false | |||
if type( item ) == "number" and item > 0 then | |||
local entity = mw.wikibase.getEntity( string.format( "Q%d", | |||
item ) ) | |||
if type( entity ) == "table" then | |||
local vsn = entity:formatPropertyValues( "P348" ) | |||
if type( vsn ) == "table" and | |||
type( vsn.value) == "string" and | |||
vsn.value ~= "" then | |||
r = vsn.value | |||
end | |||
end | |||
end | |||
end | |||
if not r then | |||
if not since or since <= Sort.serial then | |||
r = Sort.serial | |||
else | |||
r = false | |||
end | |||
end | |||
return r | |||
end -- Sort.failsafe() | |||
Zeile 307: | Zeile 351: | ||
p.failsafe = function ( frame ) | |||
return | -- Versioning interface | ||
local s = type( frame ) | |||
local since | |||
if s == "table" then | |||
since = frame.args[ 1 ] | |||
elseif s == "string" then | |||
since = frame | |||
end | |||
if since then | |||
since = mw.text.trim( since ) | |||
if since == "" then | |||
since = false | |||
end | |||
end | |||
return Sort.failsafe( since ) or "" | |||
end -- p.failsafe() | end -- p.failsafe() | ||