Modul:Partei

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Vorlagenprogrammierung Diskussionen Lua Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus


local p = {}
local cfg = mw.loadData('Modul:Partei/Liste');
local cfx = mw.loadData('Modul:Partei/Akronyme');	
local getArgs = require('Modul:Arguments').getArgs

-- §1 DELINK
local function delink(partei)
	local a = partei
	local n1 = mw.ustring.find(a,'%[%[')
	if (n1) then
		local b = mw.ustring.sub(a,n1+2)
		local n2 = mw.ustring.find(b,'%|')
		local n3 = mw.ustring.find(b,'%]%]')
		local c = mw.ustring.sub(a,n1+2,n3+n1)
		local n4 = mw.ustring.find(c,'%|')
		if (n4) then
			a = mw.ustring.sub(a,n1+2,n2+n1)
			else
			a = c
		end
		else
		if (n3) then
			if (n2) then
				a = mw.ustring.sub(a,n1+2,n2+n1)
				else
				a = c
			end
		end
	end
	a = mw.text.decode(a)
	return a
end

-- §2 PARTEINAME/AKRONYM
function p.name(frame)
	local args = getArgs(frame)
	local partei = args[1]
	local land = args[2]
	if land then kom = land..'-'..partei end
	local full = cfx.akronym[kom] or ''
	return full[1] or delink(partei)
end

-- §3 STANDARD FARBE
function p.farbe(frame)
	local partei = p.name(frame)
	partei = cfg.altname[partei] or partei
	local farbe = cfg.info[partei] or ''
	return farbe[1] or 'DABAD0'
end

function p.color(frame)
	local args = getArgs(frame)
	local kurz = args[1]
	local land = args[2]
	return p.farbe({kurz, land})
end

-- §4 ALTERNATIVE FARBE
function p.alt(frame)
	local partei = p.name(frame)
	partei = cfg.altname[partei] or partei
	local farbe = cfg.info[partei] or ''
	return farbe[3] or 'DABAD0'
end

-- §5 DUNKEL FARBE: STANDARD/ALTERNATIVE
local function farben(frame)
	local args = getArgs(frame)
	local v = args['V']
	if v == 'A' then return p.alt(frame)
	elseif v == 'HA' then return p.alt(frame) 
	elseif mw.ustring.find(args[1],' ') then return p.alt(frame)
	else return p.farbe(frame) or 'DABAD0'
	end
end

-- §6: HELLERE FARBE: STANDARD/ALTERNATIVE
function p.hell(frame)
	local args = getArgs(frame)
	local opaz = tonumber(args['h']) or 0.2
	local farbe = args['col'] or farben(frame)
	local cls = {}
	if (farbe:len() == 6) then
		cls[1] = tonumber(farbe:sub(1,2),16) or 255
		cls[2] = tonumber(farbe:sub(3,4),16) or 255
		cls[3] = tonumber(farbe:sub(5,6),16) or 255
	end
	cls[1] = 255 - math.floor((255-cls[1])*opaz)
	cls[2] = 255 - math.floor((255-cls[2])*opaz)
	cls[3] = 255 - math.floor((255-cls[3])*opaz)
	return string.format('%02X%02X%02X',cls[1],cls[2],cls[3])
end

-- §7 PARTEINAMEFARBE
function p.parteinamefarbe(frame)
	local args = getArgs(frame)
	local farbe = '#' .. farben(frame)
	local spaltef = 'rowspan="%s" style="width:2px; background-color:%s;"|\n'
	local spaltek = '| scope="row" rowspan="%s" colspan="%s" style="text-align:left;"|%s\n'
	local spaltep = '| scope="row" rowspan="%s" colspan="%s" style="text-align:left;"|%s'
	local rowspan = tonumber(args.rowspan) or 1
	local colspan = tonumber(args.colspan) or 1
	spaltef = string.format(spaltef, rowspan, farbe)
	if args['k'] then spaltek = string.format(spaltek, rowspan, colspan, args['k']) end
	spaltep = string.format(spaltep, rowspan, colspan, args[1])
	if args['k'] then return(spaltef..spaltek..spaltep) else
	return (spaltef..spaltep) end
end

-- §
local function namelink(frame)
	local args = getArgs(frame)
	local part = args[1]
	local land = args[2]
	if land then return cfx.akronym[(land..'-'..part)] end
end

-- §8 PIPELINK (Akronym, Land > [[Name|Akronym]])
function p.pipelink(frame)
	local args = getArgs(frame)
	local link = namelink(frame) or ''
	local kompletter = link[1]
	local sequenz = link[2]
	local kurz = mw.ustring.find(args[1],'%s%(')
	local trick = mw.ustring.sub(args[1], 1, kurz)
	if args[1] == 'Unabh.' then return '[[Parteilos|Unabh.]]' else
		if sequenz then return sequenz else
			if kompletter then
				if args[1] == kompletter then return '[['..args[1]..']]'
					else return '[['..kompletter..'|'..trick..']]'
				end
				else return args[1]
			end
		end
	end
end

-- §9 FULL (Akronym, Land > [[Name]], oder [[Name (Begriffsklärung)|Name]])
function p.full(frame)
	local args = getArgs(frame)
	local link = namelink(frame)
	local label = link['label']
	if link then
		local full = mw.ustring.find(link[1],'%s%(')
		local trick = mw.ustring.sub(link[1], 1, full)
		if label then return '[['..link[1]..'|'..label..']]' else
			if full then return '[['..link[1]..'|'..trick..']]'
				else return '[['..link[1]..']]'
			end
		end
		else return args[1]
	end
end

