Modul:Failsafe: Unterschied zwischen den Versionen
K (vereinfacht) |
K (Datum) |
||
Zeile 2: | Zeile 2: | ||
local Failsafe = { | local Failsafe = { | ||
suite = 'Failsafe', | suite = 'Failsafe', | ||
serial = '2019-07- | serial = '2019-07-14', | ||
item = 65306115 | item = 65306115 | ||
} | } |
Version vom 14. Juli 2019, 05:26 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Failsafe/doc erstellt werden
-- module interface local Failsafe = { suite = 'Failsafe', serial = '2019-07-14', item = 65306115 } -- modul variable local fs = {} -- possible vaules of version -- nil, false: no version required -- string: string of version required -- table: frame table (template, #invoke) -- moduleInterface -- table function fs._failsafe( version, moduleInterface ) if type( moduleInterface ) ~= 'table' then return false end local i, s, v -- check if version is a frame table if type( version ) == 'table' and type( version.args ) == 'table' then s = version.args[ 1 ] if not s and type( version.getParent ) == 'function' then i = version:getParent() if i then s = i.args[ 1 ] end end version = s end -- version should be a string if type( version ) == 'string' then -- check if empty string version = mw.text.trim( version ) if version == '' then version = nil end else version = nil end -- getting version from Wikidata if version == 'wikidata' then version = nil i = moduleInterface.item if type( i ) == 'number' and i > 0 then s = mw.wikibase.getBestStatements( 'Q' .. i, 'P348' ) for i = 1, #s, 1 do if s[ i ].mainsnak.snaktype == 'value' then v = s[ i ].mainsnak.datavalue.value if v ~= '' then return v end end end end end if not moduleInterface.serial then return false elseif not version or version <= moduleInterface.serial then return moduleInterface.serial else return false end end -- returns module interface -- function name is identical to the module name function fs.Failsafe() return Failsafe end -- returns failsafe function for this module -- identical name "failsafe" for all modules, therefore it could be used as -- example code function fs.failsafe( version ) return fs._failsafe( version, Failsafe ) or '' end return fs