Modul:EpLink
Version vom 4. Januar 2019, 11:43 Uhr von Master (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „local episodes = mw.loadData( 'Module:Episoden' ) local numberOfEpisodes = 727 local p = {} function p.getEpisodeData(frame) local title = frame.args[1]…“)
Die Dokumentation für dieses Modul kann unter Modul:EpLink/Doku erstellt werden
local episodes = mw.loadData( 'Module:Episoden' )
local numberOfEpisodes = 727
local p = {}
function p.getEpisodeData(frame)
local title = frame.args[1]
title = mw.ustring.gsub( title , '=', '=')
local series = 'ALL'
if frame.args[2] ~= nil and frame.args[2] ~= '' then
series = mw.ustring.sub(frame.args[2], 0, 3)
end
local suffix = ''
if type(episodes[series]) == 'table' then
for _,episode in pairs(episodes[series]) do
thisTitleDE = episode[4]
if p.fuzzyMatch(thisTitleDE, title) then
return episode
end
end
end
end
function p.getArticle(episode)
local title = mw.ustring.gsub( episode[4] , '', '')
local series = episode[5]
local suffix = ''
if series ~= "" then
suffix = ' (' .. series .. ')'
end
return title .. suffix
end
function p.fuzzyMatch(first, second)
return p.simplifyString(first) == p.simplifyString(second)
end
function p.simplifyString(string)
string = string.gsub(string, '[^%a%d]', '')
return mw.ustring.lower(string)
end
function p.getDescription(episode)
local number = mw.ustring.gsub( episode[2], 'x', '×')
local series = episode[1]
local title = episode[4]
local origtitle = mw.ustring.gsub( episode[3], '"', '"' )
local output = series .. ' ' .. number .. "\n»" .. title .. '« ' .. "\n" .. 'Originaltitel: »' .. origtitle .. '«'
return mw.text.encode( output )
end
function p.getRemasteredSuffix(series)
return ' – [[' .. series .. ' Remastered|Remastered]]'
end
function p.getLink(frame)
local episode = p.getEpisodeData(frame)
if episode == nil then
return p.getFallbackLink(frame)
end
local article = p.getArticle(episode)
local title = episode[4]
local description = p.getDescription(episode)
if frame.args[2] ~= nil then
local isRemastered = mw.ustring.match( frame.args[2], '-R', 3 ) ~= nil
else
local isRemastered = false
end
local suffix = ''
if isRemastered then
local series = episode[1]
suffix = p.getRemasteredSuffix(series)
end
return '[[' .. article .. "|<i title=\"" .. description .. "\">" .. title .. "</i>]]" .. suffix
end
function p.getFallbackLink(frame)
local title = frame.args[1]
local note = 'Ungenaue Angabe bitte Link überprüfen.'
local suffix = ' [[Vorlage:EpLink/Häufige Fehler|<sup title="' .. note .. '" style="color:red">?</sup>]]'
suffix = suffix .. '[[Kategorie:Artikel die Episodenverweise haben, die nicht auf Episoden verweisen]]'
return '[[' .. title .. "|<i>" .. title .. "</i>]]" .. suffix
end
function p.getEpisodeList()
local output = ''
for _,episode in pairs(episodes.ALL) do
series = episode[1]
title = episode[4]
output = output .. "\n* " .. p.getLink{['args']={title, series}}
end
return output
end
function p.getArticleByCode(frame)
local query = frame.args[1]
-- Expected format: TNG-0x01
local series = mw.ustring.sub( query, 0, 3)
local no = mw.ustring.sub( query, 5, 8)
for _,episode in pairs(episodes.ALL) do
thisSeries = episode[1]
thisNo = episode[2]
if (thisSeries == series) and (thisNo == no) then
return episode[4]
end
end
end
function p.getEpisodeTable()
local output = '{|'
output = output .. "\n|-"
local header = {'Serie', '№', 'Originaltitel', 'Dt. Titel', 'Suffix', 'Schlüssel' }
for _,text in pairs(header) do
output = output .. "\n! " .. text
end
for _,episode in pairs(episodes.ALL) do
output = output .. "\n|-"
for _,cell in pairs(episode) do
output = output .. "\n| " .. cell
end
output = output .. "\n| " .. p.simplifyString( episode[4] )
end
output = output .. "\n|-"
output = output .. "\n|}"
return output
end
function p.getCompactEpisodeTable(frame)
local series = frame.args[1]
local output = '{|'
output = output .. "\n|-"
local header = {'№', 'Titel' }
for _,text in pairs(header) do
output = output .. "\n! " .. text
end
for _,episode in pairs(episodes.ALL) do
local article = p.getArticle(episode)
if series == episode[1] then
output = output ..
"\n|-" ..
'\n| align="center" | ' ..
"[[" ..
article ..
'|' ..
episode[1] ..
'<br />' ..
episode[2] ..
"]]"..
"\n| " ..
"[[" ..
article ..
'|' ..
"''" ..
episode[4] ..
"''" ..
'<br />' ..
'<small>' ..
"''" ..
episode[3] ..
"''" ..
'</small>' ..
']]'
end
end
output = output .. "\n|-"
output = output .. "\n|}"
return output
end
return p