Modul:Lehensabfrage Briefspiel: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
VolkoV (Diskussion | Beiträge) K (Automatisch synchronisiert.) |
K (SyncBot) |
||
| (Eine dazwischenliegende Version von einem anderen Benutzer wird nicht angezeigt) | |||
| Zeile 3: | Zeile 3: | ||
function robusttrim(s) | function robusttrim(s) | ||
if s==nil then return '' end | if s==nil then return '' end | ||
local p= | local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') | ||
p= | p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') | ||
return mw.text.trim(p) | return mw.text.trim(p) | ||
end | end | ||
| Zeile 41: | Zeile 41: | ||
function printhandlungsortesub(frame,ort,catname,visited,rekursion,enhance) | function printhandlungsortesub(frame,ort,catname,visited,rekursion,enhance) | ||
ort= | ort=mw.ustring.gsub(ort,"(%b<>)","") --strip html tags | ||
if rekursion==0 then return '' end | if rekursion==0 then return '' end | ||
if visited[ort]~=nil then return '' end | if visited[ort]~=nil then return '' end | ||
| Zeile 89: | Zeile 89: | ||
local result=holehandlungsorte(frame,geschichte) | local result=holehandlungsorte(frame,geschichte) | ||
return printhandlungsorte(frame,result,catname) | return printhandlungsorte(frame,result,catname) | ||
end | end | ||
return p | return p | ||
Aktuelle Version vom 18. August 2024, 14:55 Uhr
Dokumentation und Testfälle unter Modul:Lehensabfrage Briefspiel/Doku.
local p = {}
function robusttrim(s)
if s==nil then return '' end
local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
return mw.text.trim(p)
end
function holehandlungsorte(frame,geschichte)
if geschichte=='' then return '' end
--Finde alle Handlungsorte
local a=frame:callParserFunction(
'#ask','[['..geschichte..']]',
'mainlabel=-',
'?Handlungsort ist#=',
'limit=500',
'searchlabel=',
'format=list'
)
return mw.text.split(a,',',true);
end
function holelehenattribut(frame,lehen,attribut)
if lehen=='' then return 'unbekannt' end
local a=frame:callParserFunction(
'#show',lehen,
'?'..attribut..'#'
)
if a=='' then a='unbekannt' end
return a
end
function basepagename(page)
local parts=mw.text.split(page,':',true)
if #parts==1 then return parts[1] end
return parts[2]
end
function printhandlungsortesub(frame,ort,catname,visited,rekursion,enhance)
ort=mw.ustring.gsub(ort,"(%b<>)","") --strip html tags
if rekursion==0 then return '' end
if visited[ort]~=nil then return '' end
visited[ort]=true
ort=mw.text.split(ort,'#',true)[1]
local result=''
local i=holelehenattribut(frame,ort,'Icon ist')
local ortbps=basepagename(ort)
local hoi='[[Handlungsort indirekt::'..ort..'| ]]'
if rekursion==7 then hoi='' end
result=result..' [['..i..'|20px|link='..ort..']][[Kategorie:'..ortbps..'|'..catname..']]'..hoi
if enhance then
result='<div class="hell" style="display:inline-block;">'..result..'</div>'
end
local heg=frame:callParserFunction(
'#show',ort,
'?Vasallenlehen von#'
)
if heg~='' then
local heg1=mw.text.split(heg,',',true);
for key,value in pairs(heg1) do
if robusttrim(value)~='' then
result=printhandlungsortesub(frame,value,catname,visited,rekursion-1,false)..result..' '
end
end
end
return result
end
function printhandlungsorte(frame,orte,catname)
local result=''
local visited={}
for key,value in pairs(orte) do
if robusttrim(value)~='' then
result=result..printhandlungsortesub(frame,value,catname,visited,7,true)
end
end
return result
end
function p.Abfrage(frame)
if (frame.args[1]==nil) then
return "no parameter found"
end
local catname=robusttrim(frame.args[2])
local geschichte=frame.args[1]
local result=holehandlungsorte(frame,geschichte)
return printhandlungsorte(frame,result,catname)
end
return p