Module:League

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

To edit the documentation or categories for this module, click here. This module returns values from {{Leaguenames}}m, which defines variables for leagues. Unlike {{Teamnames}}m, none of the outputs is guaranteed to be globally unique. That is to say, while in {{Teamnames}}m, you are guaranteed that |link= is a unique identifier of a team, in this case there is no single output like that. Leagues can change logos across years, so league name and link are not unique; and two different leagues could use the same logo, so logo is not unique.

While one may consider <League>_<Year> as a candidate for unique identifier, the reality is that a league could change logo mid-season. If we were to use this syntax it would be at the cost of potentially a huge amount of technical debt.

Therefore, when storing league data it is advised to store a specific property just for calling this module.

FAQ:

Why is this a module and not a Cargo table?

This way we don't have to use Cargo every single time when pulling a league image (for example in News). Also, if it were a Cargo table, on some level it would have to be "in between" [Leagues] and [Tournaments] anyway: The former doesn't allow for changes in status across years, and the latter would be cumbersome to keep updated and also will not include as many entries as are needed for this table. Additionally, this table will need to be interacted with by users significantly more than the other two, since any image uploaded for a tournament to be listed in news will need to be added to this list.

So how does this work with [Tournaments]?

The value of |LeagueIconKey= given in that module is the league's unique key for this module. That table will store all of its metadata as well as the raw key input by the user, to preserve uniqueness.

local util_args = require('Module:ArgsUtil')
local util_table = require('Module:TableUtil')
local lang = mw.getLanguage('en')

local h = {}

function h.getInfo(str, settings)
	local vars = util_args.lookupVars(str, mw.loadData('Module:Leaguenames'), true)
	if not vars then
		vars = {
			link = str,
			long = str,
			short = str,
			image = 'Unknown Infobox Image - Tournament.png'
		}
	end
	settings.vars = util_table.shallowClone(vars)
	if settings.link then
		settings.vars.link = settings.link
	end
	return vars
end

function h.getClass(str)
	if not str then return '' end
	return ('|class=%s-logo-std'):format(str)
end

local p = {}

function p.league(frame)
	local args = util_args.merge(true)
	local str = lang:lc(args[1] or '')
	local style = lang:lc(args[2] or 'onlyimage')
	return p[style](str, args)
end

function p.main(frame)
	local args = util_args.merge(true)
	local str = lang:lc(args[1] or '')
	local style = lang:lc(args[2] or 'onlyimage')
	return p[style](str, args)
end

function p.newsitem(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return('<div class="news-league-icon">[[File:%s|link=%s|%spx%s]]</div>&nbsp;[[%s|%s]]'):format(
		settings.vars.image,
		settings.vars.link,
		settings.size or 25,
		h.getClass(settings.vars.class),
		settings.vars.link,
		settings.vars.short
	)
end

function p.onlyimage(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return ('[[File:%s|link=|%spx%s]]'):format(
		settings.vars.image,
		settings.size or 25,
		h.getClass(settings.vars.class)
	)
end

function p.leaguename(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return settings.vars.long
end

function p.leagueshortname(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return settings.vars.short
end

function p.onlyimagelinked(str, settings)
	if not settings then settings = {} end
	h.getInfo(str, settings)
	return ('[[File:%s|link=%s|%spx%s]]'):format(
		settings.vars.image,
		settings.vars.link,
		settings.size or 25,
		h.getClass(settings.vars.class)
	)
end

return p