Questa pagina è protetta dallo spostamento
Questa pagina è protetta

Modulo:Categorie bozza

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Modulo che implementa il template:Categorie bozza.


require('strict')

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local namespace = mw.title.getCurrentTitle().namespace

	if not args[1] or namespace == 0 then return args[1] end

	local ret = args[1]
	local catlinks = {}
	local pattern = "%[%[ *[Cc][Aa][Tt][Ee][Gg][Oo][Rr][YyIi][Aa]? *: *[^%s][^\n]-%]%]"

	for catlink in string.gmatch(args[1], pattern) do
		local namespaceprefix = catlink:match('[^%[ :]+')
		local ns = mw.site.namespaces[namespaceprefix]

		if ns and ns.canonicalName == 'Category' then
			local i, j = ret:find(catlink, 1, true)
			ret = ret:sub(0, i - 1) .. ret:sub(j + 1)
			catlink = catlink
				:gsub('^%[%[ *[Cc].-: *', '')
				:gsub('^%l', string.upper)
				:gsub('^', '[[:Categoria:')
				:gsub('%|.+$', ']]')
				:gsub('^%[%[(:.-):(.+)%]%]$', '[[%1:%2|%2]]')
			table.insert(catlinks, '<li>' .. catlink .. '</li>')
		end
	end

	if #catlinks > 0 then
		local label
		local text = 'Questa pagina sarà elencata %s una volta spostata nel [[Aiuto:Namespace|namespace]] principale.'

		if #catlinks == 1 then
			label = 'Categoria'
			text = string.format(text, 'nella seguente categoria')
		else
			label = 'Categorie'
			text = string.format(text, 'nelle seguenti categorie')
		end

		local div = mw.html.create('div')
			:css('font-size', 'small')
			:wikitext(text)

		local ul = mw.html.create('ul')
			:css('margin', '0')
			:wikitext(table.concat(catlinks))

		local container = mw.html.create('div')
			:addClass('catlinks')
			:node(div)
			:wikitext('[[Aiuto:Categorie|' .. label .. ']]:')
			:node(ul)

		ret = ret .. tostring(container)
	end

	return mw.text.trim(ret)
end

return p