Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
2019-10-29
(2018-09-24) |
(2019-10-29) |
||
Zeile 1: | Zeile 1: | ||
local LuaModuleDoc = { suite = "LuaModuleDoc", | local LuaModuleDoc = { suite = "LuaModuleDoc", | ||
serial = " | serial = "2019-10-29", | ||
item = 12981914, | item = 12981914, | ||
frame = false, | frame = false, | ||
Zeile 15: | Zeile 15: | ||
* failsafe() | * failsafe() | ||
]=] | ]=] | ||
local Failsafe = LuaModuleDoc | |||
Zeile 149: | Zeile 150: | ||
repo.value:find( "//" ) then | repo.value:find( "//" ) then | ||
local t = mw.text.split( repo.value, ",%s+" ) | local t = mw.text.split( repo.value, ",%s+" ) | ||
local params | |||
if #t > 1 then | if #t > 1 then | ||
for i = 1, #t do | for i = 1, #t do | ||
Zeile 183: | Zeile 185: | ||
LuaModuleDoc.title.prefixedText ) | LuaModuleDoc.title.prefixedText ) | ||
local vsn = entity:formatPropertyValues( "P348" ) | local vsn = entity:formatPropertyValues( "P348" ) | ||
params = { } | |||
if mode < 2 then | if mode < 2 then | ||
params[ 1 ] = string.format( "[%s %s]", | params[ 1 ] = string.format( "[%s %s]", | ||
Zeile 194: | Zeile 196: | ||
params.version = vsn.value | params.version = vsn.value | ||
end | end | ||
if type( bib ) == "table" | if type( bib ) == "table" then | ||
local serial | |||
if bib.failsafe then | |||
if type( bib.failsafe ) == "function" then | |||
serial = bib.failsafe( { args = { } } ) | |||
else | |||
serial = bib.failsafe | |||
end | |||
elseif bib[ "#serial"] then | |||
serial = bib[ "#serial"] | |||
end | end | ||
if | if type( serial ) == "number" then | ||
serial = string.format( "%d", serial ) | |||
end | end | ||
if | if type( serial ) == "string" then | ||
params.here = | params.here = serial | ||
end | end | ||
end | end | ||
Zeile 287: | Zeile 291: | ||
end | end | ||
if t then | if t then | ||
r = | r = string.format( "%s:%s", | ||
mw.site.namespaces[ n ].name, s ) | |||
end | end | ||
return r | return r | ||
Zeile 664: | Zeile 669: | ||
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 | ||
-- 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 | ||
local | local entity = mw.wikibase.getEntity( string.format( "Q%d", | ||
item ) ) | |||
if type( | if type( entity ) == "table" then | ||
local vsn = | 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 696: | Zeile 710: | ||
end | end | ||
return r | return r | ||
end -- | end -- Failsafe.failsafe() | ||
Zeile 742: | Zeile 756: | ||
end | end | ||
end | end | ||
return | return Failsafe.failsafe( since ) or "" | ||
end -- p.failsafe() | end -- p.failsafe() | ||
return p | return p |