Module:MediumLink

From Nookipedia, the Animal Crossing wiki
Revision as of 23:58, November 6, 2022 by PanchamBro (talk | contribs)

Module documentation (view)


Usage

This module is used to display the link of a medium in the Animal Crossing series in various different ways. These are then transcluded through link templates, where the editor can switch how they display the link under different conditions.

While it can be used inside other Lua modules if require("Module:MediumLink") is added, it is recommended to use through standard templates as is. Note that {{SSB4}} uses the Module:SSB4Link instead of this module.

Creating a new medium link

{{#invoke:MediumLink|main|medium=<medium>|link=<link (OPTIONAL)>|short=<short>|shorter=<shorter (OPTIONAL)>|shortest=<shortest (OPTIONAL)>|<mode1>|<mode2>|<mode3>}}
outputMediumLink(medium, link, short, shorter, shortest, mode1, mode2, mode3)

When creating a new medium link to be used on pages, the following syntax is provided.

  • medium is the name of the medium (e.g. Animal Crossing: New Horizons)
  • link is used to provide the direct link to the medium.
  • short is the name of the medium under a shorthand name (e.g. New Horizons)
  • shorter is the name of the medium under a long acronym name (e.g. ACNH)
  • shortest is the name of the medium under a short acronym name (e.g. NH)
  • mode1, mode2, and mode3 should be reversed for the editors to decide what conditions to use to display the link.

If Gekijōban Doubutsu no Mori is declared as the medium, then linkindicator is automatically declared with "🎬 " and appended to the medium name if nolink is not declared.

Note that while shorter and shortest are optional, if they are not declared and the editor tries to declare shorter or shortest, an error will pop up, describing that they are either using invalid parameters or that the parameters needed to generate the link is empty. See Category:Pages with incorrect usage of link template for a list of pages with this error.

Example

{{#invoke:MediumLink|main|medium=Animal Crossing: New Horizons|short=New Horizons|shorter=ACNH|shortest=NH|{{{1|}}}|{{{2|}}}|{{{3|}}}}}
outputMediumLink("Animal Crossing: New Horizons", , "New Horizons", "ACNH", "NH", mode1, mode2, mode3)

"Animal Crossing: New Horizons" is the medium, with "New Horizons" as short, "ACNH" as shorter and "NH" as shortest. Since link is not declared, the default link is "Animal Crossing: New Horizons".

When mode1 is "nolink" and mode2 is "short", the output is: New Horizons

When mode1 is "sm" and mode2 is "shortest", the output is: NH

This page is fully-protected to prevent editing by non-administrator users

local p = {}

local function getArgs(frame)
    local args = {}
    for key, value in pairs(frame:getParent().args) do
        args[key] = value
    end
    for key, value in pairs(frame.args) do
        args[key] = value
    end
    return args
end

function p.main(frame)
    local args        = getArgs(frame)
    local medium      = args.medium or ''
    local link        = args.link or ''
    local short       = args.short or ''
    local shorter     = args.shorter or ''
    local shortest    = args.shortest or ''
    local mode1       = args[1] or args.mode1 or ''
    local mode2       = args[2] or args.mode2 or ''
    return p.outputMediumLink(medium, link, short, shorter, shortest, mode1, mode2)
end

function p.outputMediumLink(medium, link, short, shorter, shortest, mode1, mode2)
	local function isEmpty(s)
		return s == nil or s == ''
	end
	local print = ''
	local linkindicator = ''
	if medium == "Gekijōban Doubutsu no Mori" then
		linkindicator = "🎬 "
	end
	if not isEmpty(mode1) then
		if mode1 == "nolink" then
			if not isEmpty(short) and mode2 == "short" then
				print = "''" .. short .. "''"
			elseif not isEmpty(shorter) and mode2 == "shorter" then
				print = shorter
			elseif not isEmpty(shortest) and mode2 == "shortest" then
				print = shortest
			elseif isEmpty(mode2) then
				print = "''" .. medium .. "''"
			end
		elseif not isEmpty(short) and mode1 == "short" then
			if mode2 == "nolink" then
				print = "''" .. short .. "''"
			elseif isEmpty(mode2) then
				if not isEmpty(link) then
					print = "''[[" .. link .. "|" .. linkindicator .. short .. "]]''"
				else
					print = "[[" .. medium .. "|" .. linkindicator .. "''" .. short .. "'']]"
				end
			end
		elseif not isEmpty(shorter) and mode1 == "shorter" then
			if mode2 == "nolink" then
				print = shorter
			elseif isEmpty(mode2) then
				if not isEmpty(link) then
					print = "[[" .. link .. "|" .. linkindicator .. shorter .. "]]"
				else
					print = "[[" .. medium .. "|" .. linkindicator .. shorter .. "]]"
				end
			end
		elseif not isEmpty(shortest) and mode1 == "shortest" then
			if mode2 == "nolink" then
				print = shortest
			elseif isEmpty(mode2) then
				if not isEmpty(link) then
					print = "[[" .. link .. "|" .. linkindicator .. shortest .. "]]"
				else
					print = "[[" .. medium .. "|" .. linkindicator .. shortest .. "]]"
				end
			end
		else
			print = '\'\'\'<span class="error" dir="ltr" lang="en">Invalid parameters detected! Did you entered the wrong parameters or are the parameters needed to generate this game link empty?</span>\'\'\'[[Category:Pages with incorrect usage of game link template]]'
		end
	else
		if not isEmpty(link) then
			print = "[[" .. link .. "|"  .. linkindicator .. "''" .. medium .. "'']]"
		else
			print = "[[" .. linkindicator .. "''" .. medium .. "'']]"
		end
	end
	return print
end

return p