Jump to content

Module:Portal maintenance status

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Evad37 (talk | contribs) at 02:35, 8 June 2018 (adjust level of error). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function cleanupArgs(argsTable)
	local cleanArgs = {}
	for key, val in pairs(argsTable) do
		if type(val) == 'string' then
			val = val:match('^%s*(.-)%s*$')
			if val ~= '' then
				cleanArgs[key] = val
			end
		else
			cleanArgs[key] = val
		end
	end
	return cleanArgs
end

p.main = function(frame)
	local parent = frame.getParent(frame)
	local args = cleanupArgs(frame.args)
	local demo = args.demo and true or false
	local portalContent
	if demo then
		portalContent = '{{' .. args.demo .. '}}'
		if args.demo2 then
			portalContent = portalContent  .. '{{' .. args.demo2 .. '}}'
		end
	else
		local talkTitle = mw.title.getCurrentTitle()
		if talkTitle.namespace ~= 101 then
			return error('Wrong namespace', 0)
		end
		local portalTitle = mw.title.new("Portal:"..talkTitle.text)
		portalContent = portalTitle:getContent()
	end

	local isMaintained = mw.ustring.find(portalContent, '%{%{%s*[Mm]aintained portal flag%s*%}%}') and true or false
	local isNonstandard = mw.ustring.find(portalContent, '%{%{%s*[Nn]on%-standard portal flag%s*%}%}') and true or false

	if (not isMaintained) and (not isNonstandard) then
		return ''
	end

	local text = "This portal " .. ( isMaintained and "'''is [[Wikipedia:WikiProject Portals#Specific portal maintainers|maintained]]'''" or '' ) .. ( ( isMaintained and isNonstandard ) and ' and ' or '' ) .. ( isNonstandard and "has a '''non-standard layout'''" or '' ) .. '.'
	local subtext = "Please [[WP:CAREFUL|take care]] when editing, especially if using [[WP:ASSISTED|automated editing software]]" .. ( isMaintained and ", and seek [[Wikipedia:Consensus|consensus]] before making major changes." or '.')

	return text .. '<br>' .. '<span style="font-size:90%">' .. subtext .. '</span>'
end

return p