Modulo:Fumetto e animazione: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto cancellato Contenuto aggiunto
categoria d'errore unica |
m fix |
||
Riga 299: | Riga 299: | ||
} |
} |
||
tipo = tipo[args.tipo] |
tipo = tipo[args.tipo] |
||
tipo = tipo[1] and tipo[1] .. ']][[Categoria:' .. tipo[2] or tipo |
tipo = tipo and tipo[1] and tipo[1] .. ']][[Categoria:' .. tipo[2] or tipo |
||
category = tipo and tipo ~= '' and '[[Categoria:' .. tipo .. ']]' |
category = tipo and tipo ~= '' and '[[Categoria:' .. tipo .. ']]' |
||
end |
end |
Versione delle 01:28, 26 mag 2017
Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Fumetto e animazione/man (modifica · cronologia)
Sandbox: Modulo:Fumetto e animazione/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Fumetto e animazione/test (modifica · cronologia · Esegui)
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Fumetto e animazione/man (modifica · cronologia)
Sandbox: Modulo:Fumetto e animazione/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Fumetto e animazione/test (modifica · cronologia · Esegui)
Modulo Lua di appoggio al template {{Fumetto e animazione}}, per gestirne le funzioni di categorizzazione automatica.
Ha una sottopagina di configurazione: Modulo:Fumetto e animazione/Configurazione.
--[[
Questo modulo è in appoggio al template Fumetto e animazione per gestirne
le funzioni di categorizzazione automatica
]]
local p = {}
local cfg = mw.loadData("Modulo:Fumetto e animazione/Configurazione")
local getArgs = require('Module:Arguments').getArgs
local mDelink = require('Modulo:Delink')
local error_category = 'Errori di compilazione del template Fumetto e animazione'
local function build_reverse_alias(table_name)
local reverse_alias = {}
for alias, name in pairs(cfg['alias_' .. table_name]) do
if not reverse_alias[name] then reverse_alias[name] = {} end
table.insert(reverse_alias[name], alias)
end
return reverse_alias
end
-- ========================================================================
-- Sostituisce name con il suo alias se presente nella tabella alias
-- quindi ritorna il valore corrispondente dalla tabella values
-- ========================================================================
local function get_category(name, table_name)
name = cfg['alias_' .. table_name][name] or name
return cfg[table_name][name]
end
-- ========================================================================
-- Rimpiazza le parentesi quadre nella stringa con i corrispondenti codici
-- ascii
-- ========================================================================
local function replace_braces(s)
local new_s = mw.ustring.gsub(s, "%[", "[")
new_s = mw.ustring.gsub(new_s, "%]", "]")
new_s = mw.ustring.gsub(new_s, "%(", "(")
new_s = mw.ustring.gsub(new_s, "%)", ")")
new_s = mw.ustring.gsub(new_s, " ", " ")
return new_s
end
-- ========================================================================
-- Appende una tabella a un'altra tabella
-- ========================================================================
local function append_table(t1, t2)
for _,el in ipairs(t2) do
t1[#t1+1] = el
end
end
-- ========================================================================
-- Restituisce l'aggettivo plurale maschile o femminile del Paese
-- specificato usando il template AggNaz
-- ========================================================================
local function get_adj(paese, genere)
local adj
local title = mw.title.new('Template:AggNaz/' .. paese)
adj = (title and title.exists) and
mw.getCurrentFrame():expandTemplate {
title = title.text,
args = { genere }
} or nil
return adj
end
-- ========================================================================
-- Ritorna una lista di categorie per la sequenza di parametri con
-- nome base 'base_name' consultando la tabella 'table'.
-- 'alias_table' è una tabella di nomi alternativi per i valori dei
-- parametri, 'max_index' il numero massimo dell'indice del parametro
-- da controllare
-- ========================================================================
local function categorizza(args, base_name, table_name, lowercase)
local categories = {}
local adj = {}
local anno = {}
local name_value = args[base_name]
if name_value then
name_value = mDelink._main({ name_value })
if lowercase then name_value = mw.ustring.lower(name_value) end
if table_name == 'paese_TV' then
adj = get_adj(name_value, 'fp')
if adj and adj ~= 'giapponesi' then
categories[#categories+1] = 'Serie televisive d\'animazione ' .. adj
end
elseif table_name == 'paese_film' then
adj = get_adj(name_value, 'mp')
if adj then
categories[#categories+1] = 'Film d\'animazione ' .. adj
if args['data inizio'] then
anno = tonumber(args['data inizio']:match('%d%d%d%d'))
if anno then
categories[#categories+1] = 'Film ' .. adj .. ' del ' .. anno
end
end
end
elseif table_name == 'paese_fumetto' then
if name_value == 'Belgio' or name_value == 'Francia' then
categories[#categories+1] = 'Fumetti franco-belgi'
else
adj = get_adj(name_value, 'mp')
if adj and adj ~= 'giapponesi' and
adj ~= 'cinesi' and adj ~= 'coreani' then
categories[#categories+1] = 'Fumetti ' .. adj
end
end
elseif table_name == 'etichetta_sottotipo' or table_name == 'editore_sottotipo' then
categories[#categories+1] = get_category(args.sottotipo .. ' ' .. name_value, table_name)
else
local category = get_category(name_value, table_name)
if category then
categories[#categories+1] = category
end
end
local index = 2
while true do
name_value = args[base_name .. ' ' .. tostring(index)]
if name_value then
name_value = mDelink._main({ name_value })
if lowercase then name_value = mw.ustring.lower(name_value) end
if table_name == 'paese_TV' then
adj = get_adj(name_value, 'fp')
if adj and adj ~= 'giapponesi' then
categories[#categories+1] = 'Serie televisive d\'animazione ' .. adj
end
elseif table_name == 'paese_film' then
adj = get_adj(name_value, 'mp')
if adj then
categories[#categories+1] = 'Film d\'animazione ' .. adj
if args['data inizio'] then
anno = tonumber(args['data inizio']:match('%d%d%d%d'))
if anno then
categories[#categories+1] = 'Film ' .. adj .. ' del ' .. anno
end
end
end
elseif table_name == 'paese_fumetto' then
if name_value == 'Belgio' or name_value == 'Francia' then
categories[#categories+1] = 'Fumetti franco-belgi'
else
adj = get_adj(name_value, 'mp')
if adj and adj ~= 'giapponesi' and
adj ~= 'cinesi' and adj ~= 'coreani' then
categories[#categories+1] = 'Fumetti ' .. adj
end
end
elseif table_name == 'etichetta_sottotipo' or table_name == 'editore_sottotipo' then
categories[#categories+1] = get_category(args.sottotipo .. ' ' .. name_value, table_name)
else
local category = get_category(name_value, table_name)
if category then
categories[#categories+1] = category
end
end
else
break
end
index = index + 1
end
end
return categories
end
----------------------------------------------------------------------------------
-- Categorizza tranne che per genere
----------------------------------------------------------------------------------
function p.categorie(frame)
local args = getArgs(frame, {parentOnly = not frame.args.debug})
local current_page = mw.title.getCurrentTitle()
local current_namespace = current_page.namespace
if (current_namespace ~= 0 or args.categorie == 'no') and not frame.args.debug then return '' end
local categories = {}
local tipo = {}
local counter = {}
if args.tipo then
tipo = get_category(args.tipo .. (args.sottotipo and (' ' .. args.sottotipo) or ''), 'tipo')
end
-- Categorizzazioni specifiche
if tipo == "Serie televisive d'animazione" then
counter = #categories
append_table(categories, categorizza(args, 'studio', 'studio_cartoneTV'))
if counter == #categories then
append_table(categories, categorizza(args, 'paese', 'paese_TV'))
append_table(categories, categorizza(args, 'studio', 'studio'))
end
elseif args.tipo == 'anime' or args.tipo == 'cartone' then
if tipo == 'Film d\'animazione' then
append_table(categories, categorizza(args, 'paese', 'paese_film'))
end
append_table(categories, categorizza(args, 'studio', 'studio'))
elseif args.tipo == 'manga' then
counter = #categories
append_table(categories, categorizza(args, 'editore', 'editore_manga'))
if counter == #categories then
append_table(categories, categorizza(args, 'editore', 'editore'))
end
elseif args.tipo == 'manhwa' or args.tipo == 'manhua' then
append_table(categories, categorizza(args, 'editore', 'editore'))
elseif args.tipo == 'light novel' then
categories[#categories+1] = tipo
if mDelink._main({ args['lingua originale'] }) == 'giapponese' then
categories[#categories+1] = 'Romanzi in giapponese'
end
counter = #categories
append_table(categories, categorizza(args, 'etichetta', 'etichetta'))
if counter == #categories then
append_table(categories, categorizza(args, 'editore', 'editore'))
end
elseif args.tipo == 'fumetto' then
counter = #categories
if args.sottotipo then
append_table(categories, categorizza(args, 'etichetta', 'etichetta_sottotipo'))
end
if counter == #categories then
local etichetta = {}
etichetta = get_category(mDelink._main({ args.etichetta }), 'etichetta')
if etichetta then
append_table(categories, categorizza(args, 'etichetta', 'etichetta'))
end
counter = #categories
if args.sottotipo then
append_table(categories, categorizza(args, 'editore', 'editore_sottotipo'))
end
if counter == #categories then
if args.sottotipo then
categories[#categories+1] = tipo
end
if etichetta == nil then
counter = #categories
append_table(categories, categorizza(args, 'editore', 'editore'))
if counter == #categories then
append_table(categories, categorizza(args, 'paese', 'paese_fumetto'))
end
end
end
end
end
if args.tipo == 'manga' or args.tipo == 'manhwa' then
append_table(categories, categorizza(args, 'target', 'target', true))
end
-- Categorizzazione per tipo delle opere non suddivise per anno
if tipo == 'Manhua' or tipo == 'Manhwa' or tipo == 'Original net anime' or
tipo == 'Special televisivi anime' or tipo == "Special televisivi d'animazione" or
tipo == "Webserie d'animazione" then
categories[#categories+1] = tipo
-- Categorizzazione per anno delle opere previste
elseif tipo ~= nil and args['data inizio'] then
local anno = {}
if args['data inizio'] then
anno = tonumber(args['data inizio']:match('%d%d%d%d'))
end
if anno == nil and args['data fine'] then
anno = tonumber(args['data fine']:match('%d%d%d%d'))
end
-- Categoria di errore quando data inizio/data fine sono compilati
-- ma non si rilevano le quattro cifre dell'anno in entrambi
if anno == nil then
categories[#categories+1] = error_category
elseif args.sottotipo ~= 'film' then
if args.tipo == 'light novel' then
tipo = 'Romanzi'
elseif args.tipo == 'fumetto' then
tipo = 'Fumetti'
end
categories[#categories+1] = tipo .. ' del ' .. anno
end
end
for index,cat in ipairs(categories) do
categories[index] = '[[Categoria:' .. cat .. ']]'
end
if #categories == 0 then return '' end
return frame.args.debug and mw.text.nowiki(table.concat(categories)) or table.concat(categories)
end
----------------------------------------------------------------------------------
-- Gestisce categorie e wikilink dei generi
----------------------------------------------------------------------------------
function p.generi(frame)
local args = getArgs(frame, {parentOnly = not frame.args[1]})
local genre = frame.args[1]
if genre == '' then return end
local current_page = mw.title.getCurrentTitle()
local current_namespace = current_page.namespace
local category
local result = {}
for name, alias_name in pairs(cfg['alias_genere']) do
local piped = mw.ustring.match(genre, '%[%[[^%[]*|%s*' .. name .. '%s*%]%]')
local pattern = (piped and '%[%[[^%[]*|%s*' or '%[%[%s*') .. name .. '%s*%]%]%a*'
genre = mw.ustring.gsub( genre, pattern, '[[' .. alias_name .. ']]' )
end
for name, correct_name in pairs(cfg['genere']) do
if current_namespace == 0 and args.categorie ~= 'no' then
local tipo = {
['anime'] = correct_name[1],
['fumetto'] = correct_name[2],
['light novel'] = correct_name[3],
['manga'] = correct_name[1],
['manhua'] = correct_name[2],
['manhwa'] = correct_name[2]
}
tipo = tipo[args.tipo]
tipo = tipo and tipo[1] and tipo[1] .. ']][[Categoria:' .. tipo[2] or tipo
category = tipo and tipo ~= '' and '[[Categoria:' .. tipo .. ']]'
end
local piped = mw.ustring.match(genre, '%[%[[^%[]*|%s*' .. name .. '%s*%]%]')
local pattern = (piped and '%[%[[^%[]*|%s*' or '%[%[%s*') .. name .. '%s*%]%]%a*'
genre = mw.ustring.gsub( genre, pattern, correct_name[4] .. (category or '') )
-- Categoria d'errore in caso di genere senza corrispondenza
local list = mw.text.split( genre, ',' )
for i = 1, #list do
local s = replace_braces(list[i])
local p = replace_braces(correct_name[4])
if mw.ustring.match( s, p ) then
result[i] = ''
elseif result[i] == nil then
result[i] = '[[Categoria:' .. error_category .. ']]'
end
end
end
genre = genre .. table.concat(result)
return genre
end
----------------------------------------------------------------------------------
-- Ritorna la configurazione della tabella per aziende e target
----------------------------------------------------------------------------------
function p.tabella_configurazione(frame)
local args = getArgs(frame)
local table_name = args[1]
if not(table_name) then return '' end
local reverse_alias = build_reverse_alias(table_name)
local root = mw.html.create('table')
root
:addClass('wikitable sortable')
:tag('tr')
:tag('th'):wikitext(table_name):done()
:tag('th'):wikitext('Alias'):done()
:tag('th'):wikitext('Categoria'):done()
for name, cat_name in pairs(cfg[table_name]) do
local name_code = table_name == 'genere' and
replace_braces(cat_name[4]) or
'[[' .. name .. ']]'
local cat_code = {}
if cat_name[1] then
for i, cat in ipairs(cat_name) do
if i > 3 then break end
cat = cat[1] and
cat[1] .. ']]<br />[[:Categoria:' .. cat[2] or cat
if cat ~= '' then
cat_code[#cat_code+1] = '[[:Categoria:' .. cat .. ']]'
end
end
cat_code = table.concat(cat_code, '<br />')
else
cat_code = '[[:Categoria:' .. cat_name .. ']]'
end
local alias_code = ' '
if reverse_alias[name] then
for i,alias in ipairs(reverse_alias[name]) do
reverse_alias[name][i] = '[[' .. alias .. ']]'
end
alias_code = table.concat(reverse_alias[name], '<br />')
end
root:tag('tr')
:tag('td'):wikitext(name_code):done()
:tag('td'):wikitext(alias_code):done()
:tag('td'):wikitext(cat_code):done()
end
return tostring(root)
end
return p