Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
w>PerfektesChaos (2018-03-16) |
K (14 Versionen von wikivoyage:Modul:Sort importiert) |
||
| (4 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
local Sort = { suite = "Sort", | local Sort = { suite = "Sort", | ||
serial = " | serial = "2019-10-29", | ||
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-29 | |||
local storage = access | |||
local finer = function () | |||
if append then | |||
storage = string.format( "%s/%s", | |||
storage, | |||
append ) | |||
end | |||
end | |||
local fun, lucky, r, suited | |||
if advanced then | |||
fun = require | |||
else | |||
fun = mw.loadData | |||
end | |||
GlobalMod.globalModules = GlobalMod.globalModules or { } | |||
suited = GlobalMod.globalModules[ access ] | |||
if not suited then | |||
finer() | |||
lucky, r = pcall( fun, "Module:" .. storage ) | |||
end | |||
if not lucky then | |||
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 | |||
finer() | |||
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 13: | Zeile 67: | ||
-- 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 collate, post, pre | |||
local collate | |||
if apply then | if apply then | ||
collate = apply | collate = apply | ||
| Zeile 26: | Zeile 79: | ||
collate = "uni" | collate = "uni" | ||
end | end | ||
if type( collate ) == "string" then | |||
collate = foreignModule( Sort.suite, | |||
false, | |||
collate, | |||
Sort.item ) | |||
end | |||
if adapt and type( collate ) == "table" then | if adapt and type( collate ) == "table" then | ||
local variants = type( adapt ) | local variants = type( adapt ) | ||
| Zeile 49: | Zeile 107: | ||
collate = tmp | collate = tmp | ||
for i = 1, n do | for i = 1, n do | ||
tmp = foreignModule( Sort.suite, | |||
false, | |||
variants[ i ], | |||
Sort.item ) | |||
if type( tmp ) == "table" then | if type( tmp ) == "table" then | ||
var = tmp.single | var = tmp.single | ||
| Zeile 80: | Zeile 140: | ||
end -- for k, v | end -- for k, v | ||
end | end | ||
elseif | elseif type( tmp ) == "string" then | ||
collate = | collate = tmp | ||
break -- for i | break -- for i | ||
else | else | ||
collate = | collate = "Invalid table " .. variants[ i ] | ||
break -- for i | break -- for i | ||
end | end | ||
| Zeile 105: | Zeile 165: | ||
s = " " | s = " " | ||
end | end | ||
elseif (k >= | elseif ( k >= 0x0300 and k <= 0x0362 ) or | ||
(k >= | ( k >= 0x1AB0 and k <= 0x1AFF ) or | ||
(k >= | ( k >= 0x1DC0 and k <= 0x1DFF ) or | ||
(k >= | ( k >= 0xFE20 and k <= 0xFE2F ) then | ||
-- COMBINING ... | -- COMBINING ... | ||
s = "" | s = "" | ||
| Zeile 128: | Zeile 188: | ||
else | else | ||
r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate | r = "**ERROR** Sort.lex ** Submodule unavailable " .. collate | ||
end | end | ||
end | end | ||
| Zeile 274: | Zeile 332: | ||
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 351: | ||
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 373: | ||
end | end | ||
return r | return r | ||
end -- | end -- Failsafe.failsafe() | ||
| Zeile 366: | Zeile 432: | ||
end | end | ||
end | end | ||
return | return Failsafe.failsafe( since ) or "" | ||
end -- p.failsafe() | end -- p.failsafe() | ||