Module:Contentious topics/make link

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

local p = {}

function p.makeTopicLink(frame)
	-- call from a template
	args = require('Module:Arguments').getArgs(frame)
	return p._makeTopicLink(args['code'] or args[1])
end

function p._makeTopicLink(code)
	-- call from a module
	local topicSubpage = mw.getCurrentFrame():expandTemplate{
		title = "Contentious topics/list",
		args = { ['topic-subpage'] = code }
	}
	if code == nil then
		return '<span class="error">Error! No contentious topic code given</span>'
	elseif topicSubpage == '' then
		return '<span class="error">Error! <code>' .. code .. '</code> is not a valid contentious topic code</span>'
	end
	
	return '[[' .. topicSubpage ..'|'
		.. mw.ustring.gsub(topicSubpage, 'Wikipedia:Contentious topics/', '')
		.. ']]'
end

return p