Modul:Sandlåda/Lavallen
Dokumentationen för denna modul kan skapas på Modul:Sandlåda/Lavallen/dok
p = {}
ibcolor = {
['brown'] = '#dacaa5',
['cave'] = '#dacaa5',
['geology'] = '#dacaa5',
['island'] = '#dacaa5',
['mountain'] = '#dacaa5',
['mountain range'] = '#dacaa5',
['summit'] = '#dacaa5',
['pass'] = '#dacaa5',
['peninsula'] = '#dacaa5',
['valley'] = '#dacaa5',
['range'] = '#dacaa5',
['creek'] = '#b3cce4',
['lake'] = '#b3cce4',
['river'] = '#b3cce4',
['reservoir'] = '#b3cce4',
['stream'] = '#b3cce4',
['water'] = '#b3cce4',
['national park'] = '#cde5b2',
['nature'] = '#cde5b2',
['protected area'] = '#cde5b2',
['reserve='] = '#cde5b2',
['borough'] = '#dfdfdf',
['city'] = '#dfdfdf',
['settlement'] = '#dfdfdf',
['town'] = '#dfdfdf',
['township'] = '#dfdfdf',
['village'] = '#dfdfdf',
['bell'] = '#ffffcc',
['bridge'] = '#ffffcc',
['building'] = '#ffffcc',
['monument'] = '#ffffcc',
['race track'] = '#ffffcc',
['region'] = '#ffdead',
['parish'] = '#ffec8b'
}
ibcolor2 = {
['småort'] = '#dfdfdf',
['tätort i sverige'] = '#dfdfdf',
['sveriges kommuner'] = '#ffdead'
}
Geobox2color = function(entity, args)
if args[1] then
return ibcolor[mw.ustring.lower(args[1])]
end
if not entity then
return '#dacaa5'
end
if not entity.claims then
return '#dacaa5'
end
if not entity.claims["P31"] then
return '#dacaa5'
end
for i, j in pairs(entity:getBestStatements( "P31" )) do
if j.mainsnak.snaktype == 'value' then
local qid = 'Q' .. j.mainsnak.datavalue.value['numeric-id']
local entity2 = mw.wikibase.getEntityObject(qid)
local label = entity2:getLabel()
if ibcolor2[mw.ustring.lower(label)] then
return ibcolor2[mw.ustring.lower(label)]
end
end
end
return ''
end
Geobox2lineplain = function(entity, args, namn, set, stil)
local s = mw.text.tag('td', {colspan="2", style = (stil or "text-align: center;") }, namn)
return mw.text.tag('tr', set, s)
end
form = function(entity, args)
local s = {}
if args['form'] or args['form1'] then
if args['form'] then
table.insert(s, args['form'])
end
local c = 1
while(args['form' .. c]) do
table.insert(s, args['form' .. c])
c = c + 1
end
else
if not entity.claims["P31"] then
return s
end
for i, j in pairs(entity:getBestStatements( "P31" )) do
if j.mainsnak.snaktype == 'value' then
table.insert(s, i)
end
end
end
local s2 = {}
local style = "text-align: center; background-color: " .. Geobox2color(entity, args) ..";"
for i, j in pairs(s) do
if i ~= #s then
table.insert(s2, Geobox2lineplain(entity, args, j, {class="mergedrow", title= 'Kategori'}, style))
else
table.insert(s2, Geobox2lineplain(entity, args, j, {class="mergedbottomrow", title= 'Kategori'}, style))
end
end
return s2
end
inhemskt = function(entity, args)
local s = {}
if args['officiellt_namn'] or args['officiellt_namn1'] then
if args['officiellt_namn'] then
if args['officiellt_namn_språk'] then
table.insert(s, {args['officiellt_namn'], args['officiellt_namn_språk']})
else
table.insert(s, {args['officiellt_namn'], nil})
end
end
local c = 1
while args['officiellt_namn' .. c] do
if args['officiellt_namn' .. c ..'_språk'] then
table.insert(s, {args['officiellt_namn' .. c], args['officiellt_namn' .. c ..'_språk']})
else
table.insert(s, {args['officiellt_namn' .. c], nil})
end
c = c + 1
end
else
if not entity then
return s
end
if not entity.claims then
return s
end
if not entity.claims["P1566"] then
return s
end
for i, j in pairs(entity:getBestStatements( "P1448" )) do
if j.mainsnak.snaktype == 'value' then
table.insert(s, {j.mainsnak.datavalue.value.text, mw.language.fetchLanguageName( j.mainsnak.datavalue.value.language, 'sv')})
end
end
end
local s2 = {}
local style = "text-align: center; font-weight: bold; background-color: " .. Geobox2color(entity, args) ..";"
for i, j in pairs(s) do
if j[2] then
table.insert(s2, Geobox2lineplain(entity, args, j[1], {class="mergedrow", title= 'Officiellt namn på ' .. j[2]}, style))
else
table.insert(s2, Geobox2lineplain(entity, args, j[1], {class="mergedrow", title= 'Officiellt namn'}, style))
end
end
return s2
end
p.geobox = function(frame)
local s = {}
local entity = mw.wikibase.getEntityObject()
local args = frame:getParent().args
local style = args.style or "text-align: center; font-weight: bold; font-size: 1.25em; background-color: " .. Geobox2color(entity, args) .. ";"
local namn = args.namn or entity:getLabel() or mw.title.getCurrentTitle().text
table.insert(s, Geobox2lineplain(entity, args, namn, {class="mergedtoprow", title= 'Objektets namn'}, style))
for i, j in pairs(inhemskt(entity, args)) do
table.insert(s, j)
end
for i, j in pairs(form(entity, args)) do
table.insert(s, j)
end
return mw.text.tag('table', {class="infobox geography", style="width: " .. (args['geobox_width'] or '256') .. "px; padding: 0; font-size: 89%;"}, table.concat(s, ''))
end
return p