Module:Wiki

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search

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


local util_args = require("Module:ArgsUtil")
local lang = mw.getLanguage('en')
local WIKI_LOOKUP = mw.loadData('Module:Wikinames')

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

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

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

local p = {}
function p.main(frame)
	local args = util_args.merge()
	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,
		WIKI_LOOKUP.url[1],
		namevars.url,
		WIKI_LOOKUP.url[2],
		addTarget(args.target)
	)
end

return p