Mòdul:Autor
Aparença
Mòdul per a la plantilla {{Autor}}.
Funcions:
infotaula
[modifica]Construeix la taula amb les dades d'un autor.
Sintaxi:
{{#invoke:Autor|infotaula}}
--------------------------------------------------------------------------------
-- Adaptat de https://ca.wikiquote.org/wiki/Mòdul:Persona
-- (versió «10:26, 24 juny 2026 Docosong»)
--------------------------------------------------------------------------------
local p = {}
-- Funció auxiliar de seguretat per fer preprocessos controlats
local function safePreprocess(frame, text)
local success, result = pcall(frame.preprocess, frame, text)
return success and result or ""
end
-- Funció auxiliar per triar el primer paràmetre manual amb text
local function obtenirArg(args, llista)
for _, nom in ipairs(llista) do
if args[nom] and args[nom] ~= '' then return args[nom] end
end
return nil
end
-- Funció nativa per obtenir dades de Wikidata netes i sense intermediaris
local function obtenirValorWD(itemId, propietat)
if not itemId or itemId == '' then return "" end
local statements = mw.wikibase.getBestStatements(itemId, propietat)
if statements and statements[1] and statements[1].mainsnak and statements[1].mainsnak.datavalue then
local value = statements[1].mainsnak.datavalue.value
if type(value) == "table" then
return value.id or value.time or ""
elseif type(value) == "string" then
return value
end
end
return ""
end
function p.infotaula(frame)
local args = frame:getParent().args
local item = args['item'] or ''
if item == '' then
local entitat = mw.wikibase.getEntityObject()
if entitat then item = entitat.id end
end
local dades = {
titlestyle = 'background-color: #d6d6c2; color:black; text-align:center;',
abovestyle = 'background-color: #d6d6c2; color:black; text-align:center; padding:2px; font-size:110%;',
headerstyle = 'background: #d6d6c2; color:black; text-align:center; padding:5px;',
datastyle = 'text-align:left'
}
-- Clau d'ordenació
local Ordenar = obtenirArg(args, {'Ordenar', 'ordenar'}) or ''
local p735 = (item ~= '') and obtenirValorWD(item, 'P735') or ''
local p734 = (item ~= '') and obtenirValorWD(item, 'P734') or ''
if Ordenar == '' then
if p734 ~= '' then
local Cognom = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P734 | list=false | formatting=label | item=' .. item .. '}}')
if Cognom ~= '' then Ordenar = Cognom end
elseif (Ordenar == '' and p735 ~= '') then
local Prenom = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P735 | list=false | formatting=label | item=' .. item .. '}}')
if Prenom ~= '' then Ordenar = Prenom end
end
end
local CategoriesAutor = ''
if Ordenar ~= '' then
CategoriesAutor = '[[Categoria:Autors-' .. mw.ustring.upper(mw.ustring.sub(Ordenar, 1, 1)) .. ']]'
end
-- Connexió a Wikidata
local ConnexioWD
local PagWD = mw.wikibase.getSitelink(item, 'cawikisource') or ''
if PagWD == '' then
ConnexioWD = '[[Categoria:Pàgines d\'autor no connectades amb Wikidata]]'
else
ConnexioWD = '[[Categoria:Pàgines d\'autor connectades amb Wikidata]]'
end
if Ordenar ~= '' then
CategoriesAutor = CategoriesAutor .. ConnexioWD
else
CategoriesAutor = ConnexioWD
end
-- Títol i Imatge principal
local nomPagina = obtenirArg(args, {'nom', 'Nom'}) or safePreprocess(frame, '{{PAGENAME}}')
dades['title'] = '<span style="float:left; margin-left:6px;">[[image:Simpleicons Interface user-outline.svg|20px|link=]]</span>' .. nomPagina .. CategoriesAutor
local img = obtenirArg(args, {'imatge', 'image'}) or (item ~= '' and obtenirValorWD(item, 'P18')) or ''
if img ~= '' then
local codiImg = '{{#invoke:InfoboxImage|InfoboxImage | image=' .. img .. ' | size=' .. (args['mida_imatge'] or '225px') .. ' | sizedefault=frameless | upright=1 | alt=' .. (args['alt'] or '') .. ' | suppressplaceholder=yes}}'
dades['image'] = '<div class="ombreig">' .. safePreprocess(frame, codiImg) .. '</div>'
end
if obtenirArg(args, {'imatge', 'image'}) and obtenirArg(args, {'peu', 'descripció'}) then
dades['caption'] = obtenirArg(args, {'peu', 'descripció'})
elseif item ~= '' and img ~= '' then
local captionWD = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P18 | qualifier=P2096 | list=lang | item=' .. item .. '}}')
--Per treure possibles enllaços (no funciona amb Delink):
captionWD = mw.text.decode(captionWD) --Treu entitats HTML
captionWD = mw.text.killMarkers(captionWD):gsub("<[^>]+>", "") -- Treu etiquetes HTML
captionWD = captionWD:gsub("%[%[[^%]]*%|([^%]%]]*)%]%]", "%1") --'[[Enllaç|Text 1]] => "Text 1"'
captionWD = captionWD:gsub("%[%[([^%]%]]*)%]%]", "%1") --'[[Text]] => Text'
dades['caption'] = mw.text.trim(captionWD)
end
-- SECCIÓ: Projectes germans
dades['header1'] = 'Projectes germans'
if item ~= '' then
dades['data3'] = '<span style="padding:5px;">[[Fitxer:Wikidata-logo.svg|20px|enllaç=]] Metadades a \'\'\'[[d:' .. item .. '|Wikidata]]\'\'\'</span>'
local wp = mw.wikibase.getSitelink(item, 'cawiki') or ''
if wp ~= '' then dades['data4'] = '<span style="padding:5px;">[[Fitxer:Wikipedia-logo-v2.svg|20px|link=]] Biografia a la \'\'\'[[w:' .. wp .. '|Viquipèdia]]\'\'\'</span>' end
local wq = mw.wikibase.getSitelink(item, 'cawikiquote') or ''
if wq ~= '' then dades['data5'] = '<span style="padding:5px;">[[Fitxer:Wikiquote-logo.svg|20px|enllaç=]] Dites i citacions a \'\'\'[[q:' .. wq .. '|Viquidites]]\'\'\'</span>' end
end
local p373 = (item ~= '') and obtenirValorWD(item, 'P373') or ''
if p373 ~= '' then
local cm = obtenirArg(args, {'Wikicommons', 'Commons'}) or (item ~= '' and safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P373 | list=false | item=' .. item .. ' }}')) or ''
if cm ~= '' then dades['data7'] = '<span style="padding:5px;">[[Fitxer:Commons-logo.svg|20px|link=]] Multimèdia a \'\'\'[[commons:Category:' .. cm .. '|Commons]]\'\'\'</span>' end
end
-- SECCIÓ: Dades biogràfiques
dades['header9'] = 'Dades biogràfiques'
local p19 = (item ~= '') and obtenirValorWD(item, 'P19') or ''
local p569 = (item ~= '') and obtenirValorWD(item, 'P569') or ''
local p20 = (item ~= '') and obtenirValorWD(item, 'P20') or ''
local p570 = (item ~= '') and obtenirValorWD(item, 'P570') or ''
local p742 = (item ~= '') and obtenirValorWD(item, 'P742') or ''
-- Naixement
if p19 ~= '' or p569 ~= '' then
dades['label11'] = 'Naixement'
local elementsNaix = {}
if p19 ~= '' then table.insert(elementsNaix, safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P19 | list=false | item=' .. item .. ' | formatting=label}}')) end
if p569 ~= '' then
local dataTxt = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P569 | list=false | formatting= j xg "de" Y | item=' .. item .. '}}')
table.insert(elementsNaix, dataTxt)
end
dades['data11'] = table.concat(elementsNaix, ', ')
end
-- Mort
if p20 ~= '' or p570 ~= '' then
dades['label13'] = 'Mort'
local elementsMort = {}
if p20 ~= '' then table.insert(elementsMort, safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P20 | list=false | item=' .. item .. ' | |formatting=label}}')) end
if p570 ~= '' then
local dataTxt = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P570 | list=false | formatting= j xg "de" Y | item=' .. item .. '}}')
table.insert(elementsMort, dataTxt)
end
dades['data13'] = table.concat(elementsMort, ', ')
end
-- Pseudònim
if p742 ~= '' then
dades['label14'] = 'Pseudònim'
dades['data14'] = safePreprocess(frame, '{{#invoke:Wikidata | claim | property=P742 | list=false | formatting=label | item=' .. item .. '}}')
end
-- SECCIÓ: Drets d'autor
if item ~= '' then
local Drets = ''
local TextFinal = ''
local LogoPD = '[[Fitxer:Icon PD.svg|20px|link=]]'
local LogoCR = '[[Fitxer:Red copyright.svg|20px|link=]]'
local claimsCopyright = mw.wikibase.getBestStatements(item, 'P7763')
if claimsCopyright and claimsCopyright[1] and claimsCopyright[1].mainsnak.datavalue then
local idCopyright = claimsCopyright[1].mainsnak.datavalue.value.id
if idCopyright == 'Q71887839' then
Drets = 'PD'
TextFinal = LogoPD .. ' Els drets d\'autor [[:d:' .. item .. '#P7763|han expirat]]'
elseif idCopyright == 'Q50423863' then
Drets = 'CR'
TextFinal = LogoCR .. ' Els drets d\'autor [[:d:' .. item .. '#P7763|no han expirat]]'
end
end
if Drets == '' then
if p570 ~= '' then
local anyMort = tonumber(string.match(p570, "%d%d%d%d")) or 0
local anyActual = tonumber(os.date('%Y')) --or 2026
if (anyMort > 0 and (anyActual - anyMort) > 100) then
TextFinal = LogoPD .. ' Els drets d\'autor han expirat (100 p.m.a.)'
elseif (anyMort > 0 and (anyActual - anyMort) > 80) then
TextFinal = LogoPD .. ' Els drets d\'autor han expirat (80 p.m.a.)'
elseif (anyMort > 0 and anyMort > 1995 and (anyActual - anyMort) > 70) then
TextFinal = LogoPD .. ' Els drets d\'autor han expirat (70 p.m.a.)'
else
TextFinal = LogoCR .. ' Els drets d\'autor no han expirat encara'
end
else
TextFinal = LogoCR .. ' Els drets d\'autor no han expirat' --viu
end
end
dades['header18'] = "Drets d'autor [[Fitxer:Commons-emblem-notice.svg|20px|link=Viquitexts:Drets d\'autor]]"
dades['data19'] = TextFinal
end
return frame:expandTemplate{ title = 'Infotaula', args = dades }
end
return p