Modul:Wahl Listen

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:Wahl Listen/Doku erstellt werden

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local farbe = require('Modul:Partei').farbe
local gewahlt = require('Modul:Direktwahl').gewahlt

function p.form(num)
	return (tonumber(num) and mw.getLanguage('de'):formatNum(tonumber(num))) or '–'
end
	
function p.pz(frame)
	local args = getArgs(frame)
	a = args[1] or ''
	b = args[2] or ''
	if tonumber(a) and tonumber(b) then
		s = string.format('%.1f', a*100/b)
		z = string.gsub(s, "%.", "%,")
	else z = '–'
	end
	return z
end

function p.wahl(frame)
	local args = getArgs(frame)
	if args['p'] == 's' then farben = true end
	if args['typ'] == 'PR' then PR = true end
	if args['typ'] == 'PA' then PA = true end
	if args['typ'] == 'PRZ' then PRZ = true end
	if args['typ'] == 'PAZ' then PAZ = true end
	if args['z1'] or PRZ or args['typ'] == 'PAZ' then zweite = true end
	local system = args['system'] or ''
	local cspan = 4 + (farben and 1 or 0) + (args['DS1'] and 1 or 0) + (args['DM1'] and 1 or 0) + (zweite and 2 or 0) + (args['gesamtmg'] and 2 or 0) + (args['DSZ1'] and 1 or 0) + (args['DMZ1'] and 1 or 0) + (args['DMG1'] and 1 or 0) + (args['BG'] and 1 or 0)
	local cst = farben and 2 or 1
	local rst = zweite and 2 or 1
	local subcsp = 2 + (PAZ and 1 or 0) + (args['DS1'] and 1 or 0) + (args['DM1'] and 1 or 0)
	local gesamts = args['gesamts']
	local gesamtsz = args['gesamtsz']
	local wahler = args['wähler']
	local wahlerz = PRZ and args['wähler'] or args['wählerz']
	local wahlberechtigte = args['wahlberechtigte']
	local wahlberechtigtez = PRZ and args['wahlberechtigte'] or args['wahlberechtigtez']
	local titel1 = PR and '1. Wahlgang' or ((system == '1') and '1. Wahlgang') or ((system == '2') and 'Direktstimmen') or (system == '3' and 'Wahlkreisstimmen') or (system == '4' and 'Provinzialstimmen') or (system == '5' and 'Listenstimmen') or 'Erststimmen'
	local titel2 = PR and '2. Wahlgang' or ((system == '1') and '2. Wahlgang') or ((system == '2') and 'Listenstimmen') or (system == '3' and 'Landesstimmen') or (system == '4' and 'Nationalstimmen') or (system == '5' and 'Wahlkreisstimmen') or 'Zweitstimmen'
	
	if PR or PRZ then
		a = 'Kandidaten'
		x = PRZ and 'Parteien/Listen' or 'Parteien'
		b = 'Stimmen'
		c = '%'
		csp = farben and 3 or 2
	elseif PA then
		a = 'Listen'
		b = 'Stimmen'
		c = '%'
		csp = farben and 2 or 1
		parl = true
	elseif PAZ then
		a = 'Listen'
		csp = farben and 2 or 1
		parl = true
	end

	if args['p1'] then
		root = mw.html.create('table'):addClass('wikitable sortable'):css('text-align', 'right'):css('float', 'left'):css('margin-right', '1em')
	else
		root = mw.html.create('table'):addClass('wikitable sortable'):css('text-align', 'right')
	end	
	row = root:tag('tr')
	row:tag('th')
		:wikitext(a)
		:attr('colspan', cst)
		:attr('rowspan', rst)
	if PR or PRZ then
		row:tag('th')
			:wikitext(x)
			:attr('rowspan', rst)
	end
	if zweite then
		row:tag('th')
			:wikitext(titel1)
			:attr('colspan', subcsp)
		row:tag('th')
			:wikitext(titel2)
			:attr('colspan', subcsp)
		if PAZ then
			if args['DMG1'] then			
				row:tag('th')
					:wikitext('Mandate')
					:attr('colspan', 2)
			else
				row:tag('th')
					:wikitext('Mandate<br/>Gesamt')
					:attr('rowspan', 2)
			end
			if args['BG'] then
				row:tag('th')
					:wikitext('[[Berliner Bundestagsabgeordneter|Berliner<br/>Abg.]]')
					:attr('rowspan', 2)
			end
		end
		row = root:tag('tr')
		row:tag('th')
			:wikitext('Stimmen')
		row:tag('th')
			:wikitext('%')
		if PAZ then
			if args['DS1'] then
				row:tag('th')
					:wikitext('+/-')
			end			
			row:tag('th')
				:wikitext('Mandate')
			if args['DM1'] then
				row:tag('th')
					:wikitext('+/- Mandate')
			end
		end
		row:tag('th')
			:wikitext('Stimmen')
		row:tag('th')
			:wikitext('%')
		if PAZ then
			if args['DSZ1'] then
				row:tag('th')
					:wikitext('+/-')
			end
			row:tag('th')
				:wikitext('Mandate')
			if args['DMZ1'] then
				row:tag('th')
					:wikitext('+/- Mandate')
			end
			if args['DMG1'] then
				row:tag('th')
					:wikitext('Anzahl')
				row:tag('th')
					:wikitext('+/-')
			end
		end
	else
		row:tag('th')
			:wikitext(b)
		row:tag('th')
			:wikitext(c)
		if args['DS1'] then
			row:tag('th')
				:wikitext('+/-')
		end
		if PA then
			row:tag('th')
				:wikitext('Mandate')
			if args['DM1'] then
				row:tag('th')
					:wikitext('+/-')
			end
		end
	end
	
	for k,v in pairs(args) do
		if PR then
			if tonumber(k) and ((tonumber(k) - 3 * math.floor(tonumber(k)/3)) == 1) then
				row = root:tag('tr')
				if farben then
					row:tag('td')
						:css('background', '#'..farbe({args[tonumber(k+1)]}))
						:css('width', '0px')
				end
				row:tag('td')
					:wikitext(v)
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(args[tonumber(k+1)])
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(p.form(args[tonumber(k+2)]))
				row:tag('td')
					:wikitext(p.pz({args[tonumber(k+2)], gesamts}))
				if args['z'..((tonumber(k+2)/3))] then
					row:tag('td')
						:wikitext(p.form(args['z'..((tonumber(k+2)/3))]))
					row:tag('td')
						:wikitext(p.pz({args['z'..(tonumber(k+2)/3)], gesamtsz}))
				end
			end
		elseif PRZ then
			if tonumber(k) == 1 then gew = gewahlt({'gewählt im WK'}) else gew = '' end
			if tonumber(k) and ((tonumber(k) - 4 * math.floor(tonumber(k)/4)) == 1) then
				row = root:tag('tr')
				if farben then
					row:tag('td')
						:css('background', '#'..farbe({args[tonumber(k+1)]}))
						:css('width', '0px')
				end
				row:tag('td')
					:wikitext(v..gew)
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(args[tonumber(k+1)])
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(p.form(args[tonumber(k+2)]))
				row:tag('td')
					:wikitext(p.pz({args[tonumber(k+2)], gesamts}))
				row:tag('td')
					:wikitext(p.form(args[tonumber(k+3)]))
				row:tag('td')
					:wikitext(p.pz({args[tonumber(k+3)], gesamtsz}))
			end	
		elseif PA then
			if tonumber(k) and ((tonumber(k) - 3 * math.floor(tonumber(k)/3)) == 1) then
				row = root:tag('tr')
				if farben then
					row:tag('td')
						:css('background', '#'..farbe({v}))
						:css('width', '0px')
				end
				row:tag('td')
					:wikitext(v)
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(p.form(args[tonumber(k+1)]))
				row:tag('td')
					:wikitext(p.pz({args[tonumber(k+1)], gesamts}))
				if args['DS1'] then
					row:tag('td')
						:wikitext(args['DS'..((tonumber(k+2)/3))])
				end
				row:tag('td')
					:wikitext(args[tonumber(k+2)])
				if args['DM1'] then
					row:tag('td')
						:wikitext(args['DM'..((tonumber(k+2)/3))])
				end
			end
		else
			if PAZ then
				if tonumber(k) and ((tonumber(k) - 6 * math.floor(tonumber(k)/6)) == 1) then
					row = root:tag('tr')
					if farben then
						row:tag('td')
							:css('background', '#'..farbe({v}))
							:css('width', '0px')
					end
					row:tag('td')
						:wikitext(v)
						:css('text-align', 'left')
					row:tag('td')
						:wikitext(p.form(args[tonumber(k+1)]))
					row:tag('td')
						:wikitext(p.pz({args[tonumber(k+1)], gesamts}))
					if args['DS1'] then
						row:tag('td')
							:wikitext(args['DS'..((tonumber(k+5)/6))])
					end
					row:tag('td')
						:wikitext(args[tonumber(k+2)])
					if args['DM1'] then
						row:tag('td')
							:wikitext(args['DM'..((tonumber(k+5)/6))])
					end
					row:tag('td')
						:wikitext(p.form(args[tonumber(k+3)]))
					row:tag('td')
						:wikitext(p.pz({args[tonumber(k+3)], gesamtsz}))
					if args['DSZ1'] then
						row:tag('td')
							:wikitext(args['DSZ'..((tonumber(k+5)/6))])
					end
					row:tag('td')
						:wikitext(args[tonumber(k+4)])
					if args['DMZ1'] then
						row:tag('td')
							:wikitext(args['DMZ'..((tonumber(k+5)/6))])
					end
					row:tag('td')
						:wikitext(args[tonumber(k+5)])
					if args['DMG1'] then
						row:tag('td')
							:wikitext(args['DMG'..((tonumber(k+5)/6))])
					end
					if args['BG'] then
						row:tag('td')
							:wikitext(args['B'..((tonumber(k+5)/6))] or '&ndash;')
					end
				end
			end
		end
	end
	
	if args['jgültige'] then
		row = root:tag('tr')
			row:tag('td')
				:wikitext(args['jname'] or (parl and 'Keine Liste') or 'Kein Kandidat')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(args['jgültige']))
			row:tag('td')
				:wikitext(p.pz({args['jgültige'], gesamts}))
			if parl then
				if args['DS1'] then
					row:tag('td')
						:wikitext(args['DJ'])
				end
				row:tag('td')
						:wikitext('&ndash;')
				if args['DM1'] then
					row:tag('td')
						:wikitext('&ndash;')
				end
			end
			if zweite then
				row:tag('td')
					:wikitext(p.form(args['jgültigez']))
				row:tag('td')
					:wikitext(p.pz({args['jgültigez'], gesamtsz}))
				if parl then
					if args['DSZ1'] then
						row:tag('td')
							:wikitext(args['DJZ'])
					end
					row:tag('td')
						:wikitext('&ndash;')
					if args['DMZ1'] then
						row:tag('td')
							:wikitext('&ndash;')
					end
					row:tag('td')
						:wikitext('&ndash;')
					if args['DMG1'] then
						row:tag('td')
							:wikitext('&ndash;')
					end
				end
			end
	end

	if args['rungültige'] then
		row = root:tag('tr')
			row:tag('td')
				:wikitext('Ungültige Stimmen')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(args['rungültige']))
			row:tag('td')
				:wikitext(p.pz({args['rungültige'], gesamts}))
			if parl then
				if args['DS1'] then
					row:tag('td')
						:wikitext(args['DR'])
				end
				row:tag('td')
					:wikitext('&ndash;')
				if args['DM1'] then
					row:tag('td')
						:wikitext('&ndash;')
				end
			end
			if zweite then
				row:tag('td')
					:wikitext(p.form(args['rungültigez']))
				row:tag('td')
					:wikitext(p.pz({args['rungültigez'], gesamtsz}))
				if parl then
					if args['DSZ1'] then
						row:tag('td')
							:wikitext(args['DRZ'])
					end
					row:tag('td')
						:wikitext('&ndash;')
					if args['DMZ1'] then
						row:tag('td')
							:wikitext('&ndash;')
					end
					row:tag('td')
						:wikitext('&ndash;')
					if args['DMG1'] then
						row:tag('td')
							:wikitext('&ndash;')
					end
				end
			end
	end
	
	if gesamts then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('th')
				:wikitext('Gesamt')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('th')
				:wikitext(p.form(gesamts))
				:css('text-align', 'right')
			row:tag('th')
				:wikitext('100')
				:css('text-align', 'right')
		if parl then
			if args['DS1'] then
				row:tag('th')
			end
			row:tag('th')
				:wikitext(args['gesamtm'])
				:css('text-align', 'right')
			if args['DM1'] then
				row:tag('th')
					:wikitext(args['DM'] or '&ndash;')
					:css('text-align', 'right')
			end
		end
		if zweite then
			row:tag('th')
				:wikitext(p.form(gesamtsz))
				:css('text-align', 'right')
			row:tag('th')
				:wikitext('100')
				:css('text-align', 'right')
			if parl then
				if args['DSZ1'] then
					row:tag('th')
				end
				row:tag('th')
					:wikitext(args['gesamtmz'])
					:css('text-align', 'right')
				if args['DMZ1'] then
					row:tag('th')
						:wikitext(args['DMZ'] or '&ndash;')
						:css('text-align', 'right')
				end
				row:tag('th')
					:wikitext(args['gesamtmg'])
					:css('text-align', 'right')
				if args['DMG1'] then
					row:tag('th')
						:wikitext(args['DMG'] or '&ndash;')
						:css('text-align', 'right')
				end
				if args['BG'] then
					row:tag('th')
						:wikitext(args['BG'])
						:css('text-align', 'right')
				end
			end
		end
	end
		
	if wahler or args['gültige'] or args['rungültige'] or wahlberechtigte then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:attr('colspan', cspan)
	end

	if args['gültige'] or args['rungültige'] then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext(args['gültige'] and 'Gültige Stimmzettel' or 'Gültige Stimmen')
				:attr('colspan', csp)
				:css('text-align', 'left')
				:css('font-weight', 'bold')
			row:tag('td')
				:wikitext(p.form(args['gültige'] or (gesamts - args['rungültige'])))
				:css('font-weight', 'bold')
			row:tag('td')
				:wikitext('&ndash;')
				:css('font-weight', 'bold')
			if args['DS1'] then
				row:tag('td')
					:wikitext('&ndash;')
					:css('font-weight', 'bold')
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				row:tag('td')
					:wikitext(p.form(args['gültigez'] or (gesamtsz - args['rungültigez'])))
					:css('font-weight', 'bold')
				row:tag('td')
					:wikitext('&ndash;')
					:css('font-weight', 'bold')
				if args['DSZ1'] then
					row:tag('td')
						:wikitext('&ndash;')
						:css('font-weight', 'bold')
				end
			end
	end

	if wahler or args['rungültige'] then
		if args['hungültige'] then
			row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext(args['hname'] or (parl and 'Keine Liste') or 'Kein Kandidat')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(args['hungültige']))
			row:tag('td')
				:wikitext(p.pz({args['hungültige'], wahler}))
			if args['DS1'] then
				row:tag('td')
					:wikitext(args['DH'])
			end
		end
		if args['leere'] and args['ungültige'] then
			row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext('Leere Stimmzettel')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(args['leere']))
			row:tag('td')
				:wikitext(p.pz({args['leere'], (args['rungültige'] and gesamts or wahler)}))
			if args['DS1'] then
				row:tag('td')
					:wikitext(args['DL'])
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				row:tag('td')
					:wikitext(p.form(args['leerez']))
				row:tag('td')
					:wikitext(p.pz({args['leerez'], wahlerz}))
				if args['DSZ1'] then
					row:tag('td')
						:wikitext(args['DLZ'])
				end
			end
			row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext('Ungültige Stimmzettel')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(args['ungültige']))
			row:tag('td')
				:wikitext(p.pz({args['ungültige'], (args['rungültige'] and gesamts or wahler)}))
			if args['DS1'] then
				row:tag('td')
					:wikitext(args['DU'])
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				row:tag('td')
					:wikitext(p.form(args['ungültigez']))
				row:tag('td')
					:wikitext(p.pz({args['ungültigez'], (args['rungültigez'] and gesamtsz or wahlerz)}))
				if args['DSZ1'] then
					row:tag('td')
						:wikitext(args['DUZ'])
				end
			end
		elseif not args['rungültige'] then
			row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext(args['gültige'] and 'Ungültige Stimmzettel' or 'Ungültige Stimmen')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form((args['abgegebene'] or wahler) - (args['gültige'] or gesamts) - (args['hungültige'] or 0)))
			row:tag('td')
				:wikitext(p.pz({(args['abgegebene'] or wahler) - (args['gültige'] or gesamts) - (args['hungültige'] or 0), wahler}))
			if args['DS1'] then
				row:tag('td')
					:wikitext(args['DU'])
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				
				row:tag('td')
					:wikitext(p.form((args['abgegebenez'] or wahlerz) - (args['gültigez'] or gesamtsz) - (args['hungültigez'] or 0)))
				row:tag('td')
					:wikitext(p.pz({(args['abgegebenez'] or wahlerz) - (args['gültigez'] or gesamtsz) - (args['hungültigez'] or 0), wahlerz}))
				if args['DSZ1'] then
					row:tag('td')
						:wikitext(args['DUZ'])
				end
			end
		end
		if args['abgegebene'] then
			row = root:tag('tr'):addClass('sortbottom')
				row:tag('td')
					:wikitext(args['gültige'] and 'Abgegebene Stimmzettel' or 'Abgegebene Stimmen')
					:attr('colspan', csp)
					:css('text-align', 'left')
					:css('font-weight', 'bold')
				row:tag('td')
					:wikitext(p.form(args['abgegebene']))
					:css('font-weight', 'bold')
				row:tag('td')
					:wikitext('&ndash;')
					:css('font-weight', 'bold')
			if args['DS1'] then
				row:tag('td')
					:wikitext('&ndash;')
					:css('font-weight', 'bold')
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				row:tag('td')
					:wikitext(p.form(args['abgegebenez']))
					:css('font-weight', 'bold')					
				row:tag('td')
					:wikitext('&ndash;')
					:css('font-weight', 'bold')
				if args['DSZ1'] then
					row:tag('td')
						:wikitext('&ndash;')
						:css('font-weight', 'bold')
				end					
			end
			row = root:tag('tr'):addClass('sortbottom')
				row:tag('td')
					:wikitext(args['gültige'] and 'Ausgefallene Stimmzettel' or 'Ausgefallene Stimmen')
					:attr('colspan', csp)
					:css('text-align', 'left')
				row:tag('td')
					:wikitext(p.form(wahler - args['abgegebene']))
				row:tag('td')
					:wikitext(p.pz({(wahler - args['abgegebene']), wahler}))
			if args['DS1'] then
				row:tag('td')
					:wikitext(args['DA'])
			end
			if zweite then
				if parl then
					row:tag('td')
				end
				if args['DM1'] then
					row:tag('td')
				end
				row:tag('td')
					:wikitext(p.form(wahlerz - args['abgegebenez']))
				row:tag('td')
					:wikitext(p.pz({(wahlerz - args['abgegebenez']), wahlerz}))
				if args['DS1'] then
					row:tag('td')
						:wikitext(args['DAZ'])
				end
			end
		end
	end
	
	if args['rungültige'] then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('th')
				:wikitext('Wähler')
				:attr('colspan', csp)
				:css('text-align', 'left')
				:css('font-weight', 'bold')
			row:tag('th')
				:wikitext(p.form(gesamts))
				:css('text-align', 'right')
				:css('font-weight', 'bold')
			row:tag('th')
				:wikitext(p.pz({gesamts, wahlberechtigte}))
				:css('text-align', 'right')
			if args['DS1'] then
				row:tag('th')
					:wikitext(args['DW'])
					:css('text-align', 'right')
			end
			if zweite then
				if parl then
					row:tag('th')
				end
				if args['DM1'] then
					row:tag('th')
				end
				row:tag('th')
					:wikitext(p.form(gesamtsz))
					:css('text-align', 'right')
					:css('font-weight', 'bold')
				row:tag('th')
					:wikitext(p.pz({gesamtsz, wahlberechtigtez}))
					:css('text-align', 'right')
				if args['DSZ1'] then
					row:tag('th')
						:wikitext(args['DWZ'])
						:css('text-align', 'right')
				end
			end
	elseif wahler then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('th')
				:wikitext('Wähler')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('th')
				:wikitext(p.form(wahler))
				:css('text-align', 'right')
			row:tag('th')
				:wikitext(p.pz({(wahler), wahlberechtigte}))
				:css('text-align', 'right')
		if args['DS1'] then
			row:tag('th')
				:wikitext(args['DW'])
				:css('text-align', 'right')
		end
		if zweite then
			if parl then
				row:tag('th')
			end
			if args['DM1'] then
				row:tag('th')
			end
			row:tag('th')
				:wikitext(p.form(wahlerz))
				:css('text-align', 'right')
			row:tag('th')
				:wikitext(p.pz({(wahlerz), wahlberechtigtez}))
				:css('text-align', 'right')
			if args['DSZ1'] then
				row:tag('th')
					:wikitext(args['DWZ'])
					:css('text-align', 'right')
			end
		end
	end
	
	if wahlberechtigte then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext('Wahlberechtigte')
				:attr('colspan', csp)
				:css('text-align', 'left')
			row:tag('td')
				:wikitext(p.form(wahlberechtigte))
			row:tag('td')
		if args['DS1'] then
			row:tag('td')
		end
		if zweite then
			if parl then
				row:tag('td')
			end
			if args['DM1'] then
				row:tag('td')
			end
			row:tag('td')
				:wikitext(p.form(wahlberechtigte))
			row:tag('td')
			if args['DSZ1'] then
				row:tag('td')
			end
		end
	end

	if args['url'] or args['quelle'] or args['quellen'] then
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:attr('colspan', cspan)
	end
	
	if args['url'] or args['quelle'] or args['quellen'] then
		quelle = ((args['url'] or args['quelle']) and 'Quelle' or 'Quellen')..': '..(args['url'] and '['..args['url']..' '..(args['quelle'] or 'Innenministerium')..']' or args['quelle'] or args['quellen'])
		row = root:tag('tr'):addClass('sortbottom')
			row:tag('td')
				:wikitext(quelle)
				:attr('colspan', cspan)
				:css('text-align', 'left')
	end


	local index = {}
	local i = 0
	for datum = 1, 50 do i = i + 1
		if args['k'..i] then table.insert(index, i) end
		if args['v'..i] == 'ja' then verzicht = true end
		if args['op'..i] then option = true end
	end

	local rootz = mw.html.create('table'):addClass('wikitable sortable')

	if args['p1'] then
		rootz
			:tag('th'):attr('colspan', '2'):wikitext('Listen'):done()
			:tag('th'):wikitext('Kandidaten'):done()
		if args['w1'] then
			rootz
				:tag('th'):wikitext('Wahlkreis'):done()
		end
		if args['s1'] then
			rootz
				:tag('th'):wikitext('Stimmen'):done()
		end

		for i, v in ipairs(index) do
			row = rootz:tag('tr')

			if args['v'..v] then
				if args['v'..v] == 'ja' then x = '&#11119; ' else x = '<sup>'..args['v'..v]..' </sup>' end
				else x = ''
			end
			if args['b'..v] then kand = x..' '..args['b'..v]..' '..args['k'..v] else
				if args['link'..v] then kand = x..'[['..args['link'..v]..'|'..args['a'..v]..' '..args['k'..v]..']]'
					else kand = x..'[['..args['a'..v]..' '..args['k'..v]..']]'
				end
			end

			if args['p'..v] then
				row:tag('td')
					:attr('rowspan', args['n'..v])
					:css('width', '0px')
					:css('background', '#'..(args['f'..v] or farbe({(args['pf'..v] or args['p'..v])})))
				row:tag('td')
					:attr('rowspan', args['n'..v])
					:wikitext(args['p'..v])
			end
			row:tag('td')
				:wikitext('<span data-sort-value="'..args['k'..v]..'">'..kand..'</span>')
			if args['w'..v] then
				row:tag('td')
					:wikitext(args['w'..v])
					:css('text-align', 'center')
			end
			if args['s'..v] then
				row:tag('td')
					:wikitext(tonumber(args['s'..v]) and mw.getLanguage('de'):formatNum(tonumber(args['s'..v])) or '&ndash;')
					:css('text-align', 'center')
			end
		end
		if verzicht or option then
			row = rootz:tag('tr'):addClass('sortbottom')
				row:tag('td')
					:attr('colspan', 4)
			if verzicht then
				row = rootz:tag('tr'):addClass('sortbottom')
					row:tag('td')
						:attr('colspan', 4)
						:wikitext('&#11119; : Verzicht auf den Sitz')
						:css('font-size', '90%')
			end
			for i, v in ipairs(index) do
				if args['op'..v] and args['opw'..v] then opt = '<span style=font-style:italic>'..args['op'..v]..'</span>: '..args['opw'..v] end
				if args['op'..v] then
					row = rootz:tag('tr'):addClass('sortbottom')
						row:tag('td')
							:attr('colspan', 4)
							:wikitext('Option '..opt)
							:css('font-size', '90%')
				end
			end
			if args['kurl'] then kquelle = 'Quelle: ['..args['kurl']..' '..args['kquelle']..']' elseif args['kquellen'] then kquelle = 'Quellen: '..args['kquellen'] end
			if args['kurl'] or args['kquellen'] then
				row = rootz:tag('tr'):addClass('sortbottom')
					row:tag('td')
						:attr('colspan', 4)
				row = rootz:tag('tr'):addClass('sortbottom')
					row:tag('td')
						:wikitext(kquelle)
						:attr('colspan', 4)
			end
		end
	end
	if args[1] and args['p1'] then return tostring(root)..tostring(rootz)..'<div style="clear:both"></div>' elseif args[1] then return tostring(root) else return tostring(rootz) end
end

return p