Modul:Adelskalendarium
Zur Navigation springen
Zur Suche springen
Dokumentation und Testfälle unter Modul:Adelskalendarium/Doku.
local p = {}
require("Modul:Hilfsfunktionen")
function holeHerrscher(lehen,maxdatum)
if lehen=='' then return {} end
local herrscher=mw.smw.ask('[[Herrscher von Lehen::'..lehen..']] [[Herrscher von VonIndex::<'..maxdatum..'0000]] [[Herrscher von BisIndex::>'..maxdatum..'0000]]'
..'|mainlabel=-'
..'|?Herrscher von Titel#=Titel'
..'|?=Herrscher'
..'|?Herrscher von Lehen#=Lehen'
..'|?Herrscher von Anzeige=Anzeige'
..'|?Herrscher von Von#=Von'
..'|limit=10'
)
if herrscher==nil then return {} end
return herrscher
end
function holeInfos(lehen,extern,vasallen)
if lehen=='' then return {} end
local s='[['..lehen..']]'
if vasallen then
s='[[Vasallenlehen von::'..lehen..']]'
end
local vasallen=mw.smw.ask(s..' [[Extern::'..extern..']]'
..'|mainlabel=-'
..'|?#-=Artikel'
..'|?Kennziffer'
..'|?Lehensebene'
..'|?Lehenstyp'
..'|?Einwohner'
..'|?Wappen ist#'
..'|?Icon ist#'
..'|?Briefspieler#'
..'|sort=Kennziffer'
..'|limit=500'
..'|searchlabel='
)
if vasallen==nil then return {} end
return vasallen
end
function nonil(s)
if(type(s)=='table') then
return 'TABLE'
end
if((s==nil)or(type(s)=='table')) then
return ''
end
return s
end
function farbeLehensebene(lehensebene)
if lehensebene=='Herr' then return '#c0c0c0' end
if lehensebene=='Junker' then return '#404040' end
if lehensebene=='Baron' then return '#008000' end
if lehensebene=='Graf' then return '#ffcc00' end
if lehensebene=='Provinzherr' then return '#d40000' end
if lehensebene=='Kaiser' then return '#0000c0' end
if lehensebene=='Kirche' then return '#ffffff' end
return ''
end
function iconLehensebene(lehensebene,namespace,name)
if lehensebene=='Herr' then return 'Edlenkrone' end
if lehensebene=='Junker' then return 'Junkerskrone' end
if lehensebene=='Baron' then return 'Baronskrone' end
if lehensebene=='Graf' then return 'Grafenkrone' end
if lehensebene=='Provinzherr' then
if namespace=='Garetien' then return 'Debrekskrone' end
if namespace=='Perricum' or namespace=='Greifenfurt' then return 'Markgrafenkrone' end
if namespace=='' then
if name=='Rommilyser Mark' or name=='Sonnenmark' or name=='Rabenmark' or name=='Markgrafschaft Warunk' or name=='Markgrafschaft Windhag' then return 'Markgrafenkrone' end
if name=='Fürstentum Albernia' or name=='Fürstentum Almada' or name=='Fürstentum Maraskan' or name=='Fürstentum Kosch' then return 'Fürstenkrone' end
if name=='Herzogtum Weiden' or name=='Herzogtum Tobrien' or name=='Herzogtum Nordmarken' then return 'Herzogenkrone' end
end
end
if lehensebene=='Kaiser' then return 'Raulskrone' end
if lehensebene=='Kirche' then return 'Kirchenkrone' end
if mw.site.siteName=='KoschWiki' then return 'Fürstenkrone' end
if mw.site.siteName=='TobrienWiki' then return 'Herzogenkrone' end
return ''
end
function classNachLevel(level)
local class=''
if level==0 or level==3 then
class='dunkel'
end
if level==1 or level==4 then
class='mittel'
end
if level==2 or level==5 then
class='hell'
end
return class
end
function styleNachLevel(level)
local style='font-size:'..(1.2-level/10)..'em;border:none;'
if level==0 then
style=style..'font-weight:bold;'
end
return style
end
function starteTabelle(maxlevel)
local result='{| style="width:100%;border:none;border-collapse:collapse"'
..'\n|- style="font-style:italic;font-size:0.7em"'
for i=1,maxlevel do
result=result..'\n|width="10px"|'
end
result=result
..'\n|width="30px"|'
..'\n|width="10%"|Kennziffer'
..'\n|width="20%"|Lehen'
..'\n|width="10%" style="text-align:right;padding-right:1em"|Einwohner'
..'\n|width="40%" |Herrscher'
..'\n|width="10%" style="text-align:center"|Briefspiel'
..'\n|width="30px" style="text-align:center"|Ebene'
..'\n'
return result
end
function endeTabelle()
local result='\n|}\n'
return result
end
function formatiereHerrscher(herrscher)
local result=''
for k,v in pairs(herrscher) do
result=result
..nonil(v['Titel'])..' '
..nonil(v['Herrscher'])..' '
..'[['..nonil(v['Lehen'])..'|'..v['Anzeige']..']] '
..'(seit '..nonil(v['Von'])..')<br>'
end
return result
end
function formatiereBriefspieler(briefspieler)
local result=''
if(briefspieler==nil) then return '' end
if(type(briefspieler)~='table') then briefspieler={briefspieler} end
for k,v in pairs(briefspieler) do
if v~='' then
local benutzer=string.match(v,"Benutzer:(.*)")
if benutzer~=nil then
result=result..'[[Datei:Bespielt.svg|20x20px|link='..v..']]'
else
result=result..'[[Datei:Bespielt NSC.svg|20x20px|link='..v..']]'
end
end
end
return result
end
function lehensLevel(lehenstyp)
if(lehenstyp=='Reich') then return 0 end
if(lehenstyp=='Provinz') then return 1 end
if(lehenstyp=='Grafschaft') then return 2 end
if(lehenstyp=='Baronie') then return 3 end
if(lehenstyp=='Großjunkertum') then return 4 end
if(lehenstyp=='Junkertum') then return 5 end
if(lehenstyp=='Herrschaft') then return 6 end
if(lehenstyp=='Ortschaft') then return 7 end
if(lehenstyp=='Bauwerk') then return 8 end
return 9
end
function syntaxKennziffer(kennziffer)
local redin='<span style="color:red">'
local redout='</span>'
local token=split(kennziffer,"-")
if (string.find(token[1],"^[A-Z][a-z][a-z]$")==nil) then token[1]=redin..token[1]..redout end
if (token[2]~=nil) and (string.find(token[2],"^[IVX]+$")==nil) then token[2]=redin..token[2]..redout end
if (token[3]~=nil) and (string.find(token[3],"^[0-9][0-9][KPGFHZ]*$")==nil)
and (string.find(token[3],"^S[0-9][KP]$")==nil)
and (string.find(token[3],"^A$")==nil) then token[3]=redin..token[3]..redout end
if (token[4]~=nil) and (string.find(token[4],"^[a-z][KPGFHZ]*$")==nil)
and (string.find(token[4],"^A$")==nil) then token[4]=redin..token[4]..redout end
if (token[5]~=nil) and (string.find(token[5],"^[a-z][KPGFHZ]*$")==nil) then token[5]=redin..token[5]..redout end
local result=token[1]
local c=2
while token[c]~=nil do
result=result.."-"..token[c]
c=c+1
end
return result
end
function sortiereNachKennziffern(lehen,a,b)
local ka=lehen[a]['Kennziffer']
local kas=ka:match("([^-]+)$")
local kan=tonumber(string.sub(kas,1,1))==nil
local kb=lehen[b]['Kennziffer']
local kbs=kb:match("([^-]+)$")
local kbn=tonumber(string.sub(kbs,1,1))==nil
if not kan and kbn then return false end
if kan and not kbn then return true end
return ka<kb
end
function formatiereInfos(lehen,extern,rekursion,columns,maxlevel,maxrekursion,maxdatum)
local result=''
for k,v in spairs(lehen,sortiereNachKennziffern) do
local level=lehensLevel(nonil(v['Lehenstyp']))
local style=styleNachLevel(rekursion)
local class=classNachLevel(rekursion)
local wappendatei=nonil(v['Wappen ist'])
local wappen='[['..wappendatei..'|30x30px|link=]]'
if wappendatei=='Datei:Wappen blanko.svg' then
wappen=''
end
local kennziffer=syntaxKennziffer(nonil(v['Kennziffer']))
local artikel=nonil(v['Artikel'])
local namespace=string.match(artikel,"(.*):")
if namespace==nil then
namespace=''
end
local name=string.match(artikel,":(.*)")
if name==nil then
name=artikel
end
local artikellink='[['..artikel..'#Kalendarium|'..name..']]'
local einwohner=nonil(v['Einwohner'])
local herrscher=holeHerrscher(artikel,maxdatum)
lehensebene='[['..nonil(v['Icon ist'])..'|30x30px|link=|'..nonil(v['Lehensebene'])..']]'
if nonil(v['Icon ist'])==nonil(v['Wappen ist']) then
lehensebene='[[Datei:'..iconLehensebene(nonil(v['Lehensebene']),namespace,name)..'.svg|30x30px|link=|'..nonil(v['Lehensebene'])..']]'
end
local farbe=farbeLehensebene(nonil(v['Lehensebene']))
if farbe=='' then class='' end
local thiscolumn='\n|class="'..class..'"|'
if level<=maxlevel then
result=result
..'\n|- style="'..style..'" class="'..class..'"'
..columns
..'\n| style="border:none;" colspan="'..(1+maxrekursion-rekursion)..'"|'..wappen
..'\n| style="border:none;"|'..kennziffer
..'\n| style="border:none;padding-left:'..(rekursion*10)..'px"|'..artikellink
..'\n| style="border:none;text-align:right;padding-right:1em"|'..einwohner
..'\n| style="border:none;"|'..formatiereHerrscher(herrscher)
..'\n| style="border:none;text-align:center"|'..formatiereBriefspieler(v['Briefspieler'])
..'\n| style="border:none;text-align:center;background-color:'..farbe..'"|'..lehensebene
end
if (level<maxlevel) and (rekursion<maxrekursion) then
local vasallen=holeInfos(artikel,extern,true)
result=result..formatiereInfos(vasallen,extern,rekursion+1,columns..thiscolumn,maxlevel,maxrekursion,maxdatum)
end
end
return result
end
function p.Abfrage(frame)
if (frame.args[1]==nil) then
return 'no parameter found'
end
local lehen=robusttrim(frame.args[1])
local extern=robusttrim(frame.args[2])
local maxlevel=robusttrim(frame.args[3])
local maxrekursion=robusttrim(frame.args[4])
local maxdatum=robusttrim(frame.args[5])
if maxdatum=='' then
maxdatum='9999'
end
local selbst=holeInfos(lehen,extern,false)
local result=starteTabelle(tonumber(maxrekursion))
..formatiereInfos(selbst,extern,0,'',tonumber(maxlevel),tonumber(maxrekursion),maxdatum)
..endeTabelle()
return result
end
return p