Mòdul que construeix la capçalera de la plantilla {{Header}}.

Els paràmetres poden informar-se a mà, o bé ser capturats des d'un Índex, o bé ser capturats des de Wikidata.

El mòdul és cridat amb el següent codi:

{{#invoke:Header|header}}


-------------------------------------------------------------------------
-- Construcció de la capçalera
-- Adaptat de https://es.wikisource.org/wiki/Module:Encabezado
-------------------------------------------------------------------------
local p = {}
local Wikidata = require('Module:Wikidata')
local Args = require('Module:Arguments')
local categories = ''

local params = { --1 = vigent, 0 = obsolet. Per ordre alfabètic:
	['any']=1,['autor']=1,['compositor']=1,['current']=1,['editor']=1,['footer']=1,['from']=1,
	['header']=1,['imatge']=1,['idioma']=1,['ilustrador']=1,['index']=1,['info']=1,['lloc']=1,
	['next']=1,['nivell']=1,['nomcategoria']=1,['prev']=1,['qid']=1,
	['subtitol']=1,['sumari']=1,['titol']=1,['to']=1,['traductor']=1,['value']=1,
}
local altparams= {['anterior']='prev',['il·lustrador']='ilustrador',
	['següent']='next',['subtítol']='subtitol',['sub-títol']='subtitol',['títol']='titol',
}
local function alias(args, altTable)
	local _args = {}
	for k, v in pairs(args) do
		k = mw.ustring.lower(tostring(k))
		if altTable[k] then
			_args[altTable[k]] = v
		else
			_args[k] = v
		end
	end
	return _args
end
function errorMessage(text)
	local html = mw.html.create('div')
	html:addClass('error')
		:wikitext(text)
	categories=categories..'[[Categoria:Pàgines amb errors diversos|E]]'
	return tostring(html)
end
local function delink(s)
	if not s:match("%[") then
		return s
	end
    local result = s
    result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
    result = mw.text.decode(result, true) -- decode HTML entities.
    -- Remove the colon if the link is using the [[Help:Colon trick]].
    if result:match("%[%[:") then
        result = "[[" .. result:match("%[%[:(.*%]%])")
    end
    -- Find the display area of the wikilink
    if result:match("|") then -- Find if we're dealing with a pipecd link.
        result = result:match("%[%[.-%|(.+)%]%]")
        -- Remove new lines from the display of multiline piped links,
        -- where the pipe is before the first new line.
        result = result:gsub("\n", "")
    else     
    	result = result:match("%[%[(.-)%]%]")
    end
    return result
end
function microformat(d, argus)
	local microformat = mw.html.create('div')
			:cssText('display:none')
			:attr('id', 'ws-data')
			:addClass('ws-noexport')
	--Exclosos: compositor, subtitol... vegeu [[:old:Wikisource:Microformat]]
	microformat:node( linkMicroformat( 'title', d.titol ) )
    if d.autor then
        microformat:node( linkMicroformat( 'author', d.autor ) )
    end
    if d.traductor then
        microformat:node( linkMicroformat( 'translator', d.traductor ) )
    end
    if d.ilustrador ~= '' then
        microformat:node( linkMicroformat( 'illustrator', d.ilustrador ) )
    end
    if d.editor ~= '' then
        microformat:node( linkMicroformat( 'publisher', d.editor ) )
    end
	if d.any then
        microformat:node( linkMicroformat( 'year', d.any ) )
    end
    if d.lloc ~= '' then
        microformat:node( linkMicroformat( 'place', d.lloc ) )
    end
    if d.nivell ~= '' then
        microformat:node( linkMicroformat( 'progress', d.nivell ) )
    end
    if d.volum ~= '' then
        microformat:node( linkMicroformat( 'volume', d.volum ) )
    end
    if d.index then
        microformat:node( linkMicroformat( 'scan', d.index ) )
        if d.imatge ~= '' then
            microformat:node( linkMicroformat( 'cover', d.index .. '/' .. d.imatge ) )
        end
    end
    if argus.sumari and argus.sumari ~= '' then
        microformat:tag('div')   --no pot ser span
        :addClass('ws-summary')
        :wikitext(argus.sumari)	
    end
    return tostring(microformat)
end
function linkMicroformat(param, valor)
	if valor and valor ~= '' then
		return mw.html.create('span')
        :addClass('ws-' .. param)
        :wikitext(delink(valor))	
	else return '' end
end
function resoldreWikidataImatge(argus, parametro)
	local ws = argus[parametro]	--imatge
	if not ws or ws == '' then
		ws = '1'
		if not argus['qid'] or argus['qid'] == '' then return ws end
		if not argus['index'] or argus['index'] == '' then return ws end
		local FileOnCommonsStmts = mw.wikibase.getAllStatements (argus['qid'], 'P996');
		if FileOnCommonsStmts then
			for _, stmt in pairs( FileOnCommonsStmts ) do
				local commonsFilename = stmt['mainsnak']['datavalue']['value']	--=argus['index']
				if commonsFilename and commonsFilename ~= '' then
					--Cal decodificar nompag, per exemple, per l'apòstrof "'" arriba com "'"
					if mw.text.decode(argus['index']) == commonsFilename then
						ws = Wikidata.claim{item=qid, property="P996", qualifier="P4714", lang="ca", list=false, editicon=false}
					end
				end
			end
		end
	end
	if not ws or ws == '' then ws = '1' end
	if ws and ws~= '' then return ws end
end
function resoldreWikidataProgress(argus, parametro)
	local ws = argus[parametro]	--nivell
	if not ws or ws == '' then
		ws = "I"
		if not argus['qid'] or argus['qid'] == '' then return ws end
		local badges = require("Module:Edition").badge{args={qid=argus['qid']}}
		if badges and badges ~='' then
			if badges == "Q20748093" then ws = "V" end
			if badges == "Q20748092" then ws = "R" end
			if badges == "Q20748091" then ws = "I" end
			if badges == "Q20748094" then ws = "E" end
		end
	end
	if ws and ws~= '' then return ws end
end
function resoldreWikidata(argus, parametro, PID)
	local ws = argus[parametro]
	if not ws or ws == '' then
    	ws = Wikidata.claim{item=argus['qid'], property=PID, lang="ca", list=false, editicon=false}
	end
	if ws and ws~= '' then return ws end
end
function resoldreWikidataPersona(argus, parametro, PID)
	local ws = argus[parametro]
	if not ws or ws == '' then
    	ws = Wikidata.claim{item=argus['qid'], property=PID, lang="ca", list=true, editicon=false}
	end
	if ws and ws~= '' then return ws end
end
function consolidat(argus)	-- Si no s'ha informat, captura la dada de Wikidata
	local data = {}
    local props = {
    	any 		= {'any', 'P577'},
    	autor		= {'autor','P50', true},	--todo: else P2093
    	editor		= {'editor', 'P123'},
    	ilustrador	= {'ilustrador', 'P110', true},
    	imatge		= {'imatge', true, true, true, true},
    	index		= {'index', 'P996'},
    	lloc		= {'lloc', 'P291'},
    	nivell		= {'nivell', true, true, true},
    	subtitol	= {'subtitol', 'P1680'},
    	titol		= {'titol', 'P1476'},
    	traductor	= {'traductor', 'P655', true},
    	volum		= {'volum', 'P478'},
    }
	for k, v in pairs(props) do
		if v[5] then
			data[k] = resoldreWikidataImatge(argus, v[1])
		elseif v[4] then
			data[k] = resoldreWikidataProgress(argus, v[1])
		elseif v[3] then
			data[k] = resoldreWikidataPersona(argus, v[1], v[2])
		else
			data[k] = resoldreWikidata(argus, v[1], v[2])
		end
	end
	return data
end
--=p.header({qid='Q19529123',prev="[[../Capítol 48|Capítol 48]]"})
--=p.header({current='mig',prev='antes',next='luego',titol='El Títol',subtitol='El subtítol',autor='Autor',info='això és una nota'})
function p.header( frame )

    local titol = mw.title.getCurrentTitle()
	local essub = titol.isSubpage
	local linkPagina  = mw.title.getCurrentTitle().text
	local textoenlace = mw.uri.encode(linkPagina,QUERY)

    local argus = Args.getArgs(frame)
	argus = alias(argus, altparams)
	local d = consolidat(argus)
	
	-- estructura HTML
    local html = mw.html.create()
    local divPrincipal = html:tag('div')
    	:attr('id','headerContainer')
    	:addClass('noprint ws-noexport')
    	:css('background', '#eff5f9')
    	:css('display', 'table')
		:css('width', '95%')
    	:css('text-align', 'center')
    	:css('padding', '1em')
    	:css('border-top', '1px solid #aaaaaa')
    	:css('border-bottom', '8px solid #355291')

	local divMig = divPrincipal:tag('div')
		:addClass('middle-div')
		:css('width', '95%')
		:css('display', 'table-cell')
		:css('vertical-align', 'middle')

	if argus['current'] and argus['current'] ~= '' then
    	divMig:wikitext('Sou a «'.. argus['current'] ..'»<br />')
	end

    if not d.titol then d.titol = textoenlace end
   	divMig:wikitext('<span style="font-size:125%;"><b>' .. d.titol .. '</b></span><br />')

	if not essub then
	  	if d.subtitol then
   			divMig:wikitext(d.subtitol ..'<br />')	
	  	end
   	end

	if d.autor then
		divMig:wikitext(d.autor ..'<br>')
	end
	
    if d.traductor then
    	for _,v in ipairs(mw.text.split(d.traductor, '[/,]')) do
			if delink(v) == 'Anònim' then
				categories = categories..'[[Categoria:Texts anònims]]'
			end
		end
    	divMig:wikitext('(traduït per '..d.traductor..')<br>')
    end
    
   	if d.any and not argus['noany'] then
   		divMig:wikitext(' ('.. d.any ..')')
   	end

    local divMigInf = divMig:tag('div'):addClass('noprint plainlinks lower-div')

	local divInfo = divMigInf:tag('span')
		:attr('id','headerinfo')
    	:css('background-color','#eff5f9')
		:css('text-align','center')
		:css('font-size','80%')
		
	if argus['info'] and argus['info'] ~= '' then
		divInfo:wikitext(argus['info'])
	end
	
	local LinkExport  = 'https://ws-export.wmcloud.org/?lang=ca&page='..textoenlace..'&format='
	local w = '<br /><span style=\"font-size:80%\">'
	w = w .. 'Baixa com a &nbsp;[[File:EPUB silk icon.svg|12px|link='..LinkExport..'epub|Baixa com a ePub]]'
	w = w .. '&nbsp;[[File:Document-pdf.svg|15px|link='..LinkExport..'pdf|Baixa com a PDF]]'
	w = w .. '&nbsp;[[File:Mobi_icon.svg|22px|link='..LinkExport..'mobi|Baixa com a mobi]]</span>'
	divMigInf:wikitext(w)

	local divFinal = divMig:tag('div')
		:attr('id', 'header-final')
    	:addClass('noprint ws-noexport')
    	:css('display', 'table')
		:css('width', '100%')

	local divPrev = divFinal:tag('div')
		:attr('id','headerprevious')
		:css('padding', '0')
		:css('display', 'table-cell')
		:css('vertical-align', 'bottom')
		:css('align', 'float-left')
		:css('text-align', 'left')
	
	local divNext = divFinal:tag('div')
		:attr('id','headernext')
		:css('padding', '0')
		:css('display', 'table-cell')
		:css('vertical-align', 'bottom')
		:css('align', 'float-right')
		:css('text-align', 'right')

	if argus['prev'] and argus['prev'] ~= '' then
		divPrev:wikitext('[[Fitxer:Breezeicons-actions-22-go-previous.svg|30px|link=]] '..argus['prev'])
	end
    if argus['next'] and argus['next'] ~= '' then
		divNext:wikitext(argus['next'] .. ' [[Fitxer:Breezeicons-actions-22-go-next.svg|30px|link=]]')
	end

	if titol.namespace == 0 then --només namespace principal
	    if argus['nomcategoria'] and argus['nomcategoria'] ~= '' then
		    if argus['nomcategoria'] == 'cap' then
			else
	 			categories = categories..'[[Categoria:' .. argus['nomcategoria'] .. ']]'
	    	end
	 	else
			categories = categories..'[[Categoria:' .. titol.rootText .. ']]'
    	end
	    if argus['idioma'] and argus['idioma'] ~= '' then
 			categories = categories..'[[Categoria:Texts originalment en '..argus['idioma']..']]'
		end
	end

    for k,v in pairs(argus) do
		if params[k] or altparams[k] then
			if params[k] == 0 then
				categories = categories..'[[Categoria:Pàgines amb errors diversos|K]]'
			end
		else
			html:wikitext(errorMessage('Error: paràmetre '..k..' no reconegut'))
			categories=categories..'[[Categoria:Pàgines amb errors diversos|P]]'
		end
	end
	
	html:wikitext(categories)

	html:wikitext(microformat(d, argus))

    return tostring(html)

end
return p