Modul:Failsafe: Unterschied zwischen den Versionen
(correction) |
(+failsaveUsed) |
||
Zeile 11: | Zeile 11: | ||
notOk = '[[File:Symbol oppose vote.svg|15px|text-bottom|Contra]]', | notOk = '[[File:Symbol oppose vote.svg|15px|text-bottom|Contra]]', | ||
otherVersion = '[[Category:Andere Modulversion in Wikidata]]', | otherVersion = '[[Category:Andere Modulversion in Wikidata]]', | ||
failsaveUsed = '[[Category:Modulversion mit failsave bestimmt]]', | |||
versionText = 'Versionsbezeichnung auf Wikidata:', | versionText = 'Versionsbezeichnung auf Wikidata:', | ||
noVersion = 'keine Version verfügbar', | noVersion = 'keine Version verfügbar', | ||
Zeile 89: | Zeile 90: | ||
function fs.getModuleVersion( frame ) | function fs.getModuleVersion( frame ) | ||
local result = strings.versionText .. ' ' .. strings.noVersion | local result = strings.versionText .. ' ' .. strings.noVersion | ||
local fromModule, fromWikidata, m, success | local failsaveUsed, fromModule, fromWikidata, m, success | ||
local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) | local title = mw.ustring.gsub( mw.title.getCurrentTitle().text, '/' .. strings.docPage, '' ) | ||
Zeile 103: | Zeile 104: | ||
fromWikidata = fs._failsafe( 'wikidata', m.moduleInterface ) | fromWikidata = fs._failsafe( 'wikidata', m.moduleInterface ) | ||
elseif m.failsafe then | elseif m.failsafe then | ||
failsaveUsed = true | |||
fromModule = m.failsafe( '' ) | fromModule = m.failsafe( '' ) | ||
fromWikidata = m.failsafe( 'wikidata' ) | fromWikidata = m.failsafe( 'wikidata' ) | ||
Zeile 117: | Zeile 119: | ||
elseif not fromWikidata then | elseif not fromWikidata then | ||
result = result .. ' ' .. noWikidataVersion | result = result .. ' ' .. noWikidataVersion | ||
end | |||
if failsaveUsed then | |||
result = result .. strings.failsaveUsed | |||
end | end | ||
end | end |
Version vom 8. April 2021, 08:04 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Failsafe/doc erstellt werden
-- module interface local Failsafe = { suite = 'Failsafe', serial = '2021-04-08', 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]]', otherVersion = '[[Category:Andere Modulversion in Wikidata]]', failsaveUsed = '[[Category:Modulversion mit failsave bestimmt]]', 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 -- 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 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 failsaveUsed, 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 failsaveUsed = true 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 if failsaveUsed then result = result .. strings.failsaveUsed end end end return result end return fs