Modulo:Videogioco: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m sposto categorizzazione per aziende dopo le altre (seguendo l'attuale ordine del template Videogioco) |
revisione della categorizzazione per aziende, v. dp:Videogiochi#Categorizzazione_per_azienda |
||
(8 versioni intermedie di 2 utenti non mostrate) | |||
Riga 43:
t1[#t1+1] = el
end
end
-- ========================================================================
-- Restituisce l'aggettivo plurale maschile del Paese specificato usando
-- il template AggNaz
-- ========================================================================
local function get_adj(paese)
local adj
local title = mw.title.new('Template:AggNaz/' .. paese)
adj = title and title.exists and
mw.getCurrentFrame():expandTemplate {
title = title.text,
args = { 'mp' }
}
return adj
end
-- ========================================================================
-- Controlla la presenza di una categoria figlia tra quelle da aggiungere
-- per evitare eventuali conflitti di categorizzazione
-- ========================================================================
local function check_redundancy(t, cat)
for _,v in ipairs(t) do
if v == cat then
return true
end
end
return false
end
Riga 52 ⟶ 81:
-- da controllare
-- ========================================================================
local function categorizza(args, base_name, table_name, lowercase, must_exist, cat_assenza)
local categories = {}
local name_value = args[base_name] or args[base_name .. " 1"]
if name_value then
if lowercase then name_value = mw.ustring.lower(name_value) end
Riga 65 ⟶ 94:
local index = 2
while true do
name_value = args[base_name .. ' ' .. tostring(index)]
if name_value then
if lowercase then name_value = mw.ustring.lower(name_value) end
Riga 72 ⟶ 101:
categories[#categories+1] = category
elseif must_exist then
errors_msg[#errors_msg+1] = 'Valore non valido per ' .. base_name .. ' ' .. tostring(index)
end
else
Riga 79 ⟶ 108:
index = index + 1
end
elseif cat_assenza and not args[base_name .. " altro"] then
categories[#categories+1] = 'Videogiochi senza ' .. base_name
end
if args[base_name] and args[base_name .. " 1"] then
errors_msg[#errors_msg+1] = 'Inserire solo uno di ' .. base_name .. ' e ' .. base_name .. ' ' .. tostring(index)
end
return categories
end
-- ========================================================================
-- Categorizzazione per aziende (sviluppo N e pubblicazione N)
-- ========================================================================
local function categoria_azienda(str)
-- converte eventuali alias
str = cfg['alias_aziende'][str] or str
-- se il nome contiene un wikilink, estrae la voce puntata, senza disambiguante
local azienda = mw.ustring.match(str, "%[%[([^%]%(|]+)") or str
azienda = mw.text.trim(azienda)
-- se esiste "cat:Videogiochi Azienda" la seleziona
local cat = "Videogiochi " .. azienda
local titolo = mw.title.new(cat, "Categoria")
if titolo and titolo.exists then
return cat
end
return nil
end
local function categorizza_aziende(args, base_name)
local categories = {}
local name_value = args[base_name] or args[base_name .. " 1"]
if name_value then
local cat = categoria_azienda(name_value)
if cat then
categories[#categories+1] = cat
end
local index = 2
while true do
name_value = args[base_name .. ' ' .. tostring(index)]
if name_value then
cat = categoria_azienda(name_value)
if cat then
categories[#categories+1] = cat
end
else
break
end
index = index + 1
end
end
if args[base_name] and args[base_name .. " 1"] then
errors_msg[#errors_msg+1] = 'Inserire solo uno di ' .. base_name .. ' e ' .. base_name .. ' ' .. tostring(index)
end
return categories
end
-- ========================================================================
-- categorizza
-- ========================================================================
function p.categorie(frame)
local args = getArgs(frame, {parentOnly = not frame.args.debug})
Riga 99 ⟶ 177:
local anno = tonumber(args.anno)
if anno == nil then
categories[#categories+1] = 'Videogiochi annullati'
else
errors_msg[#errors_msg+1] = 'anno di pubblicazione non valido'
end
elseif anno <= 1970 then
categories[#categories+1] = 'Videogiochi fino al 1970'
Riga 105 ⟶ 187:
categories[#categories+1] = 'Videogiochi del ' .. args.anno
end
else
categories[#categories+1] = 'Videogiochi senza anno'
end
append_table(categories, categorizza(args, 'genere', 'genere', true, true, true))
append_table(categories, categorizza(args, 'tema', 'tema', true))
for i = 1, 3 do
local origine = args['origine ' .. i] or i == 1 and args['origine']
if not origine then
categories[#categories+1] = i == 1 and 'Videogiochi senza nazionalità' or nil
break
end
local adj = get_adj(origine)
if adj then
categories[#categories+1] = 'Videogiochi ' .. adj
end
end
append_table(categories, categorizza(args, 'piattaforma', 'piattaforma', false, true, true))
append_table(categories, categorizza_aziende(args, 'sviluppo'))
append_table(categories, categorizza_aziende(args, 'pubblicazione'))
append_table(categories, categorizza(args, 'distribuzione digitale', 'distribuzione', false, true))
entity = mw.wikibase.getEntity()
if entity and entity.claims and entity.claims['P3442'] then
categories[#categories+1] = 'Videogiochi per Debian'
end
local cache = mw.clone(categories)
-- Categorie madri da annullare in presenza delle figlie
local sub_cat = {
['Videogiochi d\'orrore'] = 'Survival horror'
}
for index,cat in ipairs(categories) do
if sub_cat[cat] and check_redundancy(cache, sub_cat[cat]) then
categories[index] = ''
else
categories[index] = '[[Categoria:' .. cat .. ']]'
end
end
if #errors_msg>0 then
Riga 121 ⟶ 229:
return frame.args.debug and mw.text.nowiki(table.concat(categories)) or table.concat(categories)
end
-- ========================================================================
-- Visualizza le tabelle delle configurazioni per il manuale
-- ========================================================================
function p.tabella_configurazione(frame)
local args = getArgs(frame)
|