Módulo:Fusión de historiales

Este módulo no tiene página de documentación[crear]
local p = {}
function p.main(frame)
	local params = frame:getParent().args or {}
	local ended = params['fin'] and (params['fin'] == 'sí' or params['fin'] == 'yes' or params['fin'] == '1')
	local html = mw.html.create()
	local ul = html:tag('ul')
	for n, name in pairs(params) do
		if type(n) == 'number' then
			local li = ul:tag('li')

			local method = 1
			local pageExists = nil
			local pageSize = 0
			local isRedirect = nil

			if not ended then
				if method == 1 then
					local ret, obj = pcall(mw.title.new, name)
					if ret then
						local n = obj:getContent()
						pageExists = (n ~= nil)
						pageSize = (pageExists and #n) or 0
						isRedirect = obj.isRedirect
					end
				elseif method == 2 then
					pageExists = (n == 1) or (frame:callParserFunction( 'PROTECTIONEXPIRY:edit', name ) ~= '')
					if pageExists then
						pageSize = tonumber( frame:callParserFunction( 'PAGESIZE:' .. name, 'R' ) )
					end
				end
			end
	
			-- show link
			if n == 1 then
				li:wikitext('[[' .. name .. ']]')
			else
				if ended or not pageExists or isRedirect then
					li:wikitext( name )
				else
					li:tag('span')
						:attr('class', 'plainlinks')
						:wikitext( frame:preprocess('[{{fullurl:' .. name .. '}} ' .. name .. ']') )
						:done()
				end
			end
	
			-- show actions
			li:tag('span')
				:attr('class', 'plainlinks')
				:css('font-size', 'smaller')
				:wikitext(' ( ')
				:wikitext( frame:preprocess('[{{fullurl:' .. name .. '|action=edit}} editar]') )
				:wikitext(' | ')
				:wikitext( frame:preprocess('[{{fullurl:' .. name .. '|action=history}} historial]') )
				:wikitext(' | ')
				:wikitext( frame:preprocess('[{{fullurl:Especial:MoverPágina/{{urlencode:' .. name .. '}}|wpReason=Fusionar%20historiales&wpNewTitle=}} trasladar]') )
				:wikitext(' | ')
				:wikitext( frame:preprocess('[{{fullurl:Especial:Restaurar/{{urlencode:' .. name .. '}}}} restaurar]') )
				:wikitext(' ) ')
				:done()
		
			-- show aditional information
			if n == 1 then
				li:wikitext(' — nombre final después de la fusión')
			else
				if not ended then
					li:wikitext(' — artículo a fusionar')
				else
					li:wikitext(' — fusión finalizada')
				end
			end
			if not ended and pageSize > 0 then
				li:tag('span')
					:css('font-size', 'smaller')
					:wikitext(' / Otros datos: ' .. pageSize .. ' bytes')
					:done()
			end
			if not ended and isRedirect then
				li:tag('span')
					:css('font-size', 'smaller')
					:wikitext(' [[Archivo:Dialog-warning-orange.svg|link=|18px]] es una redirección')
					:done()
			end
			if not ended and not pageExists then
				li:tag('span')
					:css('font-size', 'smaller')
					:wikitext(' [[Archivo:Dialog-warning.svg|link=|18px]] no existe la página')
					:done()
			end
			li:done()
		end
	end
	ul:done()
	return tostring( html )
end

return p