Module:Header

Èn årtike di Wikisource.

La documentation pour ce module peut être créée à Module:Header/doc

local p = {}
local prev_img = "Arrowleft.png"
local next_img = "Arrow2right.png"
local anonymous_values = {
	"s.n", "s.n.", "sins no",
	"o.n.c", "o.n.c.", "nén cnoxhou"
}

-- to place in a module 'table' ?
function in_table (val, tab)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

function get_link(str, NS)
	local page = mw.title.new( str, NS )
	if NS == nil then NS = "" else NS = NS .. ":" end 
	if mw.ustring.find( str, '[[', 0, true ) == nil then
		if page.exists then
			str = "[[" .. NS .. str .. "|" .. str .. "]]"
		end
	end
	return str
end

function p.init(frame)
	local args = frame.args
	local args_m = mw.getCurrentFrame():getParent().args
	
	-- i gn a des bokets d' live sins tite
	-- Indek:Augustin Vermer - Les Cahiers Wallons, 1967, num. 2, p.30-64.djvu
	if args.title == nil then
		return frame:expandTemplate{ 
			title = 'Bindea', 
			args = { sore = 'asteme', 'I vos fåt mete on tite.' }
		}	
	end
	
	local author = "s.n."
	if args.author ~= nil and args.author ~= "" then
		author = args.author
	end
	
	local year = "{{s.d.}}"
	if args.year ~= nil and args.year ~= "" then
		if tonumber(args.year) ~= nil then
			year = "{{date|"..args.year.."}}"
		else
			year = args.year
		end
	end
	
	local section = nil
	if args.section ~= nil and args.section ~= "" then
		section = args.section
	else
		section = args.title
	end
	
	local html = mw.html.create("div")
	html:attr({ 
		id = "headertemplate",
		class = "ws-noexport"
	})

	-- templatestyle
	if frame.extensionTag ~= nil then
		html:node(frame:extensionTag{ 
			name = 'templatestyles', 
			args = { src = 'Tiestire/styles.css' } }
		)
	end
	
	local div_info = mw.html.create("div")
	div_info:attr("class", "ht-info")
	
	local div_info_author = mw.html.create("div")
	div_info_author:attr("class", "ht-author")
	div_info_author:wikitext(get_link(author, "Oteur"))
	div_info:node(div_info_author)
	
	local div_info_section = mw.html.create("div")
	div_info_section:attr("class", "ht-section")
	div_info_section:wikitext(section)
	div_info:node(div_info_section)
	
	if (args.original ~= nil and args.original ~= "") then
		local div_info_original = mw.html.create("div")
		div_info_original:attr("class", "ht-original")
		div_info_original:wikitext("« " .. args.original .. " »")
		div_info:node(div_info_original)
	end
	
	if (args.translator ~= nil and args.translator ~= "") or 
	   (args.respelling ~= nil and args.respelling ~= "") then
		translation_txt = ''
		if args.translator ~= "" then 
			if in_table(args.translator, anonymous_values) then
			  	translation_txt = translation_txt .. "ratournaedje d’ ene djin nén cnoxhowe"
			else
				translation_txt = translation_txt .. "ratournaedje da " .. args.translator
			end
		end
		if args.respelling ~= "" then 
			if translation_txt ~= nil and translation_txt ~= "" then 
				translation_txt = translation_txt .. " et "
			end
			if in_table(args.respelling, anonymous_values) then
			  	translation_txt = translation_txt .. "rortografiaedje d’ ene djin nén cnoxhowe"
			else
				translation_txt = translation_txt .. "rortografiaedje da " .. args.respelling
			end
		end
		
		local div_info_translator = mw.html.create("div")
		div_info_translator:attr("class", "ht-translator")
		div_info_translator:wikitext(translation_txt)
		div_info:node(div_info_translator)
	end
	
	local div_info_year = mw.html.create("div")
	div_info_year:attr("class", "ht-year")
	if args.section ~= nil and args.section ~= "" and args.title ~= "" then
		div_info_year:wikitext("''"..get_link(args.title) .. "'', ")
	end
	if args.editor ~= nil and args.editor ~= "" then
		div_info_year:wikitext(args.editor .. ", ")
	end
	if args.volume ~= nil and args.volume ~= "" then
		local volume = frame:expandTemplate{ 
			title = 't.', 
			args = { args.volume }
		}	
		div_info_year:wikitext(volume .. ", ")
	end
	div_info_year:wikitext(frame:preprocess(year))
	div_info:node(div_info_year)
	
	html:node(div_info)
	
	local nav_prev = nil
	local nav_next = nil
	if args.prev ~= nil and args.prev ~= "" then 
		nav_prev = args.prev 
	end
	if args.next ~= nil and args.next ~= "" then 
		nav_next = args.next 
	end
	
	if nav_prev ~= nil or nav_next ~= nil then
		local div_nav = mw.html.create("div")
		div_nav:attr("class", "ht-nav")

		local div_prev = mw.html.create("div")
		div_prev:attr("class", "ht-prev")
		if nav_prev ~= nil then
			div_prev:wikitext("[[File:" .. prev_img .."|20px|link=]]")
			div_prev:wikitext(nav_prev)
		end
		
		local div_curr = mw.html.create("div")
		div_curr:attr("class", "ht-curr")
		
		local div_next = mw.html.create("div")
		div_next:attr("class", "ht-next")
		if nav_next ~= nil then
			div_next:wikitext(nav_next)
			div_next:wikitext("[[File:" .. next_img .."|20px|link=]]")
		end
		
		div_nav:node(div_prev)
		div_nav:node(div_curr)
		div_nav:node(div_next)
		html:node(div_nav)
	end

	if mw.title.getCurrentTitle().namespace == 0 then
		-- detect subpages
		if mw.ustring.find( mw.title.getCurrentTitle().text, '/', 0, true ) ~= nil then
			html:wikitext("[[Categoreye:Dizo-pådjes]]")
		end
		
		-- detect tipo apostrophe
		if mw.ustring.find( mw.title.getCurrentTitle().text, "'", 0, true ) ~= nil then
			html:wikitext("[[Categoreye:Årtikes ki fåt mete ene apostrofe-crolete]]")
		end
	end
	
	-- test args
	for i, v in pairs(args_m) do
		local args_p = {
			"tite", "oteur", "eplaideu", "eplaidaedje", 
			"ratourneu", "ratournaedje", "aneye", "anêye", "oridjinå", "tome",
			"seccion", "divant", "shuvant", "rortografiaedje", "rortografieu"
		}
        if not in_table(i, args_p) then
            html:wikitext("[[Categoreye:Årtikes avou des parametes nén ricnoxhous dins l' tiestire]]")
        end
	end
	
	return html
end

return p