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.


require('Modulo:No globals')

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()
	local pattern = "%[%[ *([Cc][Aa][Tt][Ee][Gg][Oo][Rr][YyIi][Aa]?) *: *[^%s][^\n]-%]%]"

	for colonprefix in text:gmatch(pattern) do
		local ns = mw.site.namespaces[colonprefix]

		if ns and ns.canonicalName == 'Category' then
			return '[[Categoria:Bozze con categorie da disabilitare]]'
		end
	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