MannedTooth (talk | contribs) No edit summary |
MannedTooth (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
local utilsTable = require('Module:UtilsTable') |
local utilsTable = require('Module:UtilsTable') |
||
− | function p.Main( |
+ | function p.Main (frame) |
− | local args = frame |
+ | local args = frame.args |
+ | return p._Main(args["game"], args["term"], args["link"], args["plural"], args["display"]) |
||
+ | end |
||
+ | |||
+ | function p._Main(game, term, link, plural, display) |
||
local returnedValue = "" |
local returnedValue = "" |
||
− | local term = p.fetchRow( |
+ | local term = p.fetchRow(game, term) |
if utilsCode.IsEmpty(term) then |
if utilsCode.IsEmpty(term) then |
||
return "<span style='color:red;'>INVALID OR MISSING TERM</span>[[Category:Pages With Invalid or Missing Terms]]" |
return "<span style='color:red;'>INVALID OR MISSING TERM</span>[[Category:Pages With Invalid or Missing Terms]]" |
||
else |
else |
||
if args[3] == "link" then |
if args[3] == "link" then |
||
− | local gameSub = utilsGame.AbbToBaseGame( |
+ | local gameSub = utilsGame.AbbToBaseGame(game, true) |
− | returnedValue = returnedValue .. "[[" .. |
+ | returnedValue = returnedValue .. "[[" .. term |
− | if (gameSub ~= "Unknown" and |
+ | if (gameSub ~= "Unknown" and game ~= "Series") then |
returnedValue = returnedValue .. "#" .. gameSub |
returnedValue = returnedValue .. "#" .. gameSub |
||
end |
end |
Revision as of 02:34, 7 May 2019
Lua error in package.lua at line 80: module 'Module:UtilsCode' not found.
local p = {}
local cargo = mw.ext.cargo
local utilsCode = require("Module:UtilsCode")
local utilsGame = require("Module:UtilsGame")
local utilsText = require('Module:UtilsText')
local utilsTable = require('Module:UtilsTable')
function p.Main (frame)
local args = frame.args
return p._Main(args["game"], args["term"], args["link"], args["plural"], args["display"])
end
function p._Main(game, term, link, plural, display)
local returnedValue = ""
local term = p.fetchRow(game, term)
if utilsCode.IsEmpty(term) then
return "<span style='color:red;'>INVALID OR MISSING TERM</span>[[Category:Pages With Invalid or Missing Terms]]"
else
if args[3] == "link" then
local gameSub = utilsGame.AbbToBaseGame(game, true)
returnedValue = returnedValue .. "[[" .. term
if (gameSub ~= "Unknown" and 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[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
end
return returnedValue
end
-- Returns raw term
function p.fetchTerm(game, page)
return p.fetchRow(game, page)["term"]
end
function p._fetchTerm(frame)
local args = frame.args
return p.fetchTerm(args[1], args[2])
end
-- Returns raw plural
function p.fetchPlural(game, page)
return p.fetchRow(game, page)["plural"]
end
-- Returns the table row of the specified game for the specified page.
-- Returns the entry for "Series" if not found.
function p.fetchRow(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