-- §10 PARTEIFARBEZEILE
function p.parteifarbezeile(frame)
	local args = getArgs(frame)
	local rowspan = tonumber(args.rowspan) or 1
	local colspan = tonumber(args.colspan) or 1
	local width = (tonumber(args.w) or 0) .. 'px'
	local def = args.k
	local farbe = '#' .. (args['f'] or farben(frame))
	local zeile = 'rowspan="%s" colspan="%s" style="border-bottom:3px solid; border-bottom-color:%s; width:%s"|' .. (def or p.pipelink(frame) or args[1]) .. '\n'
	return string.format(zeile, rowspan, colspan, farbe, width)
end

-- §11 PARTEIFARBEZELLE
function p.parteifarbezelle(frame)
	local args = getArgs(frame)
	local rowspan = tonumber(args.rowspan) or 1
	local colspan = tonumber(args.colspan) or 1
	local v = args['V']
	if v == 'H' then farbe = '#' .. p.hell(frame)
	elseif v == 'HA' then farbe = '#' .. p.hell(frame)
	else farbe = '#' .. (args['f'] or farben(frame)) end
	local zelle = 'rowspan="%s" colspan="%s" style="background-color:%s;"'
	return string.format(zelle, rowspan, colspan, farbe)
end

-- §12 PARTEILEGENDE
function p.parteilegende(frame)
	local args = getArgs(frame)
	farbe = farben(frame)
	name = p.pipelink(frame)
	legende = '<span style="border-left:1.2em solid;border-left-color:#'..farbe..';margin-right:4px">&#xfeff;</span>'.. name
	return legende
end
	
-- §13 PARTEISITZE
function p.parteisitze(frame)
	local args = getArgs(frame)
	local x = args[1]
	local y = args[2]
	local pagename = mw.title.getCurrentTitle().prefixedText
	if args[4] then a = p.name({args[3], args[4]}) else
		if args[3] == 'P' then a = pagename
			else a = args[3]
		end
	end
	if args['V'] == 'A' then altfarbe = true end
	c = args['f'] or (altfarbe and p.alt({a})) or p.farbe({a})
	local q = tonumber(string.format('%.1f', x / y * 100))
	z = string.gsub(q, "%.", "%,")
	if args['w'] then w = '<span style="font-size:80%"> ('..z..' %)</span>' else w = '' end
	local k = (x / y * 100)..'%'
	local mandate = '<div style="max-width:150px">'..x..' / '..y..'%s</div><div style="width:100px;border:0.1px solid #aaa;background-color:#FFF;height:0.6em;position:relative;text-align:left;"><div style="background-color:#%s;width:%s;height:0.6em;"></div></div>'
	return string.format(mandate, w, c, k)
end

-- §14 FARBENLISTE
function p.farbenliste(frame)
	local root = mw.html.create('table'):addClass('wikitable sortable')
	root:tag('tr')
		:tag('th'):attr('rowspan', '2'):wikitext('Partei'):done()
		:tag('th'):attr('colspan', '2'):wikitext('Farbe'):done()
		:tag('th'):attr('rowspan', '2'):wikitext('Staat'):done()
		:tag('th'):attr('colspan', '2'):wikitext('Alt. Farbe'):done()
	root:tag('tr')
		:tag('th'):addClass('unsortable'):wikitext('Ausgabe'):done()
		:tag('th'):wikitext('Code'):done()
		:tag('th'):addClass('unsortable'):wikitext('Ausgabe'):done()
		:tag('th'):wikitext('Code'):done()
	local liste = {}
	for k, v in pairs(cfg.info) do
		liste[#liste+1] = k
	end
	table.sort(liste)
	for _, value in pairs(liste) do
	local info = cfg.info[value]
	if info[3] == nil then alt = '' else alt = 'background-color:#' .. info[3] end
	root:tag('tr')
		:tag('td'):wikitext('[[' .. value .. ']]'):done()
		:tag('td'):css('background-color', '#' .. info[1]):done()
		:tag('td'):wikitext(info[1]):done()
		:tag('td'):wikitext(info[2]):done()
		:tag('td'):cssText(alt):done()
		:tag('td'):wikitext(info[3]):done()
	end
	return root
end

-- §15 LISTE DER ALTERNATIVEN NAMEN
function p.altnamenliste(frame)
	local root = mw.html.create('table'):addClass('wikitable sortable')
	root:tag('tr')
		:tag('th'):wikitext('Alternativer name'):done()
		:tag('th'):wikitext('Partei'):done()
	local altn = {}
	for k, v in pairs(cfg.altname) do
		altn[#altn+1] = k
	end
	table.sort(altn)
	for _, name in ipairs(altn) do
	root:tag('tr')
		:tag('td'):wikitext('[[' .. name .. ']]'):done()
		:tag('td'):wikitext('[[' .. cfg.altname[name] ..']]'):done()
	end
	return root
end

-- §16 AKRONYME LISTE
function p.akronymeliste(frame)
	local root = mw.html.create('table'):addClass('wikitable sortable')
	root:tag('tr')
		:tag('th'):wikitext('Staat-Akronym'):done()
		:tag('th'):wikitext('Staat'):done()
		:tag('th'):wikitext('Akronym'):done()
		:tag('th'):wikitext('Parteiname'):done()
		:tag('th'):wikitext('Parteien'):done()
	local liste = {}
	for k, v in pairs(cfx.akronym) do
		liste[#liste+1] = k
	end
	table.sort(liste)
	for _, value in pairs(liste) do
	local akr = cfx.akronym[value]
	root:tag('tr')
		:tag('td'):wikitext('' .. value .. ''):done()
		:tag('td'):wikitext(string.sub('' .. value .. '', 0, 2)):done()
		:tag('td'):wikitext(string.sub('' .. value .. '', 4)):done()
		:tag('td'):wikitext('[['..akr[1]..']]'):done()
		:tag('td'):wikitext(akr[2]):done()
	end
	return root
end

return p