Modul:Sort: Unterschied zwischen den Versionen
2019-10-27
K (11 Versionen von w:Modul:Sort importiert) |
(2019-10-27) |
||
| Zeile 1: | Zeile 1: | ||
local Sort = { suite = "Sort", | local Sort = { suite = "Sort", | ||
serial = " | serial = "2019-10-27", | ||
item = 24205172 } | item = 24205172 } | ||
--[=[ | --[=[ | ||
Sort | Sort | ||
]=] | ]=] | ||
local Failsafe = Sort | |||
local GlobalMod = Sort | |||
local foreignModule = function ( access, advanced, append, alt, alert ) | |||
-- Fetch global module | |||
-- Precondition: | |||
-- access -- string, with name of base module | |||
-- advanced -- true, for require(); else mw.loadData() | |||
-- append -- string, with subpage part, if any; or false | |||
-- alt -- number, of wikidata item of root; or false | |||
-- alert -- true, for throwing error on data problem | |||
-- Postcondition: | |||
-- Returns whatever, probably table | |||
-- 2019-10-20 | |||
local storage = access | |||
local fun, lucky, r | |||
if advanced then | |||
fun = require | |||
else | |||
fun = mw.loadData | |||
end | |||
if append then | |||
storage = string.format( "%s/%s", storage, append ) | |||
end | |||
lucky, r = pcall( fun, "Module:" .. storage ) | |||
if not lucky then | |||
local suited | |||
GlobalMod.globalModules = GlobalMod.globalModules or { } | |||
suited = GlobalMod.globalModules[ access ] | |||
if not suited and | |||
type( alt ) == "number" and | |||
alt > 0 then | |||
suited = string.format( "Q%d", alt ) | |||
suited = mw.wikibase.getSitelink( suited ) | |||
GlobalMod.globalModules[ access ] = suited or true | |||
end | |||
if type( suited ) == "string" then | |||
storage = suited | |||
if append then | |||
storage = string.format( "%s/%s", storage, append ) | |||
end | |||
lucky, r = pcall( fun, storage ) | |||
end | |||
if not lucky and alert then | |||
error( "Missing or invalid page: " .. storage, 0 ) | |||
end | |||
end | |||
return r | |||
end -- foreignModule() | |||
| Zeile 20: | Zeile 70: | ||
if adapt or not r:match( "^[ -~]*$" ) then | if adapt or not r:match( "^[ -~]*$" ) then | ||
local storage = string.format( "Module:%s/", Sort.suite ) | local storage = string.format( "Module:%s/", Sort.suite ) | ||
local collate | local collate, post, pre | ||
if apply then | if apply then | ||
collate = apply | collate = apply | ||
| Zeile 27: | Zeile 77: | ||
end | end | ||
if type( collate ) == "string" then | if type( collate ) == "string" then | ||
collate = foreignModule( Sort.suite, | |||
false, | |||
collate, | |||
Sort.item ) | |||
end | end | ||
if adapt and type( collate ) == "table" then | if adapt and type( collate ) == "table" then | ||
| Zeile 274: | Zeile 327: | ||
Failsafe.failsafe = function ( atleast ) | |||
-- Retrieve versioning and check for compliance | -- Retrieve versioning and check for compliance | ||
-- Precondition: | -- Precondition: | ||
-- | -- atleast -- string, with required version or "wikidata" or "~" | ||
-- | -- or false | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string with | -- Returns string -- with queried version, also if problem | ||
local since = | -- false -- if appropriate | ||
-- 2019-10-15 | |||
local last = ( atleast == "~" ) | |||
local since = atleast | |||
local r | local r | ||
if since == "wikidata" then | if last or since == "wikidata" then | ||
local item = | local item = Failsafe.item | ||
since = false | since = false | ||
if type( item ) == "number" and item > 0 then | if type( item ) == "number" and item > 0 then | ||
| Zeile 290: | Zeile 346: | ||
item ) ) | item ) ) | ||
if type( entity ) == "table" then | if type( entity ) == "table" then | ||
local vsn = entity:formatPropertyValues( | local seek = Failsafe.serialProperty or "P348" | ||
local vsn = entity:formatPropertyValues( seek ) | |||
if type( vsn ) == "table" and | if type( vsn ) == "table" and | ||
type( vsn.value) == "string" and | type( vsn.value ) == "string" and | ||
vsn.value ~= "" then | vsn.value ~= "" then | ||
r = vsn.value | if last and vsn.value == Failsafe.serial then | ||
r = false | |||
else | |||
r = vsn.value | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
if | if type( r ) == "nil" then | ||
if not since or since <= | if not since or since <= Failsafe.serial then | ||
r = | r = Failsafe.serial | ||
else | else | ||
r = false | r = false | ||
| Zeile 307: | Zeile 368: | ||
end | end | ||
return r | return r | ||
end -- | end -- Failsafe.failsafe() | ||
| Zeile 366: | Zeile 427: | ||
end | end | ||
end | end | ||
return | return Failsafe.failsafe( since ) or "" | ||
end -- p.failsafe() | end -- p.failsafe() | ||