Modul:Vorlage:Babel

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

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:Babel/Doku erstellt werden

-- Babel -- 20150708
-- ursprünglich aus der Esperanto-Wikipedia, aber von Tlustulimu teilweise nach dem 
-- englischen Modul angepaßt, weil anders der erste unbenannte Parameter nicht
-- wie gewünscht funktionierte.

function subtitle(text)
	-- This function builds subtitles in the box
				local sub_title = mw.html.create('table')
				  :css('text-align','center')
				  :css('width','100%')
				  :css('margin','0 auto')
				local row =  sub_title:tag('tr')
				local sub_title_cell =  row:tag('th')
				   :css('background-color','#EEFFCC')
				   :css('border','1px dotted #FFCC99')
				   :css('padding','0.3em')				   
				   :wikitext(text)
				   :done()
				-- sub_title:done()
				return tostring(sub_title)
end	


local p = {}

function p.babel(frame)  
	-- This function builds the babel box used by the {{babel}} template.
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	--local args = getArgs(frame, {wrappers = 'Template:Babel'})
	local args = getArgs(frame, {wrappers = 'Benutzer:Tlustulimu/Vorlage:Babel'})

	local tab = ""
	local frame = mw.getCurrentFrame()	
	local first = false
	if args[1] and args[1]:find('%S') then
		first = true
	end
	
	-- variables for the babel cells
	local t1 = "<tr><td>"
	local t2 = "</td></tr>"
	local mf = args.mw or "{{GENDER:{{BASEPAGENAME}}|m|w|}}"
	
	-- "remove" args[1] so it isn't looked at in the loop
	-- table.remove(args,1) doesn't produce desired result
	if first == false then
		args[1] = ''	
	end	
	
	-- creates the table cell's beginning
	tab = tab .. t1

	-- Keep track of how many columns are in this table
	local col_span = 1
	for _, v in ipairs( args ) do
		-- ! indicates a new cell should be created
		if v:find('%S') and v ~= '!' then
			if mw.ustring.sub(v,1,2) == "[[" then
				tab = tab .. v 
			elseif mw.ustring.sub(v,1,2) == "{{" and mw.ustring.sub(v,1,3) ~= "{{{" then	
				tab = tab .. v 
			elseif mw.ustring.sub(v,1,1) == "<" then
				tab = tab .. v 
			-- converts the text with ## at the begining into subtitle	
			elseif mw.ustring.sub(v,1,2) == "##" then
				v = mw.ustring.sub(v,3)
				tab = tab .. subtitle(v) 
			-- code for {{#Babel, because the parser analyzed this before Lua can work			
			elseif mw.ustring.sub(v,1,3) == "#b#" or mw.ustring.sub(v,1,3) == "#B#"	then
				local v = mw.ustring.sub(v,4) 
				-- removes the internal links 
				v = mw.ustring.gsub(v,"%[%[Project:Babel%|Babel – Benutzerinformationen%]%]","",1)
				v = mw.ustring.gsub(v,"%[%[:Kategorie:Benutzer:nach Sprache%|Benutzer nach Sprache%]%]","",1)				
				v = '<div style="width:246px; float:left;">' .. v .. "</div>"
				tab = tab .. v
				
			else	
				tab = tab .. frame:preprocess('{{User '..v.. '|mw=' .. mf .. '}}') 
			end
		-- Recycling body_cells for <td>
		elseif v and v == '!' then
			col_span = col_span + 1
			tab = tab .. '</td><td>' -- end of the table cell and beginn of a new one, for more then one column
--			body_cells = row2:tag('td')
		end
	end

	-- creates the title line of the table
	local fl = args.float or args.align or ""
	local color = args.color or ""
	local header = ""
	local t = args.titel or args.Titel or '[[Wikipedia:Babel|Babel:]]'	
	local c = ""
	local c2 = ""
	if color ~= "" then
		c = 'style="background-color:' .. color .. ';" '
		c2 = 'style="background-color:' .. color .. '; " | '		
	end
	local margin = ""
	-- correction of the left and right margins, if the box is floated to the left side
	if fl == "left" then
		margin = "margin-left:0; margin-right:1em;"
	end
	if first == true then
		-- code from the template {{Babel-HTML-Kopf}}, but with added width
		header = '<table style="width:248px; ' .. frame:preprocess('{{Babel-Style|float=' .. fl .. '}}') .. margin .. '" id="userboxes">'
		if col_span > 1 then
			header = header .. '<tr><th ' .. c .. 'colspan="' .. col_span .. '">' .. t .. '</th></tr>' 
		else
			header = header .. '<tr><th ' .. c .. '>' .. t .. '</th></tr>' 
		end
		tab = header .. tab
	else
		-- code from the template {{Babel-Kopf}}, but with added width
		header = '{| style="width:248px; ' .. frame:preprocess('{{Babel-Style|float=' .. fl .. '}}') .. margin .. '" id="userboxes"'
		if col_span > 1 then
			header = header .. '\n! ' .. c .. 'colspan="' .. col_span .. '" | ' .. t			
		else
			header = header .. '\n! ' .. c2 .. t
		end
		tab = header .. "\n" .. tab		
	end	


	
	-- for user according to the location (country, town, village etc.)
	local maxaus = 20
	for i = 1, maxaus do
		local a = args['aus' .. i] or ""
		if a ~="" then
			-- for a title before the location
			local title = args['aus' .. i .. "-titel"] or ""
			if title ~= "" then
				tab = tab .. subtitle(title) 				
			end
			tab = tab .. frame:preprocess('{{Benutzer:Vorlage/aus ' .. a .. '}}') 
		end
	end	

	-- for special boxes
	local maxspec = 15
	if args['Spezialbox'] then
			-- for a title before the special box
			local title = args['Spezialbox-titel'] or ""
			if title ~= "" then
				tab = tab .. subtitle(title) 				
			end		
		local s = args['Spezialbox']		
		tab = tab .. s 
	end
	for i = 2, maxspec do
		local s = args['Spezialbox' .. i] or ""
		if s ~="" then
			-- for a title before the special box
			local title = args['Spezialbox' .. i .. "-titel"] or ""
			if title ~= "" then
				tab = tab .. subtitle(title) 				
			end				
			tab = tab .. s 
		end
	end	

 

	-- code for the template {{Benutzer SUL}}
	if args['SUL-Projekt'] ~= nil and args['SUL-Projekt'] ~= "" then
			local p = args['SUL-Projekt']
			local l = args['SUL-Sprache'] or ""
			-- for title before the information about the user's SUL
			local title = args['SUL-Titel'] or ""
			if title ~= "" then
				tab = tab .. subtitle(title)
			end				
			tab = tab .. frame:preprocess('{{Benutzer SUL|1=' .. l .. '|2=' .. p 
				.. '}}') 
	end		

	-- creates the table cell's end
	tab = tab .. t2
	if color ~= "" then
		c = "background-color:" .. color .. ";"
	end	
	if args['Fußzeile'] or args['fußzeile'] then
		local f = args['Fußzeile'] or args['fußzeile']
		if col_span > 1 then
			tab = tab .. '<tr><td colspan="' .. col_span .. '" style="text-align:center;' .. c .. '">' .. f .. t2
		else	
			tab = tab .. '<tr><td style="text-align:center; ' .. c .. '">' .. f .. t2
		end
	else
		if first == true then
			local kat = "'''[[:Kategorie:Benutzer:nach Sprache|Benutzer nach Sprache]]'''"
			if col_span > 1 then
				tab = tab .. '<tr><td colspan="' .. col_span .. '" style="text-align: center; ' .. c .. '">' .. kat .. t2
			else
				tab = tab .. '<tr><td style="text-align: center; ' .. c .. '">' .. kat .. t2
			end
		end
	end
	
 	-- creates the end of the table
 	if first == true then
		tab = tab .. "</table>"
 	end
 
	return tostring(tab)
	
end

return p