Zelda Wiki

OoT Navi.png

Hey! Listen!

This wiki contains spoilers! Read at your own risk!

READ MORE

Zelda Wiki
Advertisement
Zelda Wiki
10,152
pages

Lua error in package.lua at line 80: module 'Module:Formatting' not found.


local p = {}
local cargo = mw.ext.cargo
local formatting = require("Module:Formatting")
local utils = require("Module:Utils")
local utilsText = require('Module:UtilsText')
local utilsTable = require('Module:UtilsTable')

function p.Main( frame )
	local args = frame:getParent().args
	local term = p.fetchTerm(args[1], args[2])
	
	local returnedValue = ""
	if args[3] == "link" then
		local gameSub = formatting.AbbToGame(args[1], true)
		returnedValue = returnedValue .. "[[" .. term["term"]
		if gameSub ~= "Unknown" then
			returnedValue = returnedValue .. "#" .. gameSub
		end
		returnedValue = returnedValue .. "|"
	else
		returnedValue = returnedValue .. "<span class='term'>"
	end
	
	if args[4] == "plural" then
		returnedValue = returnedValue .. term["plural"]
	else
		returnedValue = returnedValue .. term["term"]
	end
	
	if args[3] == "link" then
		returnedValue = returnedValue .. "]]"
	else
		returnedValue = returnedValue .. "</span>"
	end
	return returnedValue
end

-- Returns the table row of the specified game for the specified page.
-- Returns the entry for "Series" if not found.
function p.fetchTerm(game, page)
    tables = 'Terminologies'
    fields = 'games, term, plural'
    local queryArgs = {
        where = '_pageName = "' .. page .. '"'
    }
    local result = cargo.query( tables, fields, queryArgs )
    
    --Looks for the game
	for _, row in pairs(result) do
		local games = utilsText.split(row.games)
		if utilsTable.keyOf(games, game) then
			return row
		end
	end
	
	--Else, looks for "Series"
	for _, row in pairs(result) do
		local games = utilsText.split(row.games)
		if utilsTable.keyOf(games, "Series") then
			return row
		end
	end
	return nil
end

return p