Modulo:Bio/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Annullata la modifica 108468834 di Rojelio (discussione) Etichetta: Annulla |
aggiorno |
||
(21 versioni intermedie di 4 utenti non mostrate) | |||
Riga 6:
]]
require("
local mString = require("Modulo:String")
local mWikidata = require("Modulo:Wikidata")
local cfg = mw.loadData("Modulo:Bio/Configurazione")
local ex_attivita = mw.loadData("Modulo:Bio/Ex attività")
-- argomenti passati al template
local args
Line 79 ⟶ 80:
end
return false
end
-- Riconosce le ex attività previste e le restituisce senza "ex"
local function isExAttivita(attivita)
local ret
attivita = attivita:match("^ex (.+)$")
if attivita then
for _, v in ipairs(ex_attivita) do
if v == attivita then
ret = attivita
break
end
end
end
return ret
end
Line 123 ⟶ 139:
-- è ammessa l'iniziale maiuscola per i parametri per attività e nazionalità
-- (complicazione inutile. basta eliminare dalle voci le maiuscole esistenti)
end
end
for _, param in ipairs(nazionalitaParams) do
retArgs[param] = retArgs[param] and lang:lcfirst(retArgs[param])
end
Line 174 ⟶ 189:
if args.ForzaOrdinamento then
sortkey = args.ForzaOrdinamento:gsub("(.-)%s*,%s*(.*)", "%1 ,%2")
elseif args.Soprannome and args.Cognome and currentTitleEquals(args.Soprannome .. " " .. args.Cognome) then
sortkey = mString.collate( { args = { args.Cognome .. " ," .. args.Soprannome } } )
elseif args.Pseudonimo and currentTitleEquals(args.Pseudonimo) then
local pseudonimo = mString.collate( { args = { args.Pseudonimo } } )
Line 195 ⟶ 212:
end
end
self:_addAttivita(self.plurals)
self:_addNatiMorti()
self:_addCategory(cfg.categorie["bot"])
Line 318 ⟶ 332:
local plural
self.plurale_attivita = self.plurale_attivita or mw.loadData("Modulo:Bio/Plurale attività")
plural = self.plurale_attivita[isExAttivita(attivita) or attivita]
if not plural then
addAvviso(cfg.warningA.testo .. cfg.warningA.testo2a:gsub("$1", attivita) .. cfg.warningA.testo3, "warning")
Line 345 ⟶ 357:
function CategoryManager:_getPluralsAttivitaNazionalita()
local plurals = {}
local attnaznecessarie = not (args.Categorie == "no" and args.FineIncipit)
-- Nazionalità può essere vuota solo quando c'è Categorie=no e FineIncipit
if not args["Nazionalità"] and
addAvviso(cfg.warningN.testo .. cfg.warningN.testo2b .. cfg.warningN.testo3, "warning")
end
for _, nazionalita in ipairs(nazionalitaParams) do
if args[nazionalita] then
end
end
-- Attività può essere vuota solo quando c'è Categorie=no e FineIncipit
if not args["Attività"] and
addAvviso(cfg.warningA.testo .. cfg.warningA.testo2b .. cfg.warningA.testo3, "warning")
end
for _, attivita in ipairs(attivitaParams) do
if args[attivita] then
end
end
Line 383 ⟶ 390:
annoNascita = annoNascita and tonumber(annoNascita) * -1
end
if
return "2000"
end
if not annoMorte and args.AnnoMorte then
annoMorte = args.AnnoMorte:match('^(%d+) a%.C%.$')
annoMorte = annoMorte and tonumber(annoMorte) * -1
Line 403 ⟶ 413:
return ret
end
-- Aggiunge Categoria:X dei secoli, se esistono
function CategoryManager:_addCatSecolo(catname, epoca1, epoca2)
local ok = false
for _, epoca in ipairs({ epoca1, epoca2 }) do
if epoca and titleExists("Categoria:" .. catname .. " " .. epoca) then
self:_addCategory(catname .. " " .. epoca)
ok = true
end
end
return ok
end
-- Aggiunge le categorie: Attività nazionalità [del XYZ secolo]
function CategoryManager:_addAttivita(plurals)
local catname, epoca1, epoca2, added, addatt, addnaz, add1, addbase
addatt = {}
addnaz = {}
-- se Epoca e Epoca2 non sono stati inseriti dall'utente
-- e AnnoNascita e AnnoMorte cadono nello stesso secolo
-- calcola epoca1 automaticamente
if not args.Epoca and not args.Epoca2 and args.AnnoNascita
epoca1 = self:_getEpoca()
epoca1 = epoca1 and cfg.epoche[epoca1]
Line 418 ⟶ 442:
epoca1 = args.Epoca and cfg.epoche[args.Epoca]
epoca2 = args.Epoca2 and cfg.epoche[args.Epoca2]
end
if not epoca1 and not epoca2 then
self:_addCategory(cfg.categorie["no-epoca"])
end
if args.Categorie ~= "no" then
if plurals[attivita] then
if plurals[nazionalita] then
catname = plurals[attivita] .. " " .. plurals[nazionalita]
-- se non è stata aggiunta la categoria per epoca1 e epoca2
-- aggiunge la cat. semplice, es. "Scrittori italiani"
add1 = true
addatt[attivita] = true
addnaz[nazionalita] = true
else
self:_addCategory(catname)
addbase = true
end
end
end
Line 441 ⟶ 469:
end
end
-- in mancanza di "A N del S" prova "A del S" e "N del S"
for _, attivita in ipairs(attivitaParams) do
if plurals[attivita] and not addatt[attivita] then
add1 = self:_addCatSecolo(plurals[attivita], epoca1, epoca2) or add1
end
end
for _, nazionalita in ipairs(nazionalitaParams) do
if plurals[nazionalita] and not addnaz[nazionalita] then
add1 = self:_addCatSecolo(plurals[nazionalita], epoca1, epoca2) or add1
for k, v in ipairs({"cecoslovacchi", "jugoslavi", "sovietici"}) do
if plurals[nazionalita] == v and not add1 and not addbase then
self:_addCategory(plurals[nazionalita])
add1 = true
end
end
end
end
if not add1 and not addbase then
self:_addCatSecolo("Persone", epoca1, epoca2)
end
end
Line 569 ⟶ 619:
self:_addNomeCognome()
self:_addNascitaMorte()
if args.Soprannome or args.Pseudonimo or args.PostCognomeVirgola then
self:_addText(",")
end
Line 635 ⟶ 685:
-- Restituisce true se text necessita di uno spazio iniziale (PostCognome, PostSoprannome, PostPseudonimo, LuogoNascitaAlt, NoteNascita, LuogoMorteAlt, NoteMorte, AttivitàAltre, PostNazionalità, FineIncipit)
function Incipit:_needSpace(text)
return mw.ustring.match(mw.ustring.sub(text, 1, 1), "%w") ~= nil or
Line 677 ⟶ 727:
elseif args.Pseudonimo and currentTitleEquals(args.Pseudonimo) then
caption = args.Pseudonimo
elseif args.Soprannome and args.Cognome and currentTitleEquals(args.Soprannome .. " " .. args.Cognome) then
caption = args.Soprannome .. " " .. args.Cognome
elseif args.Soprannome and currentTitleEquals(args.Soprannome) then
caption = args.Soprannome
else
if args.CognomePrima and args.Nome and args.Cognome then
Line 745 ⟶ 799:
end
self:_addText(args.PostCognome)
end
if args.Soprannome then
self:_addText(", ", (not args.Sesso or args.Sesso == "M") and "detto" or "detta",
" ", "'''", args.Soprannome, "'''")
if args.PostSoprannome then
if self:_needSpace(args.PostSoprannome) then
self:_addText(" ")
end
self:_addText(args.PostSoprannome)
end
end
Line 762 ⟶ 827:
-- si apre la parentesi
self:_addText(" (")
if args.PreData then
self:_addText(args.PreData, "; ")
end
local datimancanti = not (args.LuogoNascita or args.GiornoMeseNascita or args.NoteNascita or args.LuogoMorte or args.GiornoMeseMorte)
local floruit = args.AnnoMorte == "?" and (args.Floruit or cfg.epoche[args.Epoca])
if args.LuogoNascita then
self:_addWlink(args.LuogoNascitaLink, args.LuogoNascita)
if args.LuogoNascitaAlt then
if self:
self:_addText(" ")
end
self:_addText(args.LuogoNascitaAlt)
end
self:_addText(", ")
Line 790 ⟶ 861:
self:_addText(args.AnnoNascita)
end
elseif not floruit or not datimancanti then
self:_addText("...")
end
if args.NoteNascita then
if self:_needSpace(args.NoteNascita) then
self:_addText(" ")
end
self:_addText(args.NoteNascita)
end
if args.AnnoMorte and (not floruit or not datimancanti) then
self:_addText(" – ")
if args.LuogoMorte then
self:_addWlink(args.LuogoMorteLink, args.LuogoMorte)
if args.LuogoMorteAlt then
if self:
self:_addText(" ")
end
self:_addText(args.LuogoMorteAlt)
end
self:_addText(", ")
Line 827 ⟶ 904:
end
end
end
end
-- se date ignote, usa Floruit o lo ricava da Epoca
if not args.AnnoNascita and args.AnnoMorte == "?" then
local fl = args.Floruit
if not fl and cfg.epoche[args.Epoca] then
fl = mw.ustring.gsub(cfg.epoche[args.Epoca], "^del ?l?'?", "")
-- se due epoche, le mette entrambe senza ripetere la parola "secolo"
if cfg.epoche[args.Epoca2] then
if fl ~= "I secolo a.C." then
fl = fl .. "|" .. mw.ustring.gsub(fl, " secolo.*$", "")
end
fl = "[[" .. fl .. "]]-[[" .. mw.ustring.gsub(cfg.epoche[args.Epoca2], "^del ?l?'?", "") .. "]]"
end
end
if fl then
if titleExists(fl) then
fl = "[[" .. fl .. "]]"
end
if not datimancanti then
self:_addText("; ")
end
self:_addText("[[floruit|fl.]] ", fl)
end
end
if args.NoteMorte then
if self:_needSpace(args.NoteMorte) then
self:_addText(" ")
end
self:_addText(args.NoteMorte)
end
-- si chiude la parentesi
self:_addText(")")
end
Line 840 ⟶ 948:
function Incipit:_addAttivita()
local link_attivita = mw.loadData("Modulo:Bio/Link attività")
local link_nazionalita = mw.loadData("Modulo:Bio/Link nazionalità")
self:_addText(" ")
if args["PreAttività"] then
Line 858 ⟶ 966:
end
local getLinkAttivita = function(attivita)
if not attivita then return end
local ex_attivita = isExAttivita(attivita)
return link_attivita[ex_attivita or attivita] or ex_attivita
end
self:_addWlink(getLinkAttivita(args["Attività"]), args["Attività"] or "", "ex")
if args["Attività2"] then
Line 867 ⟶ 981:
end
self:_addText(" ")
self:_addWlink(
end
Line 877 ⟶ 991:
end
self:_addText(" ")
self:_addWlink(
end
|