Modul:TemplateData: Unterschied zwischen den Versionen
2020-03-01
w>PerfektesChaos (2019-07-02) |
w>PerfektesChaos (2020-03-01) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = " | serial = "2020-03-01", | ||
item = 46997995 } | item = 46997995 } | ||
--[=[ | --[=[ | ||
improve template:TemplateData | improve template:TemplateData | ||
]=] | ]=] | ||
local Failsafe = TemplateData | |||
Zeile 171: | Zeile 172: | ||
TemplateData.extern[ sign ] = r | TemplateData.extern[ sign ] = r | ||
elseif not allow then | elseif not allow then | ||
error( string.format( "Fetch(%s) %s", sign, g ) ) | error( string.format( "Fetch(%s) %s", sign, g ), 0 ) | ||
end | end | ||
end | end | ||
Zeile 1.534: | Zeile 1.535: | ||
if s then | if s then | ||
if Data.leading then | if Data.leading then | ||
r:node( mw.html.create( " | r:node( mw.html.create( "h" .. Config.nested ) | ||
:wikitext( factory( "doc-params" ) ) ) | :wikitext( factory( "doc-params" ) ) ) | ||
:newline() | :newline() | ||
Zeile 1.575: | Zeile 1.576: | ||
local function free() | local function free() | ||
-- Remove JSON comment lines | -- Remove JSON comment lines | ||
Data.source:gsub( "([{,\"'])(%s*\n%s*//.*\n%s*)([},\"'])", | if Data.source:find( "//", 1, true ) then | ||
Data.source:gsub( "([{,\"'])(%s*\n%s*//.*\n%s*)([{},\"'])", | |||
"%1%3" ) | |||
end | |||
end -- free() | end -- free() | ||
Zeile 1.639: | Zeile 1.642: | ||
end | end | ||
end -- for k, v | end -- for k, v | ||
if arglist.heading and arglist.heading:match( "^[3-6]$" ) then | |||
Config.nested = arglist.heading | |||
else | |||
Config.nested = "2" | |||
end | |||
Config.loudly = faculty( arglist.debug or adapt.debug ) | Config.loudly = faculty( arglist.debug or adapt.debug ) | ||
Data.lazy = faculty( arglist.lazy ) and not Config.loudly | Data.lazy = faculty( arglist.lazy ) and not Config.loudly | ||
Zeile 1.698: | Zeile 1.706: | ||
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" | -- atleast -- string, with required version or "wikidata" or "~" | ||
-- or false | -- or false | ||
-- Postcondition: | -- Postcondition: | ||
-- Returns string with | -- Returns string -- with queried version, also if problem | ||
-- false -- if appropriate | |||
local last = ( atleast == "~" ) | |||
local since = 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 1.716: | Zeile 1.726: | ||
local vsn = entity:formatPropertyValues( "P348" ) | local vsn = entity:formatPropertyValues( "P348" ) | ||
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 1.731: | Zeile 1.745: | ||
end | end | ||
return r | return r | ||
end -- | end -- Failsafe.failsafe() | ||
Zeile 1.812: | Zeile 1.826: | ||
end | end | ||
return r | return r | ||
end -- p.f | end -- p.f | ||
p.failsafe = function ( frame ) | p.failsafe = function ( frame ) | ||
Zeile 1.829: | Zeile 1.843: | ||
end | end | ||
end | end | ||
return | return Failsafe.failsafe( since ) or "" | ||
end -- p.failsafe | end -- p.failsafe | ||
p.TemplateData = function () | p.TemplateData = function () |