BirbAngry emoji.png
Open Beta is out on IOS/Android, PC & Mac! Play Now for Free!

Module:MediumLink

From Castaways Wiki
Revision as of 16:49, 30 March 2024 by Jkratz01 (talk | contribs) (Created page with "local p = {} local getArgs = require('Module:Arguments').getArgs 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 '' local mode3 = args[3] o...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

local p = {}
local getArgs = require('Module:Arguments').getArgs

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 ''
    local mode3       = args[3] or args.mode3 or ''
    return p.outputMediumLink(medium, link, short, shorter, shortest, mode1, mode2, mode3)
end

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

return p