Zelda Wiki

OoT Navi.png

Hey! Listen!

This wiki contains spoilers! Read at your own risk!

READ MORE

Zelda Wiki
Advertisement
Zelda Wiki
10,154
pages

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


local p = {}
local cargo = mw.ext.cargo
local utilsCode = require("Module:UtilsCode")
local utilsGame = require("Module:UtilsGame")
local utilsLocalization = require('Module:UtilsLocalization')
local utilsText = require('Module:UtilsText')
local utilsTable = require('Module:UtilsTable')

function p._Main (frame)
	local args = frame.args
	return p.Main({game = args["game"], term = args["term"], link = args["link"], plural = args["plural"], display = args["display"], section = args["section"], sort = args["sort"]})
end

function p.Main(args)
	local returnedValue = ""
	
	local fetchedTerm = p.fetchRow({game = args["game"], term = args["term"]})
	if utilsCode.IsEmpty(fetchedTerm) then
		
		local displayedTerm = args["term"]
		if not utilsCode.IsEmpty(args["display"]) then
			displayedTerm = args["display"]
		end
		
		local linkedTerm = args["term"]
		if not utilsCode.IsEmpty(args["section"]) then
			linkedTerm = linkedTerm .. "#" .. args["section"]
		end
		return "<span class='explain facelift-term-invalid' title='Invalid or missing term'>[[" .. args["term"] .. "|" .. displayedTerm .. "]]</span>[[Category:Pages with Invalid or Missing Terms]][[Category:" .. utilsGame.AbbToGame(args["game"]) .. " Pages with Invalid or Missing Terms]]"
	else
		if args["link"] == "link" then
			local gameSub = utilsGame.AbbToBaseGame(args["game"], true)
			returnedValue = returnedValue .. "[[" .. args["term"]
			if not utilsCode.IsEmpty(args["section"]) then
				returnedValue = returnedValue .. "#" .. args["section"]
			elseif (gameSub ~= "Unknown" and args["game"] ~= "Series") then
				returnedValue = returnedValue .. "#" .. gameSub
			end
			returnedValue = returnedValue .. "|"
		else
			returnedValue = returnedValue .. "<span class='term'>"
		end
		
		if not utilsCode.IsEmpty(args["display"]) then
			returnedValue = returnedValue .. args["display"]
		elseif args["plural"] == "plural" then
			returnedValue = returnedValue .. fetchedTerm["plural"]
		else
			returnedValue = returnedValue .. fetchedTerm["term"]
		end
		
		if args["link"] == "link" then
			returnedValue = returnedValue .. "]]"
		else
			returnedValue = returnedValue .. "</span>"
		end
	end
	return returnedValue
end

-- Returns raw term
function p.fetchTerm(args)
	return p.fetchRow({game = args["game"], term = args["term"]})["term"]
end

function p._fetchTerm(frame)
	local args = frame.args
	return p.fetchTerm({game = args["game"], term = args["term"]})
end

-- Returns raw plural
function p.fetchPlural(args)
	return p.fetchRow({game = args["game"], term = args["term"]})["plural"]
end

function p._fetchPlural(frame)
	local args = frame.args
	return p.fetchPlural({game = args["game"], term = args["term"]})
end

-- Returns the table row of the specified game for the specified page.
-- Returns the entry for "Series" if not found.
function p.fetchRow(args)
    local tables = 'Terminologies'
    local fields = 'games, term, plural'
    local queryArgs = {
        where = "_pageName = '" .. string.gsub(string.gsub(args["term"], "&#39;", "''"), "'", "''") .. "' AND lang = '" .. utilsLocalization.GetPageLanguage() .. "'"
    }
    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, args["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