Modulo:CategoriaMusicale
Da Wikipedia, l'enciclopedia encyclopedia
local p = {}
local subject2wikilink = { ['Album'] = 'album musicali', ['Album video'] = 'album video', ['Brani musicali'] = 'brani musicali', ['Cantanti'] = 'cantanti', ['Disc jockey'] = 'disc jockey', ['EP'] = 'EP', ['Gruppi musicali'] = 'gruppi musicali', ['Musicisti'] = 'musicisti', ['Singoli'] = 'singoli' }
--[[ verifica quali delle chiavi della tabella subject2wikilink è presente all'inizio del titolo della categoria e la memorizza questa funzione è chiamata sia da p.main che dal template, tramite il codice ]] function p.get_subject() local title = mw.title.getCurrentTitle().text for k, v in pairs(subject2wikilink) do if title:sub(1,string.len(k))==k then return k end end return nil end
--[[ questa è la funzione principale che genera il wikicodice per il template, da invocare con il codice Categorie correlate:
- Disc jockey genere
- Cantanti genere
- Album genere
- Musicisti genere
- Singoli genere
- EP genere
- Gruppi musicali genere
- Album video genere
- Brani musicali genere
]] function p.main(frame) local args = frame.args local genre = args[1] local forced_link = args[2] local subject = p.get_subject() local text = ""
if subject then text = "Questa categoria raggruppa voci su " .. subject2wikilink[subject] .. " [[" if forced_link ~= "" then text = text .. forced_link .. "|" end text = text .. genre .. "]].\n\n" end
text = text .. "Categorie correlate:\n
if subject == "Gruppi musicali" or subject == "Musicisti" or subject == "Cantanti" or subject == "Disc jockey" then text = text .. string.format("\n* %s per nazionalità", subject, subject) end if subject then text = text .. string.format("\n* %s per genere (tutti)", subject, subject) end
-- aggiungi link alle categorie correlate se diverse da quella attuale for k, v in pairs(subject2wikilink) do if subject ~= k then text = text .. string.format("\n* %s %s", k, genre, k, genre) end end
text = text .. ""
return text end
return p