Modul:Koordinaten
Zur Navigation springen
Zur Suche springen
Dokumentation und Testfälle unter Modul:Koordinaten/Doku.
local p = {} function robusttrim(s) if s==nil then return '' end local p=string.gsub(s,'%[%[SMW::on%]%]','') p=string.gsub(p,'%[%[SMW::off%]%]','') return mw.text.trim(p) end function split(inputstr,sep) if sep==nil then sep="%s" end local t={} local i=1 for str in string.gmatch(inputstr,"([^"..sep.."]+)") do t[i]=str i=i+1 end if i==1 then t[1]=inputstr end return t end function holeKoordinaten(frame,ort) if ort=='' then return '' end local a=frame:callParserFunction( '#show',ort, '?Koordinaten' ) return a end function holeViewbox(frame,ort) if ort=='' then return '' end local a=frame:callParserFunction( '#show',ort, '?Viewbox' ) return a end function holeHandlungsorte(frame,geschichte) if geschichte=='' then return '' end local a=frame:callParserFunction( '#ask','[['..geschichte..']]', 'mainlabel=-', '?Handlungsort ist#=', 'sep=€' ) return a end function viewboxToKoordinaten(viewbox) if viewbox=="" then return "" end if true then return viewbox end local result="" local width=10000000 for token in split(viewbox,",") do local subtokens={} local i=0 for subtoken in split(token) do subtokens[i]=0+subtoken i=i+1 end if subtokens[3] then if subtokens[3]<width then width=subtokens[3] local x=subtokens[0]+subtokens[2]/2 local y=subtokens[1]+subtokens[3]/2 result=x..";"..y end end end return result end function erzeugeKoordinaten(frame,geschichte) if geschichte=='' then return '' end local orte=holeHandlungsorte(frame,geschichte) local ortet=split(orte,'€') local result="" for key,ort in pairs(ortet) do koord=holeKoordinaten(frame,ort) if koord=="" then view=holeViewbox(frame,ort) koord=viewboxToKoordinaten(view) end result=result.."\n\n"..geschichte..";0!14;;"..koord..";"..ort end return result end function p.Koordinaten() frame=mw.getCurrentFrame() geschichte=robusttrim(frame.args['Geschichte']) if(geschichte=='') then return '' end return erzeugeKoordinaten(frame,geschichte) end return p