Modulo che implementa le funzionalità del template:Bozza.

Legge i vari template:Richiesta revisione bozza presenti nella pagina e include il template:Bozza/avviso coi parametri adeguati.


local p = {}

local function removeFalsePositives(str)
	return str:gsub('<!%-%-.-%-%->', ''):gsub('<nowiki>.-</nowiki>', '')
end

local function getPageContent()
	local text = mw.title.getCurrentTitle():getContent() or ''

	return removeFalsePositives(text)
end

function p.controllo_categorie(frame)
	local text = getPageContent()

	if text:find("%[%[%s*[Cc]ategoria%s*:%s*[^%s].-%]%]" ) then
		return '[[Categoria:Bozze con categorie impreviste]]'
	end
end

function p.stato_richiesta(frame)
	if frame.args[1] == 'S' then return frame.args[1] end

	local text = getPageContent()
	local declined = false

	for str in text:gmatch('%{%{ *[Rr]ichiesta *revisione *bozza *(%|.-%})%}') do
		if str:find('| *data *= *[^ %|%}]') then
			if not str:find('%| *1? *=? *respinta *[%|%}]') then
				return 'R'
			end
			declined = true
		end
	end

	if declined then
		return frame.args[1] == 'A' and 'A' or 'N'
	end

	return frame.args[1]
end

return p