Modul:Failsafe: Unterschied zwischen den Versionen
K (vereinfacht) |
K (15 Versionen von wikivoyage:Modul:Failsafe importiert) |
||
(11 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
Zeile 2: | Zeile 2: | ||
local Failsafe = { | local Failsafe = { | ||
suite = 'Failsafe', | suite = 'Failsafe', | ||
serial = ' | serial = '2022-04-25', | ||
item = 65306115 | item = 65306115 | ||
} | } | ||
-- modul variable | local strings = { | ||
local fs = {} | docPage = 'Doku', | ||
ok = '[[File:Artículo bueno.svg|16px|text-bottom|Ok!]]', | |||
notOk = '[[File:Symbol oppose vote.svg|15px|text-bottom|Contra]][[Category:Andere Modulversion in Wikidata]]', | |||
versionText = 'Versionsbezeichnung auf Wikidata:', | |||
noVersion = 'keine Version verfügbar' | |||
} | |||
-- modul variable and administration | |||
local fs = { | |||
moduleInterface = Failsafe | |||
} | |||
-- possible vaules of version | -- possible vaules of version | ||
Zeile 13: | Zeile 23: | ||
-- string: string of version required | -- string: string of version required | ||
-- table: frame table (template, #invoke) | -- table: frame table (template, #invoke) | ||
-- | -- aModuleInterface | ||
-- table | -- table | ||
function fs._failsafe( version, | function fs._failsafe( version, aModuleInterface ) | ||
if type( | if type( aModuleInterface ) ~= 'table' then | ||
return false | return false | ||
end | end | ||
Zeile 48: | Zeile 58: | ||
if version == 'wikidata' then | if version == 'wikidata' then | ||
version = nil | version = nil | ||
i = | i = aModuleInterface.item | ||
if type( i ) == 'number' and i > 0 then | if type( i ) == 'number' and i > 0 then | ||
s = mw.wikibase.getBestStatements( 'Q' .. i, 'P348' ) | s = mw.wikibase.getBestStatements( 'Q' .. i, 'P348' ) | ||
Zeile 55: | Zeile 65: | ||
v = s[ i ].mainsnak.datavalue.value | v = s[ i ].mainsnak.datavalue.value | ||
if v ~= '' then | if v ~= '' then | ||
return v | return v:gsub( '%.', '-' ) | ||
end | end | ||
end | end | ||
Zeile 62: | Zeile 72: | ||
end | end | ||
if not | if not aModuleInterface.serial then | ||
return false | return false | ||
elseif not version or version <= | elseif not version or version <= aModuleInterface.serial then | ||
return | return aModuleInterface.serial | ||
else | else | ||
return false | return false | ||
Zeile 71: | Zeile 81: | ||
end | end | ||
local function getModule( title ) | |||
return require( 'Module:' .. title ) | |||
function | |||
return | |||
end | end | ||
function fs.getModuleVersion( frame ) | |||
local result = strings.versionText .. ' ' .. strings.noVersion | |||
-- | local fromModule, fromWikidata, m, success | ||
local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) | |||
if title == 'Failsafe' then -- the module itself | |||
success = true | |||
m = fs | |||
else | |||
success, m = pcall( getModule, title ) | |||
end | |||
if success then | |||
if m.moduleInterface then | |||
fromModule = m.moduleInterface.serial | |||
fromWikidata = fs._failsafe( 'wikidata', m.moduleInterface ) | |||
end | |||
if fromWikidata or fromModule then | |||
result = strings.versionText .. ' <code>' | |||
.. ( fromWikidata or fromModule ) .. '</code>' | |||
if fromWikidata and fromModule then | |||
result = result .. ' ' .. | |||
( fromWikidata == fromModule and strings.ok or strings.notOk ) | |||
end | |||
end | |||
end | |||
return result | |||
end | end | ||
return fs | return fs |
Aktuelle Version vom 27. Januar 2023, 07:40 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Failsafe/doc erstellt werden
-- module interface local Failsafe = { suite = 'Failsafe', serial = '2022-04-25', item = 65306115 } local strings = { docPage = 'Doku', ok = '[[File:Artículo bueno.svg|16px|text-bottom|Ok!]]', notOk = '[[File:Symbol oppose vote.svg|15px|text-bottom|Contra]][[Category:Andere Modulversion in Wikidata]]', versionText = 'Versionsbezeichnung auf Wikidata:', noVersion = 'keine Version verfügbar' } -- modul variable and administration local fs = { moduleInterface = Failsafe } -- possible vaules of version -- nil, false: no version required -- string: string of version required -- table: frame table (template, #invoke) -- aModuleInterface -- table function fs._failsafe( version, aModuleInterface ) if type( aModuleInterface ) ~= '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 = aModuleInterface.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:gsub( '%.', '-' ) end end end end end if not aModuleInterface.serial then return false elseif not version or version <= aModuleInterface.serial then return aModuleInterface.serial else return false end end local function getModule( title ) return require( 'Module:' .. title ) end function fs.getModuleVersion( frame ) local result = strings.versionText .. ' ' .. strings.noVersion local fromModule, fromWikidata, m, success local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) if title == 'Failsafe' then -- the module itself success = true m = fs else success, m = pcall( getModule, title ) end if success then if m.moduleInterface then fromModule = m.moduleInterface.serial fromWikidata = fs._failsafe( 'wikidata', m.moduleInterface ) end if fromWikidata or fromModule then result = strings.versionText .. ' <code>' .. ( fromWikidata or fromModule ) .. '</code>' if fromWikidata and fromModule then result = result .. ' ' .. ( fromWikidata == fromModule and strings.ok or strings.notOk ) end end end return result end return fs