Module:Term

local p = {} local cargo = mw.ext.cargo local utilsCode = require("Module:UtilsCode") local utilsError = require("Module:UtilsError") local utilsGame = require("Module:UtilsGame") local utilsLocalization = require('Module:UtilsLocalization') local utilsString = require('Module:UtilsString') 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 " " .. displayedTerm .. " " else if args["link"] == "link" then local gameSub = utilsGame.AbbToBaseGame(args["game"], true) returnedValue = returnedValue .. ""		else			returnedValue = returnedValue .. " "		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 .. " "		end end return returnedValue end

-- Returns raw term, or nil if none found function p.fetchTerm(args) local row = p.fetchRow({game = args["game"], term = args["term"]}) if row then return row.term else utilsError.warn(string.format("Invalid or missing term  for game  ", args.term, args.game)) end 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 = utilsString.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 = utilsString.split(row.games) if utilsTable.keyOf(games, "Series") then return row end end return nil end

return p