Module:Wiki

From Fortnite Esports Wiki
Jump to: navigation, search

To edit the documentation or categories for this module, click here.


local lang = mw.getLanguage('en')
local LOOKUP = mw.loadData('Module:Wikinames')

function lookup(str)
	local namevars = LOOKUP.wikis[lang:lc(str)]
	if type(namevars) == 'table' then
		return namevars
	elseif type(namevars) == 'string' then
		return LOOKUP.wikis[namevars]
	else
		return { long = 'Unknown Wiki', short = 'Unknown', image = '', url = 'esports' }
	end
end

function addTarget(target)
	if not target then
		target = mw.title.getCurrentTitle().text
	end
	return (LOOKUP.url[3] .. target):gsub(' ','_') or ''
end

function makeURL(url, target)
	local output = {
		LOOKUP.url[1],
		url,
		LOOKUP.url[2],
		addTarget(target)
	}
	return table.concat(output,'')
end

local p = {}
function p.main(frame)
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	return p[args[2] or 'wikilongname'](args[1] or '')
end

function p.wikilongname(str)
	return lookup(str).long
end

function p.wikiurl(str, args)
	return makeURL(lookup(str).url, args.target)
end

function p.longlinked(str, args)
	local namevars = lookup(str)
	return string.format(
		'[%s %s]',
		makeURL(namevars.url, args.target),
		namevars.long
	)
end

function p.onlyimagelinked(str, args)
	local namevars = lookup(str)
	return string.format(
		'<span title="%s">[[File:Infobox %slogo std.png|link=%s%s%s%s]]</span>',
		args.title or string.format(
			'%s on the %s wiki',
			args.titletarget or args.target or 'View this page',
			namevars.long
		),
		namevars.image,
		LOOKUP.url[1],
		namevars.url,
		LOOKUP.url[2],
		addTarget(args.target)
	)
end

return p