Modulo:Fumetto e animazione/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m spiegazione
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(60 versioni intermedie di un altro utente non mostrate)
Riga 3:
le funzioni di categorizzazione automatica
]]
 
local p = {}
require('strict')
 
local cfg = mw.loadData("Modulo:Fumetto e animazione/Configurazione/sandbox")
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)
-- Funzioni di utilità
local reverse_alias = {}
-- =============================================================================
for alias, name in pairs(cfg['alias_' .. table_name]) do
 
if not reverse_alias[name] then reverse_alias[name] = {} end
-- Converte la lettera iniziale di una stringa in maiuscola
table.insert(reverse_alias[name], alias)
local function ucfirst(str)
end
return str:gsub('^%l', string.upper)
return reverse_alias
end
 
-- Restituisce un valore senza eventuale wikilink a inizio stringa
-- ========================================================================
local function delink(value)
-- Sostituisce name con il suo alias se presente nella tabella alias
if not value then return end
-- quindi ritorna il valore corrispondente dalla tabella values
local pattern
-- ========================================================================
if value:find('|') then
local function get_category(name, table_name, delink)
pattern = "^'*%[%[ *([^%|%[%]]-) *%|.-%]%]"
if name and delink then
else
-- Rimuove i wikilink, restituendo sempre la parte a sinistra della barra
namepattern = name:match("^'^*%[%[(.-)|.+%]%]') or name:match*('[^%[%[(.]]-) *%]%]') or name"
end
return ucfirst(value:match(pattern) or value)
name = cfg['alias_' .. table_name][name] or name
return cfg[table_name][name]
end
 
-- Restituisce un numero variabile di valori uno alla volta
-- ========================================================================
local function extract_values(args, base_name)
-- Rimpiazza le parentesi quadre nella stringa con i corrispondenti codici
local index = 0
-- ascii
return function()
-- ========================================================================
index = index + 1
local function replace_braces(s)
local value = args[base_name .. ' ' .. tostring(index)]
local new_s = mw.ustring.gsub(s, "%[", "[")
if not value and index == 1 then
new_s = mw.ustring.gsub(new_s, "%]", "]")
value = args[base_name]
new_s = mw.ustring.gsub(new_s, "%(", "(")
end
new_s = mw.ustring.gsub(new_s, "%)", ")")
return value
new_s = mw.ustring.gsub(new_s, " ", " ")
end
return new_s
end
 
-- Restituisce un numero variabile di generi uno alla volta
-- ========================================================================
local function extract_genres(value)
-- Appende una tabella a un'altra tabella
local index = 0
-- ========================================================================
local functionsubstrings append_table= mw.text.split(t1value, ' *, t2*')
return function()
for _,el in ipairs(t2) do
index = index + 1
t1[#t1+1] = el
if not substrings[index] then return end
end
local genre
local link, tail = substrings[index]:match('^(%[%[.-%]%]%a*)(.*)$')
if link then
genre = link:gsub('^%[%[', ''):gsub('^[^%[%]%|]+%|', ''):gsub('%]%]', '')
else
genre, tail = substrings[index]:match('^([%w%(%) ]+[%w%(%)])( *.*)$')
end
if genre then
genre = mw.text.trim(genre:lower())
end
return cfg.alias_genere[genre] or genre, tail, substrings[index]
end
end
 
-- Parsifica i parametri rimuovendo le stringhe vuote
-- ========================================================================
local function parse_args(args)
-- Restituisce l'aggettivo plurale maschile o femminile del Paese
local ret = {}
-- specificato usando il template AggNaz
for key, value in pairs(args) do
-- ========================================================================
value = mw.text.trim(value)
local function get_adj(paese, genere)
if value ~= '' then
local adj
ret[key] = value
local title = mw.title.new('Template:AggNaz/' .. paese)
end
adj = (title and title.exists) and
end
mw.getCurrentFrame():expandTemplate {
return ret
title = title.text,
args = { genere }
} or nil
return adj
end
 
-- =============================================================================
-- classe Media
-- 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
local Media = {}
-- parametri, 'max_index' il numero massimo dell'indice del parametro
 
-- da controllare
-- Costruttore della classe Media
-- ========================================================================
local function categorizzaMedia:new(args, base_name, table_name, lowercase)
local categoriesself = {}
setmetatable(self, { __index = Media })
local adj
 
local anno
self.args = args
local name_value = args[base_name]
self.tipo = self:_getType()
if name_value then
self.sottotipo = self:_getSubtype()
name_value = mDelink._main({ name_value })
self.name = self:_getName()
if lowercase then name_value = mw.ustring.lower(name_value) end
self.alias = self:_getAlias()
if table_name == 'paese_TV' then
 
adj = get_adj(name_value, 'fp')
return self
if adj and adj ~= 'giapponesi' then
categories[#categories+1] = 'Serie televisive d\'animazione ' .. adj
end
elseif table_name == 'paese_film_DTV' 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'))
end
if anno == nil and args['data fine'] then
anno = tonumber(args['data fine']:match('%d%d%d%d'))
end
if anno then
categories[#categories+1] = 'Film ' .. adj .. ' del ' .. anno
end
end
elseif table_name == 'paese_webserie' then
adj = get_adj(name_value, 'fp')
if adj then
categories[#categories+1] = 'Webserie ' .. adj
end
elseif table_name == 'paese_film_TV' then
adj = get_adj(name_value, 'mp')
if adj then
categories[#categories+1] = 'Film d\'animazione ' .. adj .. ' per la televisione'
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_DTV' then
adj = get_adj(name_value, 'mp')
if adj then
categories[#categories+1] = 'Film d\'animazione ' .. adj
if anno then
categories[#categories+1] = 'Film ' .. adj .. ' del ' .. anno
end
end
elseif table_name == 'paese_webserie' then
adj = get_adj(name_value, 'fp')
if adj then
categories[#categories+1] = 'Webserie ' .. adj
end
elseif table_name == 'paese_film_TV' then
adj = get_adj(name_value, 'mp')
if adj then
categories[#categories+1] = 'Film d\'animazione ' .. adj .. ' per la televisione'
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
 
----------------------------------------------------------------------------------
-- Verifica se il medium corrisponde a uno di quelli indicati
-- Categorizza tranne che per genere
function Media:inArray(...)
----------------------------------------------------------------------------------
for _, value in ipairs({ ... }) do
function p.categorie(frame)
if self.tipo == value or self.sottotipo == value or self.name == value then
local args = getArgs(frame, {parentOnly = not frame.args.debug})
return true
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 direct-to-video' then
categories[#categories+1] = tipo
append_table(categories, categorizza(args, 'paese', 'paese_film_DTV'))
elseif tipo == 'Webserie d\'animazione' then
append_table(categories, categorizza(args, 'paese', 'paese_webserie'))
elseif tipo == 'Film d\'animazione per la televisione' then
append_table(categories, categorizza(args, 'paese', 'paese_film_TV'))
end
end
append_table(categories, categorizza(args, 'studio', 'studio'))
return false
elseif args.tipo == 'manga' then
end
counter = #categories
 
append_table(categories, categorizza(args, 'editore', 'editore_manga'))
-- Ottiene l'alias più generico del medium per le categorie
if counter == #categories then
function Media:_getAlias()
append_table(categories, categorizza(args, 'editore', 'editore'))
return self:_getValue('alias_tipo', 'alias_sottotipo')
end
end
elseif args.tipo == 'manhwa' or args.tipo == 'manhua' then
 
append_table(categories, categorizza(args, 'editore', 'editore'))
-- Ottiene il nome più preciso del medium per le categorie
elseif args.tipo == 'light novel' then
function Media:_getName()
categories[#categories+1] = tipo
return self:_getValue('tipo', 'sottotipo')
if mDelink._main({ args['lingua originale'] }) == 'giapponese' then
end
categories[#categories+1] = 'Romanzi in giapponese'
 
-- Verifica che il sottotipo di medium sia riconosciuto
function Media:_getSubtype()
if cfg.sottotipo[self.tipo] and cfg.sottotipo[self.tipo][self.args.sottotipo] then
return self.args.sottotipo
end
end
 
-- Verifica che il tipo di medium sia riconosciuto
function Media:_getType()
if cfg.tipo[self.args.tipo] or cfg.sottotipo[self.args.tipo] then
return self.args.tipo
end
end
 
-- Cerca il nome o l'alias del medium nella configurazione
function Media:_getValue(type_table_name, subtype_table_name)
return cfg[subtype_table_name][self.tipo] and
cfg[subtype_table_name][self.tipo][self.sottotipo] or
cfg[type_table_name][self.tipo]
end
 
-- =============================================================================
-- classe CategoryManager
-- =============================================================================
 
local CategoryManager = {}
 
-- Costruttore della classe CategoryManager
function CategoryManager:new(args)
local self = {}
setmetatable(self, { __index = CategoryManager })
 
self.args = args
self.media = Media:new(args)
self.error_category = false
self.year = self:_getYear()
self.genre_table_name = self:_getGenreTableName()
self.categories = {}
self.tables_matched = {}
 
self:_addCategories()
 
return self
end
 
-- Restituisce l'elenco di categorie
function CategoryManager:listCategories()
return table.concat(self.categories)
end
 
-- Avvia la categorizzazione automatica dell'opera
function CategoryManager:_addCategories()
if self.genre_table_name then
self:_addCategoriesBy('genere')
end
 
if self.media.name == "serie televisive d'animazione" then
self
:_addCategoriesBy('studio_cartoneTV')
:_addCategoriesBy('paese', 'fp', self._categorizeTVSeriesByCountry)
elseif self.media.name == "film d'animazione direct-to-video" then
self:_addCategoriesBy('paese', 'mp', self._categorizeDTVFilmByCountry)
elseif self.media.name == "webserie d'animazione" then
self:_addCategoriesBy('paese', 'fp', self._categorizeWebseriesByCountry)
elseif self.media.name == "film d'animazione per la televisione" then
self:_addCategoriesBy('paese', 'mp', self._categorizeTVFilmByCountry)
elseif self.media.tipo == 'manga' then
self
:_addCategoriesBy('editore_manga')
:_addCategoriesBy('editore')
:_addCategoriesBy('target')
elseif self.media:inArray('manhua', 'manhwa') then
self:_addCategoriesBy('editore')
elseif self.media.tipo == 'light novel' then
self
:_addCategory(self.media.tipo)
:_addCategory('Romanzi in giapponese')
:_addCategoriesBy('etichetta')
:_addCategoriesBy('editore')
elseif self.media.tipo == 'fumetto' and self.media.sottotipo then
self
:_addCategoriesBy('etichetta_sottotipo', nil, self._substituteParameter)
:_addCategoriesBy('etichetta')
:_addCategoriesBy('editore_sottotipo', nil, self._substituteParameter)
:_addCategoriesBy('editore')
:_addCategoriesBy('paese', 'mp', self._categorizeComicByCountry)
if not self.tables_matched['etichetta_sottotipo'] and
not self.tables_matched['editore_sottotipo'] then
self:_addCategory(self.media.name)
end
elseif self.media.tipo == 'fumetto' then
counter = #categories
self
append_table(categories, categorizza(args, 'etichetta', 'etichetta'))
:_addCategoriesBy('etichetta')
if counter == #categories then
:_addCategoriesBy('editore')
append_table(categories, categorizza(args, 'editore', 'editore'))
:_addCategoriesBy('paese', 'mp', self._categorizeComicByCountry)
end
 
if self.media:inArray('anime', 'cartone') then
self:_addCategoriesBy('studio')
local broadcaster
local network = self.args['rete 1'] or self.args.rete
if self.media:inArray('film TV', 'serie TV') then
broadcaster = self:_getCategory(network, 'rete')
elseif network and self.media:inArray('ONA', 'webserie') then
self.error_category = true
end
if not network and self.media:inArray('film TV', 'ONA', 'serie TV', 'webserie') then
elseif args.tipo == 'fumetto' then
local platform = self.args['streaming 1'] or self.args.streaming
counter = #categories
broadcaster = self:_getCategory(platform, 'streaming')
if args.sottotipo then
append_table(categories, categorizza(args, 'etichetta', 'etichetta_sottotipo'))
end
if counter == #categoriesbroadcaster then
self:_addCategory(mw.message.newRawMessage(broadcaster, self.media.alias):plain())
local etichetta = {}
end
etichetta = get_category(mDelink._main({ args.etichetta }), 'etichetta')
end
if etichetta then
 
append_table(categories, categorizza(args, 'etichetta', 'etichetta'))
-- categorizzazione per tipo delle opere non suddivise per anno
end
if self.media:inArray('film direct-to-video', 'manhua', 'manhwa', 'ONA', 'webserie') then
counter = #categories
self:_addCategory(self.media.name)
if args.sottotipo then
-- categorizzazione delle opere suddivise per anno
append_table(categories, categorizza(args, 'editore', 'editore_sottotipo'))
elseif self.media.name and self.year then
local media = self.media.sottotipo ~= 'serie TV' and
self.media.alias or self.media.name
self:_addCategory(string.format('%s del %s', media, self.year))
end
 
if self.error_category == true then
self:_addCategory(error_category)
end
end
 
-- Aggiunge categorie per una lista di valori
function CategoryManager:_addCategoriesBy(table_name, gender, callback)
local base_name = table_name:match('[^_]+')
for value in extract_values(self.args, base_name) do
if table_name == 'genere' then
self:_addCategoryByGenre(value)
elseif table_name == 'paese' then
self:_addCategoryByCountry(value, gender, callback)
elseif self:_isCategoryRedundant(table_name) == false then
local category = self:_getCategory(value, table_name)
if category then
if callback then
category = callback(self, category)
end
self.tables_matched[table_name] = true
self:_addCategory(category)
end
end
if counter == #categories then
end
if args.sottotipo then
return self
categories[#categories+1] = tipo
end
 
if etichetta == nil then
-- Formatta e aggiunge una categoria
counter = #categories
function CategoryManager:_addCategory(category)
append_table(categories, categorizza(args, 'editore', 'editore'))
if self.args.categorie ~= 'no' or category == error_category then
if counter == #categories then
append_tabletable.insert(self.categories, categorizzastring.format(args, 'paese[[Categoria:%s]]', 'paese_fumetto'category))
end
return self
end
 
-- Aggiunge la categoria per Paese dopo aver individuato l'aggettivo
-- maschile o femminile, singolare o plurale adeguato
function CategoryManager:_addCategoryByCountry(country, gender, callback)
local frame = mw.getCurrentFrame()
local success, adj = pcall(frame.expandTemplate, frame, {
title = 'Template:AggNaz/' .. delink(country),
args = { gender }
})
if not success then
self.error_category = true
elseif self:_isCategoryRedundant('paese') == false then
callback(self, adj)
end
end
 
-- Aggiunge una o più categorie per genere dell'opera
function CategoryManager:_addCategoryByGenre(value)
for genre in extract_genres(value) do
if cfg.genere_wikilink[genre] then
local categories = cfg[self.genre_table_name][genre]
if categories then
for _, category in ipairs(categories) do
self:_addCategory(category)
end
end
else
self.error_category = true
end
end
end
local rete = get_category(args.rete, 'rete', true)
 
if rete then
-- Categorizza un fumetto per Paese
local pre_rete = {
function CategoryManager:_categorizeComicByCountry(adj)
['Film d\'animazione per la televisione'] = 'Film per la televisione ',
if adj == 'giapponesi' or adj == 'cinesi' or adj == 'coreani' then
['Original net anime'] = 'Webserie ',
return
['Serie televisive anime'] = 'Serie televisive ',
elseif adj == 'belgi' or adj == 'francesi' then
['Serie televisive d\'animazione'] = 'Serie televisive ',
adj = 'franco-belgi'
['Webserie d\'animazione'] = 'Webserie '
end
}
self:_addCategory('Fumetti ' .. adj)
pre_rete = pre_rete[tipo]
end
if pre_rete then
 
categories[#categories+1] = pre_rete .. rete
-- Categorizza una serie direct-to-video per Paese
function CategoryManager:_categorizeDTVFilmByCountry(adj)
self:_addCategory("Film d'animazione " .. adj)
if self.year then
self:_addCategory(string.format('Film %s del %s', adj, self.year))
end
end
 
-- Categorizza un film televisivo per Paese
function CategoryManager:_categorizeTVFilmByCountry(adj)
self:_addCategory(string.format("Film d'animazione %s per la televisione", adj))
end
 
-- Categorizza una serie TV per Paese
function CategoryManager:_categorizeTVSeriesByCountry(adj)
if adj ~= 'giapponesi' or self.args['paese 2'] then
self:_addCategory("Serie televisive d'animazione " .. adj)
end
end
 
-- Categorizza una webserie per Paese
function CategoryManager:_categorizeWebseriesByCountry(adj)
self:_addCategory('Webserie ' .. adj)
end
 
-- Cerca il nome di una categoria nella configurazione
function CategoryManager:_getCategory(key, table_name)
key = delink(key)
key = cfg['alias_' .. table_name] and cfg['alias_' .. table_name][key] or key
return cfg[table_name][key]
end
 
-- Individua la tabella dei generi idonei al tipo di opera nella configurazione
function CategoryManager:_getGenreTableName()
local table_name
if self.media:inArray('anime', 'manga') then
table_name = 'genere_animanga'
elseif self.media.tipo == 'light novel' then
table_name = 'genere_light_novel'
elseif self.media:inArray('fumetto', 'manhua', 'manhwa') then
table_name = 'genere_fumetto'
end
return table_name
end
 
-- Ricava l'anno dell'opera dalle date di inizio e fine
function CategoryManager:_getYear()
if not (self.args['data inizio'] or self.args['data fine']) then return end
local start_date = self.args['data inizio'] or ''
local end_date = self.args['data fine'] or ''
local year = (start_date .. ' ' .. end_date):match('%f[%w]%d%d%d%d%f[%W]')
if year then
return year
else
self.error_category = true
end
end
 
-- Verifica che non sia già stata aggiunta una sottocategoria
function CategoryManager:_isCategoryRedundant(table_name)
if cfg.sottocategorie[table_name] then
for _, value in ipairs(cfg.sottocategorie[table_name]) do
if self.tables_matched[value] then
return true
end
end
end
return false
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 == "Webserie d'animazione" then
categories[#categories+1] = tipo
-- Categorizzazione per anno delle opere previste
elseif args.tipo and 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' and args.sottotipo ~= 'film direct-to-video' then
if args.tipo == 'light novel' then
tipo = 'Romanzi'
elseif args.tipo == 'fumetto' then
tipo = 'Fumetti'
elseif args.sottotipo == 'special TV' or args.sottotipo == 'film TV' then
tipo = 'Film per la televisione'
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
 
----------------------------------------------------------------------------------
-- Popola l'argomento numerato in una stringa col tipo dell'opera
-- Gestisce categorie e wikilink dei generi
function CategoryManager:_substituteParameter(msg)
----------------------------------------------------------------------------------
return mw.message.newRawMessage(msg, self.media.name):plain()
end
 
-- =============================================================================
-- Funzioni esportate
-- =============================================================================
 
local p = {}
 
-- Funzione per il template FeA, categorizza la voce
function p.categorie(frame)
if mw.title.getCurrentTitle().namespace ~= 0 then return end
local args = parse_args(frame:getParent().args)
return CategoryManager:new(args):listCategories()
end
 
-- Funzione per il template FeA, elabora i wikilink dei generi
function p.generi(frame)
local ret = {}
local args = getArgs(frame, {parentOnly = not frame.args[1]})
local genreargs = parse_args(frame.args[1])
iffor genre, ==tail, ''default thenin returnextract_genres(args[1]) enddo
local wikilink = cfg.genere_wikilink[genre]
local current_page = mw.title.getCurrentTitle()
table.insert(ret, wikilink and (wikilink .. tail) or default)
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
return table.concat(ret, ', ')
for name, correct_name in pairs(cfg['genere']) do
end
if current_namespace == 0 and args.categorie ~= 'no' then
 
local tipo = {
-- Funzione per il manuale, mostra l'elenco di valori e rispettivi alias per
['anime'] = correct_name[1],
-- una data tabella nella configurazione
['fumetto'] = correct_name[2],
function p.tabella_configurazione(frame)
['light novel'] = correct_name[3],
local table_name = parse_args(frame.args)[1]
['manga'] = correct_name[1],
if not cfg[table_name] then return end
['manhua'] = correct_name[2],
local root = mw.html.create('table')
['manhwa'] = correct_name[2]
root
}
:addClass('wikitable sortable')
tipo = tipo[args.tipo]
:tag('tr')
tipo = tipo and tipo[1] and tipo[1] .. ']][[Categoria:' .. tipo[2] or tipo
:tag('th'):wikitext('Valore'):done()
category = tipo and tipo ~= '' and '[[Categoria:' .. tipo .. ']]'
:tag('th'):wikitext('Alias'):done()
:tag('th'):wikitext('Risultato'):done()
local keys, reverse_alias = {}, {}
local alias_table_name = table_name:find('genere') and 'genere' or table_name
for alias, name in pairs(cfg['alias_' .. alias_table_name] or {}) do
if not reverse_alias[name] then reverse_alias[name] = {} end
table.insert(reverse_alias[name], alias)
end
for key in pairs(cfg[table_name]) do table.insert(keys, key) end
table.sort(keys)
local pre_table_name
if table_name == 'editore_sottotipo' or table_name == 'etichetta_sottotipo' then
pre_table_name = cfg.sottotipo.fumetto
elseif table_name == 'rete' or table_name == 'streaming' then
pre_table_name = cfg.alias_sottotipo.cartone
end
for _, key in ipairs(keys) do
local result, values = {}, {}
reverse_alias[key] = reverse_alias[key] or {}
if pre_table_name then
for _, subtype in pairs(pre_table_name) do
local msg = cfg[table_name][key]
subtype = ucfirst(subtype)
table.insert(values, mw.message.newRawMessage(msg, subtype):plain())
end
elseif type(cfg[table_name][key]) == 'string' then
values = { cfg[table_name][key] }
else
values = cfg[table_name][key]
end
for _, str in ipairs(values) do
local piped = mw.ustring.match(genre, '%[%[[^%[]*|%s*' .. name .. '%s*%]%]')
if table_name ~= 'genere_wikilink' then
local pattern = (piped and '%[%[[^%[]*|%s*' or '%[%[%s*') .. name .. '%s*%]%]%a*'
str = string.format('[[:Categoria:%s]]', str)
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 and current_namespace == 0 then
result[i] = '[[Categoria:' .. error_category .. ']]'
end
table.insert(result, str)
end
table.sort(result)
result = table.concat(result, '<br />')
table.sort(reverse_alias[key])
reverse_alias[key] = table.concat(reverse_alias[key], '<br />')
root:tag('tr')
:tag('td'):wikitext(key):done()
:tag('td'):wikitext(reverse_alias[key]):done()
:tag('td'):wikitext(result):done()
end
return tostring(root)
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
'&#91;&#91;' .. name .. '&#93;&#93;'
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 = '&nbsp;'
if reverse_alias[name] then
for i,alias in ipairs(reverse_alias[name]) do
reverse_alias[name][i] = '&#91;&#91;' .. alias .. '&#93;&#93;'
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