Modulo:Autore: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
fix "Pagine in cui è citato..." |
supporto per Wikipedia in inglese come da discussione |
||
Riga 175: | Riga 175: | ||
-- collegamento a Wikipedia in italiano |
-- collegamento a Wikipedia in italiano |
||
function wikipedia() |
function wikipedia() |
||
local lang = nil |
|||
⚫ | |||
local sl = sitelink('itwiki') |
|||
if args['Nome della pagina su Wikipedia'] == nil and sl == nil and sitelink('enwiki') then |
|||
lang = 'en' |
|||
sl = sitelink('enwiki') |
|||
end |
|||
⚫ | |||
end |
end |
||
Riga 375: | Riga 381: | ||
end |
end |
||
local wp = wikipedia() |
local wp_lang, wp = wikipedia() |
||
local com = commons() |
local com = commons() |
||
local comCat = (commonsCat() or '') |
local comCat = (commonsCat() or '') |
||
Riga 482: | Riga 488: | ||
-- INTERPROGETTO |
-- INTERPROGETTO |
||
add(tostring(mw.html.create('div'):css('margin-top', '15px') |
add(tostring(mw.html.create('div'):css('margin-top', '15px') |
||
:wikitext(frame:expandTemplate{ title = 'Interprogetto', args = { wAutore = wp, qAutore = wq, nAutore = wn, CommonsAutore = com, commons = comCat } }))) |
:wikitext(frame:expandTemplate{ title = 'Interprogetto', args = { wAutore = wp, wAutore_lang = wp_lang, qAutore = wq, nAutore = wn, CommonsAutore = com, commons = comCat } }))) |
||
if args.Nome ~= 'Anonimo' then |
if args.Nome ~= 'Anonimo' then |
Versione delle 07:42, 9 ago 2014
Questo modulo serve al {{Autore}} per generare l'incipit e le categorie delle pagine in cui è utilizzato, integrando informazioni da Wikidata quando possibile.
local p = {}
local attrs = {
nome = 'Nome',
cognome = 'Cognome',
altroNome = 'Eventuale altro nome',
pseudonimo = 'Eventuale pseudonimo',
nomeReale = 'Eventuale nome reale',
giornoMeseNascita = 'Giorno e mese di nascita',
annoNascita = 'Anno di nascita',
giornoMeseMorte = 'Giorno e mese di morte',
annoMorte = 'Anno di morte',
secoloAttivita = 'Secolo di attività',
professioneNazionalita = 'Professione e nazionalità',
wikipedia = 'Nome della pagina su Wikipedia',
wikiquote = 'Nome della pagina su Wikiquote',
wikinotizie = 'Nome della pagina su Wikinotizie',
commons = 'Nome della pagina su Commons',
immagine = 'Nome dell\'immagine'
}
function p.autodetect(frame)
local aut = frame:getParent().args[1]
local t = mw.title.getCurrentTitle().text
if aut == nil or aut == '' then
local m = string.match(t,'^Libri di (.+)$')
if m == nil then
m = string.match(t,'^Testi di (.+)$')
end
if m == nil then
m = string.match(t,'in cui è citato (.+)$')
end
if m ~= nil then
return m
end
end
return aut
end
function p.dato(frame)
local page = mw.title.new(frame:getParent().args[1], 102)
local c = string.gsub(page:getContent(), '^(.*%{%{%s*[Aa]utore)(\n*%|.-%}%}).*$', '{{DatoAutore/dato|dato='..frame:getParent().args[2]..'%2')
return frame:preprocess(c)
end
function p.prendiDato(frame)
return frame:getParent().args[attrs[frame:getParent().args.dato]]
end
-- SPERIMENTALE --
-- elemento di Wikidata
local item = mw.wikibase.getEntityObject()
function cda()
if item then
return require('Modulo:Controllo di autorità').box(item)
end
return ''
end
-- stringa da restituire
local output = ''
function add(str)
output = output..str
end
-- aggiunge una categoria
function addCat(name)
add('[['..mw.site.namespaces[14].name..':'..mw.text.trim(name)..']]')
end
-- aggiunge un template
function addTmp(title, args)
add(mw.getCurrentFrame():expandTemplate{ title = title, args = (args or {}) })
end
function datetostring(anno, giornoMese)
if anno == '' then
return nil
end
anno = mw.getCurrentFrame():expandTemplate{ title = 'Autore/Anno', args = { anno } }
if giornoMese == '' then
return anno
end
return mw.getCurrentFrame():expandTemplate{ title = 'DataGiorno', args = { giornoMese } }..' '..anno
end
-- conta il numero di pagine in una data categoria
function pagesInCat(cat)
return mw.site.stats.pagesInCategory(cat, 'pages')
end
-- crea un collegamento a una categoria (non vuota) relativa all'autore
function catLink(cat, icon)
local fcat = mw.ustring.format(cat, nomeAutore)
if pagesInCat(fcat) > 0 then
add('<div>[[File:'..(icon or 'Nuvola filesystems folder open.png')..'|20px]] \'\'[[:'..mw.site.namespaces[14].name..':'..fcat..'|'..mw.ustring.format(cat, (args.Nome or '')..' '..(args.Cognome or ''))..']] ('..pagesInCat(fcat)..')\'\'</div>')
end
end
-- TODO: asserzioni multiple, formattazione, fonti e qualificatori
function claim(prop)
if item == nil then
return nil
end
local claims = item.claims
if claims and claims[prop] then
for index,claim in pairs(claims[prop]) do
if claim.mainsnak.datavalue and claim.mainsnak.datavalue.value then
if claim.mainsnak.datavalue.value['numeric-id'] then
return mw.wikibase.sitelink('Q'..claim.mainsnak.datavalue.value['numeric-id'])
else
return claim.mainsnak.datavalue.value
end
end
end
end
end
function instanceof(arg)
if item and item.claims and item.claims.P31 then
local claims = item.claims.P31
for index, claim in pairs(claims) do
if claim.mainsnak and claim.mainsnak.datavalue then
local val = claim.mainsnak.datavalue.value
if val and val['numeric-id'] and arg == val['numeric-id'] then
return true
end
end
end
end
return false
end
local gender = nil
if item and item.claims and item.claims.P21 and #item.claims.P21 == 1 then
local claim = item.claims.P21[1]
if claim.mainsnak.datavalue and claim.mainsnak.datavalue.value and claim.mainsnak.datavalue.value['numeric-id'] then
local n = claim.mainsnak.datavalue.value['numeric-id']
if n == 6581097 then
gender = 'male'
elseif n == 6581072 then
gender = 'female'
end
end
end
-- Restituisce il collegamento corrispondente al codice fornito
function sitelink(dbname)
if item and item:getSitelink(dbname) then
return item:getSitelink(dbname)
end
end
function fallback(a, b)
if a and mw.text.trim(a) ~= '' then
return mw.text.trim(a)
end
return b
end
function fallbackWithCat(a, b, cat)
local fb = fallback(a, b)
--[[if fb ~= b then
addCat(cat)
if cat == 'Collegamento a Commons differente da Wikidata' and (wikinews() or '') == '' and string.sub(args['Nome della pagina su Wikipedia'], 3, 3) ~= ':' then
addCat('SamoaBot')
end
end]]
return fb
end
-- collegamento a Wikipedia in italiano
function wikipedia()
local lang = nil
local sl = sitelink('itwiki')
if args['Nome della pagina su Wikipedia'] == nil and sl == nil and sitelink('enwiki') then
lang = 'en'
sl = sitelink('enwiki')
end
return lang, fallbackWithCat(args['Nome della pagina su Wikipedia'], sl, 'Collegamento a Wikipedia differente da Wikidata')
end
-- collegamento a Wikiquote in italiano
function wikiquote()
return fallbackWithCat(args['Nome della pagina su Wikiquote'], sitelink('itwikiquote'), 'Collegamento a Wikiquote differente da Wikidata')
end
-- collegamento a Wikinotizie
function wikinews()
return args['Nome della pagina su Wikinotizie']
end
-- collegamento a Commons (per gallerie)
function commons()
return sitelink('commonswiki')
end
-- titolo della categoria su Commons
function commonsCat()
return fallbackWithCat(args['Nome della pagina su Commons'], claim('P373'), 'Collegamento a Commons differente da Wikidata')
end
function p.autore(frame)
if frame == nil or frame:getParent() == nil then
error('Nessun frame rilevato')
end
-- parametri passati al template Autore
args = {}
for k, v in pairs(frame:getParent().args) do
if v == nil or v == '' or mw.text.trim(v) == '' then
args[k] = nil
else
args[k] = mw.text.trim(v)
end
end
-- lingua predefinita
local lang = mw.language.getContentLanguage()
-- nome dell'autore: Nome, Cognome e Disambigua
nomeAutore = {}
for i, v in pairs({'Nome', 'Cognome', 'Disambigua'}) do
if args[v] ~= nil and mw.text.trim(args[v]) ~= '' then
table.insert(nomeAutore, mw.text.trim(args[v]))
end
end
if #nomeAutore > 0 then
nomeAutore = table.concat(nomeAutore, ' ')
else
error('Nome autore non valido')
end
local cognonome = (args.Cognome or '')..(args.Nome or '')
local dati = mw.html.create('span'):attr('id', 'dati')
for k, v in pairs(attrs) do
dati:attr('data-'..k, (args[v] or ''))
end
add(tostring(dati))
-- CAT: AUTORI OMONIMI (cioè che usano il campo Disambigua per distinguersi da omonimi)
if args.Disambigua ~= nil then
addCat('Autori omonimi')
end
if mw.title.getCurrentTitle().nsText == 'Autore' then
-- CAT: AUTORI-NATI NELL'ANNO
if args['Anno di nascita'] ~= nil then
local a = args['Anno di nascita']
if a ~= '' and tostring(tonumber(a)) == a and frame:callParserFunction('#titleparts', a, '1', '2') == '' then
addCat('Nati nel '..a)
end
end
-- CAT: AUTORI-MORTI NELL'ANNO
if args['Anno di morte'] ~= nil then
local a = args['Anno di morte']
if a ~= '' and tostring(tonumber(a)) == a and frame:callParserFunction('#titleparts', a, '1', '2') == '' then
addCat('Morti nel '..a)
end
end
end
-- CAT: AUTORI-INIZIALE
addCat('Autori')
addCat('Autori-'..mw.ustring.upper(frame:expandTemplate{ title = 'Prima lettera', args = { (args.Cognome or '')..(args.Nome or '') } }))
-- CAT: AUTORI DEL SECOLO
local secolo = (args['Secolo di attività'] or '')
if secolo == '' then
addCat('Autori senza secolo indicato')
else
if lang:ucfirst(secolo) == 'Antichità' then
addCat('Autori dell\'Antichità')
elseif lang:ucfirst(secolo) == 'Alto Medioevo' then
addCat('Autori dell\'Alto Medioevo')
else
addTmp('Autore/CategorieSecolo', { secolo, cognonome })
end
-- CAT: AUTORI PER NAZIONALITÀ E SECOLO
local plur = frame:expandTemplate{ title = 'Autore/PluraleNazionalità', args = { args['Nazionalità'] } }
if plur ~= nil and plur ~= '' then
if lang:ucfirst(secolo) == 'Antichità' then
addCat('Autori '..plur..' dell\'Antichità')
elseif lang:ucfirst(secolo) == 'Alto Medioevo' then
addCat('Autori '..plur..' dell\'Alto Medioevo')
else
addTmp('Autore/CategorieSecolo', { secolo, cognonome, plur })
end
end
end
local att = nil
-- CAT: AUTORI PER ATTIVITÀ
if args['Attività'] ~= nil then
att = args['Attività']
addTmp('Autore/CategorieAttività', { att, cognonome })
-- CAT: AUTORI PER ATTIVITÀ E SECOLO
if lang:ucfirst(secolo) == 'Antichità' then
addTmp('Autore/CategorieAttività', { att, cognonome, 'dell\'Antichità' })
elseif lang:ucfirst(secolo) == 'Alto Medioevo' then
addTmp('Autore/CategorieAttività', { att, cognonome, 'dell\'Alto Medioevo' })
else
addTmp('Autore/CategorieAttivitàSecolo', { att, secolo, cognonome })
end
else
addCat('Autori senza attività')
end
-- CAT: AUTORI PER NAZIONALITÀ
if args['Nazionalità'] ~= nil then
local naz = args['Nazionalità']
local plur = frame:expandTemplate{ title = 'Autore/PluraleNazionalità', args = { args['Nazionalità'] } }
if plur ~= nil and plur ~= '' then
addCat('Autori '..plur)
-- AUTORI PER ATTIVITÀ + NAZIONALITÀ
if att then
addTmp('Autore/CategorieAttività', { att, cognonome, plur })
end
else
addCat('Autori di nazionalità non censita')
end
else
addCat('Autori senza nazionalità')
end
-- CAT: AUTORI CON/SENZA OPERE
if (pagesInCat('Testi di '..nomeAutore) + pagesInCat('Traduzioni di '..nomeAutore)) > 0 then
addCat('Autori con opere su Wikisource')
else
addCat('Autori senza opere su Wikisource')
end
-- CAT: AUTORI DI TESTI MUSICALI
if pagesInCat('Testi musicati da '..nomeAutore) > 0 then
addCat('Autori di testi musicali')
end
-- CAT: AUTORI CITATI IN OPERE PUBBLICATE
if pagesInCat('Testi in cui è citato '..nomeAutore) > 0 then
addCat('Autori citati in opere pubblicate')
elseif pagesInCat('Pagine in cui è citato '..nomeAutore) > 0 then
addCat('Autori citati in pagine non transcluse')
end
-- CAT: AUTORI SENZA DATI ANAGRAFICI
if (
(args['Giorno e mese di nascita'] or '')..
(args['Anno di nascita'] or '')..
(args['Giorno e mese di morte'] or '')..
(args['Anno di morte'] or '')
) == '' and args.Nome ~= 'Anonimo' then
addCat('Autori senza dati anagrafici')
end
-- CAT: AUTORI SENZA DATI BIOGRAFICI
if (
(args['Professione e nazionalità'] or '')..
(args['Attività'] or '')..
(args['Nazionalità'] or '')
) == '' then
addCat('Autori senza dati biografici')
end
-- CAT: AUTORI DA CONTROLLARE PER COPYRIGHT
if args['Anno di morte'] ~= nil and tonumber(args['Anno di morte']) ~= nil and tonumber(args['Anno di morte']) >= 1926 then
addCat('Autori da controllare')
end
-- CAT: AUTORI CON/SENZA IMMAGINE
if args['Nome dell\'immagine'] ~= nil then
addCat('Autori con immagine')
else
addCat('Autori senza immagine|'..cognonome)
end
local wp_lang, wp = wikipedia()
local com = commons()
local comCat = (commonsCat() or '')
if comCat ~= '' and string.sub(comCat, 1, 9) ~= 'Category:' then
comCat = 'Category:'..comCat
end
local wq = wikiquote()
local wn = wikinews()
-- CAT: AUTORI SENZA VOCE SU WIKIPEDIA
if (wp or '') == '' then
addCat('Autori senza voce su Wikipedia')
end
-- CAT: AUTORI SENZA VOCE SU WIKIQUOTE
if (wq or '') == '' then
addCat('Autori senza voce su Wikiquote')
end
-- CAT: AUTORI SENZA VOCE SU COMMONS
if (com or '') == '' then
addCat('Autori senza voce su Commons')
end
-- AUTORI SENZA ELEMENTO SU WIKIDATA
if not item then
addCat('Autori non collegati a Wikidata')
end
if not gender and instanceof(5) then
addCat('Autori senza proprietà sesso su Wikidata')
end
-- IMMAGINE AUTORE
if args['Nome dell\'immagine'] ~= nil then
add('[[File:'..args['Nome dell\'immagine']..'|thumb|180px|right|'..(args.Nome or '')..' '..(args.Cognome or '')..']]')
end
-- NOME E COGNOME
add('\'\'\''..mw.text.trim((args.Nome or '')..' '..(args.Cognome or ''))..'\'\'\'')
-- DATI ANAGRAFICI
local annoNascita = (args['Anno di nascita'] or '')
local giornoMeseNascita = (args['Giorno e mese di nascita'] or '')
local annoMorte = (args['Anno di morte'] or '')
local giornoMeseMorte = (args['Giorno e mese di morte'] or '')
if annoNascita == '' and annoMorte == '' then
if secolo ~= nil then
add(' ('..secolo..')')
end
else
local nascita = (datetostring(annoNascita, giornoMeseNascita) or '????')
local morte = (datetostring(annoMorte, giornoMeseMorte) or '...')
add(' ('..nascita..' – '..morte..')')
end
local oa = 'o/a'
if gender then
if gender == 'male' then
oa = 'o'
elseif gender == 'female' then
oa = 'a'
end
end
-- EVENTUALE ALTRO NOME
if args['Eventuale altro nome'] ~= nil then
add(', not'..oa..' anche come \'\'\''..args['Eventuale altro nome']..'\'\'\'')
end
-- EVENTUALE PSEUDONIMO
if args['Eventuale pseudonimo'] ~= nil then
add(', not'..oa..' anche con lo pseudonimo di \'\'\''..args['Eventuale pseudonimo']..'\'\'\'')
end
-- EVENTUALE NOME REALE
if args['Eventuale nome reale'] ~= nil then
add(', nat'..oa..' \'\'\''..args['Eventuale nome reale']..'\'\'\'')
end
-- DATI BIOGRAFICI
if args['Professione e nazionalità'] ~= nil then
add(', '..lang:lcfirst(args['Professione e nazionalità'])..'.')
else
if args['Attività'] ~= nil then
add(', ')
if args['Nazionalità'] ~= nil then
addTmp('Autore/Attività', { args['Attività'] })
add(' '..args['Nazionalità']..'.')
else
addTmp('Autore/Attività', { args['Attività']..'.' })
end
else
add('.')
end
end
local authcon = cda()
-- AUTORI SENZA SCHEDE DI AUTORITÀ
if authcon == nil or authcon == '' then
addCat('Autori senza schede di autorità')
end
add(authcon)
-- INTERPROGETTO
add(tostring(mw.html.create('div'):css('margin-top', '15px')
:wikitext(frame:expandTemplate{ title = 'Interprogetto', args = { wAutore = wp, wAutore_lang = wp_lang, qAutore = wq, nAutore = wn, CommonsAutore = com, commons = comCat } })))
if args.Nome ~= 'Anonimo' then
-- LINK ALLA CATEGORIA TESTI DI ...
catLink('Testi di %s')
-- LINK ALLA CATEGORIA TESTI MUSICATI DA...
catLink('Testi musicati da %s', 'Nuvola filesystems folder sound.png')
end
-- LINK ALLA CATEGORIA TRADUZIONI DI ...
catLink('Traduzioni di %s')
-- LINK ALLA CATEGORIA TESTI IN CUI È CITATO ...
catLink('Testi in cui è citato %s')
-- LINK ALLA CATEGORIA PAGINE IN CUI È CITATO ...
if pagesInCat('Testi in cui è citato '..nomeAutore) == 0 then
catLink('Pagine in cui è citato %s')
end
if wn ~= nil then
addCat('Autori con pagina su Wikinews')
end
return output
end
return p