Modul:Failsafe: Unterschied zwischen den Versionen
+getModuleVersion
K (Datum) |
(+getModuleVersion) |
||
Zeile 2: | Zeile 2: | ||
local Failsafe = { | local Failsafe = { | ||
suite = 'Failsafe', | suite = 'Failsafe', | ||
serial = ' | serial = '2021-04-08', | ||
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]]', | |||
otherVersion = '[[Category:Andere Modulversion in Wikidata]]', | |||
versionText = 'Versionsbezeichnung auf Wikidata:', | |||
noVersion = 'keine Version verfügbar', | |||
noWikidataVersion = '(keine Version auf Wikidata verfügbar)' | |||
} | |||
-- modul variable and administration | |||
local fs = { | |||
moduleInterface = Failsafe | |||
} | |||
-- possible vaules of version | -- possible vaules of version | ||
Zeile 13: | Zeile 25: | ||
-- 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 60: | ||
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 62: | Zeile 74: | ||
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 83: | ||
end | end | ||
local function getModule( title ) | |||
return require( li.modulePrefix .. id ) | |||
return | |||
end | end | ||
function fs.getModuleVersion( frame ) | |||
local result = strings.noVersion | |||
local fromModule, fromWikidata, m, success | |||
local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) | |||
if title == 'Failsafe' then | |||
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 ) | |||
elseif m.failsafe then | |||
fromModule = m.failsafe( '' ) | |||
fromWikidata = m.failsafe( 'wikidata' ) | |||
end | |||
if fromWikidata or fromModule then | |||
result = strings.versionText .. ' <code>' | |||
.. ( fromWikidata or fromModule ) .. '</code>' | |||
if fromWikidata and fromModule then | |||
if fromWikidata == fromModule then | |||
result = result .. ' ' .. strings.ok | |||
else | |||
result = result .. ' ' .. strings.notOk .. strings.otherVersion | |||
end | |||
elseif not fromWikidata then | |||
result = result .. ' ' .. noWikidataVersion | |||
end | |||
end | |||
end | |||
return result | |||
end | end | ||
return fs | return fs |