Modulo:Gastronomia: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
Nessun oggetto della modifica
disattivo categoria al di fuori del NS0
 
(20 versioni intermedie di un altro utente non mostrate)
Riga 14:
 
function p.autocat(frame)
 
 
local args = getArgs(frame)
local current_page = mw.title.getCurrentTitle()
local current_namespace = current_page.namespace
local debug = args['debug']
local debug_values = {}
-- non categorizzare se in ns:0
if current_namespace ~= 0 and not debug then
return ''
end
local errori = {}
local new_categories = {}
local categoria = args['categoria']
local regioni = {}
local paesi = {}
local categoria = args['categoria'] or ''
categoria = cfg.categorie_alias[categoria] or categoria
local piatto_cat = cfg.categorie[categoria]
local paesi = get_list(args, 'paese', 5)
local regioni = get_list(args, 'regione', 15)
local province = get_list(args, 'provincia', 5)
-- Creo categorie in base alla categoria del piatto
if categoriapiatto_cat == nil or cfg.categorie[categoria] =~= nil then
-- categoria base del piatto
errori[#errori+1] = 'Categoria non riconosciuta o non esistente'
else
local piatto_cat = cfg.categorie[categoria]
if piatto_cat.cat_base ~= '' then
new_categories[#new_categories+1] = piatto_cat.cat_base
end
if piatto_cat.paese_cat ~= '' then
 
local paesi = get_list(args, 'paese',local escludi_paesi = 5){}
local escludi_regioni = {}
for _,paese in ipairs(paesi) do
-- prima parte categoria per province (o comunque suddivisione di regione)
local found_regione = false
for _, provincia in ipairs(province) do
if paese == 'Italia'and piatto_cat.regioni then
regioniif =cfg.province[provincia] get_list(args, 'regione', 15)then
if #regioni > 0 thennew_cat_provincia = 'Cucina ' .. cfg.province[provincia].categoria
forif _,mw.title.new('Categoria:' regione.. in ipairs(regioninew_cat_provincia).exists dothen
-- checkNon sela esistecat_base è diversa da 'Cucina ' la categoria eregionale/nazionale aggiunginon gruppoè eparente settadi found_regione'Cucina a<provincia>' true
localif new_catpiatto_cat.paese_cat == 'Cucina ' then
if escludi_regioni[cfg.regioni_fuori_standardprovince[provincia].regione] then= true
new_cat = piatto_catescludi_paesi[cfg.paese_cat .. regioni[cfg.regioni_fuori_standardprovince[provincia].regione].paese] = true
else
new_cat = piatto_cat.paese_cat .. frame:expandTemplate{ title = 'AggNaz', args = { piatto_cat.prefix , regione }}
end
if mw.title.new('Categoria:' .. new_cat).exists then
new_categories[#new_categories+1] = new_cat
found_regione = true
end
new_categories[#new_categories+1] = new_cat_provincia
end
end
end
-- seconda parte categoria per regioni
for _,regione in ipairs(regioni) do
if cfg.regioni[regione] and not escludi_regioni[regione] then
local new_cat = ''
if cfg.regioni[regione].forza_preposizione then
new_cat = piatto_cat.paese_cat .. cfg.regioni[regione].preposizione .. regione
else
new_cat = piatto_cat.paese_cat .. cfg.regioni[regione][piatto_cat.prefix]
end
if mw.title.new('Categoria:' .. new_cat).exists then
new_categories[#new_categories+1] = new_cat
escludi_paesi[cfg.regioni[regione].paese] = true
end
end
end
-- paeseterza diversoparte dacategoria 'Italia'per oppure non ha trovato una regionepaese
iffor not_,paese found_regionein thenipairs(paesi) do
if piatto_cat.internazionale andnot escludi_paesi[paese == 'Internazionale'] then
new_categories[#new_categories+1]if paese == 'Piatti internazionaliInternazionale' then
else if piatto_cat.internazionale then
new_categories[#new_categories+1] = piatto_cat.paese_cat .. frame:expandTemplate{ title ='Piatti internazionali'AggNaz', args = { piatto_cat.prefix , paese }}
end
else
new_categories[#new_categories+1] = piatto_cat.paese_cat .. frame:expandTemplate{ title = 'AggNaz', args = { piatto_cat.prefix , paese }}
end
end
end
Riga 70 ⟶ 88:
local riconoscimento = args['riconoscimento']
if riconoscimento then
riconoscimento = mw.ustring.lowerupper(riconoscimento)
if cfg.riconoscimenti[riconoscimento] then
if #paesi == 1 and cfg.riconoscimenti_nazionalita[paesi[1]] and riconoscimento ~= 'IGP-PTN' and riconoscimento ~= 'DOP-PTN' then
new_categories[#new_categories+1] = cfg.riconoscimenti[riconoscimento]
new_categories[#new_categories+1] = cfg.riconoscimenti[riconoscimento] .. cfg.riconoscimenti_nazionalita[paesi[1]]
else
new_categories[#new_categories+1] = cfg.riconoscimenti[riconoscimento]
end
elseif riconoscimento == 'PAT' then
local regione_found = false
if #regioni > 0 then
for _, regione in ipairs(regioni) do
if cfg.prefissi_regioniregioni[regione] and cfg.regioni[regione].paese == 'Italia' then
new_categories[#new_categories+1] = 'Prodotti agroalimentari tradizionali ' .. cfg.prefissi_regioniregioni[regione].preposizione .. regione
else regione_found = true
new_categories[#new_categories+1] = 'Prodotti agroalimentari tradizionali italiani'
end
end
elseend
if not regione_found then
new_categories[#new_categories+1] = 'Prodotti agroalimentari tradizionali italiani'
end
else
Riga 90 ⟶ 113:
end
-- categoria di errore per immagini assenti
if not debug and not args['immagine'] then
new_categories[#new_categories+1] = 'Immagini richieste - cucina'
end
Riga 98 ⟶ 121:
end
local wrapped = {}
if debug then
for _,cat in ipairs(new_categories) do
wrapped[#wrapped+1] = '[[:Categoria:' .. cat .. '|'.. cat .. ']] '
end
wrapped[#wrapped+1] = '<br />'
for _, debug_value in ipairs(debug_values) do
wrapped[#wrapped+1] = debug_value
end
 
else
for _,cat in ipairs(new_categories) do
wrapped[#wrapped+1] = '[[Categoria:' .. cat .. ']]'
end
end
return table.concat(wrapped)
end
 
function p.categoria(frame)
local args = getArgs(frame)
local categoria = args['categoria'] or ''
categoria = cfg.categorie_alias[categoria] or categoria
local piatto_cat = cfg.categorie[categoria]
if piatto_cat ~= nil then
return piatto_cat.voce
end
local ret = '<strong class="error">Categoria non riconosciuta</strong>'
if mw.title.getCurrentTitle().namespace == 0 then
ret = ret .. '[[Categoria:Errori di compilazione del template Gastronomia]]'
end
return ret
end
 
-- Ritorna la lista di categorie
function p.list_categorie(frame)
 
local tableNode = mw.html.create("table"):addClass('wikitable'):addClass('sortable')
tableNode:tag('tr')
:tag('th'):wikitext('Categoria'):done()
:tag('th'):wikitext('Alias'):done()
:tag('th'):wikitext('Voce'):done()
local cat_list = {}
for cat, _ in pairs(cfg.categorie) do
cat_list[#cat_list+1] = cat
end
table.sort(cat)
for _,cat in ipairs(cat_list) do
local table_row = tableNode:tag('tr')
table_row:tag('td'):wikitext(cat)
local alias_cat = {}
for k,v in pairs(cfg.action_alias) do
if v == cat then alias_cat[#alias_cat+1] = k end
end
table_row:tag('td'):wikitext(table.concat(alias_cat, ', '))
table_row:tag('td'):wikitext(cfg.categorie[cat].voce)
end
return tostring(tableNode)
end
 
function p.list_province(frame)
 
local tableNode = mw.html.create("table"):addClass('wikitable'):addClass('sortable')
tableNode:tag('tr')
:tag('th'):wikitext('Provincia'):done()
:tag('th'):wikitext('Regione'):done()
:tag('th'):wikitext('Categoria'):done()
local prov_list = {}
for cat, _ in pairs(cfg.province) do
prov_list[#prov_list+1] = cat
end
table.sort(prov_list)
for _,prov in ipairs(prov_list) do
local table_row = tableNode:tag('tr')
table_row:tag('td'):wikitext(prov)
table_row:tag('td'):wikitext(cfg.province[prov].regione)
table_row:tag('td'):wikitext('[[:Categoria:Cucina ' .. cfg.province[prov].categoria .. '|Cucina ' .. cfg.province[prov].categoria .. ']]')
end
return tostring(tableNode)
end