Modulo:Controllo certificazioni

Modulo per rilevare certificazioni FIMI di pubblicazioni antecedenti al 2009 nei parametri standard del template:Album. Genera una categoria che segnala la necessità di spostare queste certificazioni in parametri appositi.


local p = {}

local cat = '[[Categoria:Pubblicazioni antecedenti al 2009 con certificazione FIMI da spostare]]'

function p.main(frame)
	local year = tonumber(frame:getParent().args.anno)
	if not year or year > 2008 then return end
	local content = mw.title.getCurrentTitle():getContent()
	content = content:gsub('{{ *[Aa]lbum[ \n]*|', '\r{{Album\n|') .. '\r'
	local awards = { "d'oro", "di platino", "di diamante" }
	-- non usare gsplit, è molto più lento di gmatch
	for subcontent in string.gmatch(content, '{{Album\n|(.-)\r') do
		for _, v in ipairs(awards) do
			local pattern = '^(.-)|%s*numero dischi ' .. v .. '%s*=(.+)$'
			local pre, post = ('|' .. subcontent):match(pattern)
			if post then
				-- evita falsi positivi col template Brano musicale
				if pre:match('{{ *[Bb]rano musicale *|') then break end
				post = post:sub(1, 2000)
				local n = 0
				for s, c in string.gmatch(post, '(.-)([|{}]+)') do
					if s:match('FIMI') then
						return cat
					end
					n = n + select(2, c:gsub('{{', ''))
					n = n - select(2, c:gsub('}}', ''))
					if n == 0 and c:match('|$') or n < 0 then
						break
					end
				end
			end
		end
	end
end

return p