56,117
edits
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
local Franchise = require("Module:Franchise") | local Franchise = require("Module:Franchise") | ||
local utilsArg = require("Module:UtilsArg") | local utilsArg = require("Module:UtilsArg") | ||
local utilsMarkup = require("Module:UtilsMarkup") | local utilsMarkup = require("Module:UtilsMarkup") | ||
local utilsPackage = require("Module:UtilsPackage") | |||
local utilsString = require("Module:UtilsString") | local utilsString = require("Module:UtilsString") | ||
local utilsTable = require("Module:UtilsTable") | local utilsTable = require("Module:UtilsTable") | ||
local _utilsError = utilsPackage.lazyLoad("Module:UtilsError") | |||
local CATEGORY_INVALID_ARGS = "[[Category:"..Constants.category.invalidArgs.."]]" | local CATEGORY_INVALID_ARGS = "[[Category:"..Constants.category.invalidArgs.."]]" | ||
Line 45: | Line 46: | ||
if string.find(listItems, "<br") then | if string.find(listItems, "<br") then | ||
_utilsError().warn(BR_TAGS_MSG) | |||
return listItems..CATEGORY_BR_TAGS | return listItems..CATEGORY_BR_TAGS | ||
end | end | ||
Line 60: | Line 61: | ||
function p.Games(frame) | function p.Games(frame) | ||
local games = frame.args[1] | local games = frame.args[1] | ||
local categories = "" | |||
if games == nil or games == "" then | if games == nil or games == "" then | ||
return nil | return nil | ||
Line 65: | Line 68: | ||
if string.find(games, "<br") then | if string.find(games, "<br") then | ||
_utilsError().warn(BR_TAGS_MSG) | |||
categories = categories..CATEGORY_BR_TAGS | |||
return games, categories | |||
end | end | ||
games = utilsString.trim(games) | games = utilsString.trim(games) | ||
games = utilsString.split(games) | games = utilsString.split(games) | ||
Line 92: | Line 95: | ||
local properCode = Franchise.code(game) | local properCode = Franchise.code(game) | ||
if not link then | if not link then | ||
_utilsError().warn(string.format("Invalid entry <code>%s</code>. See [[Data:Franchise]] for a list of valid entries.", game)) | |||
return nil | return nil | ||
elseif properCode and properCode ~= game then | elseif properCode and properCode ~= game then | ||
_utilsError().warn(string.format("<code>%s</code> should be written as <code>%s</code>", game, properCode)) | |||
end | end | ||
return link | return link | ||
Line 101: | Line 104: | ||
function p.GameBlocks(frame) | function p.GameBlocks(frame) | ||
local args = frame:getParent().args | |||
local categories = "" | |||
local seenParams = {} | |||
local blocks = {} | |||
for i, game in ipairs(Franchise.enum({ includeSeries = true })) do | |||
seenParams[game] = true | |||
local listItems = args[game] | |||
listItems = listItems and utilsString.trim(listItems) | |||
listItems = listItems and utilsString.nilIfEmpty(listItems) | |||
if listItems then | |||
table.insert(blocks, { | |||
game = Franchise.display(game), | |||
listItems = args[game], | |||
}) | |||
end | |||
end | |||
for k, v in pairs(args) do | |||
if not seenParams[k] then | |||
local errorMessage = string.format("Invalid game <code>%s</code>", k) | |||
_utilsError().warn(errorMessage) | |||
categories = categories..CATEGORY_INVALID_ARGS | |||
end | |||
end | |||
local html = mw.html.create("ul") | |||
:addClass("infobox-game-blocks") | |||
for i, block in ipairs(blocks) do | |||
local gameList = html:tag("li") | |||
:tag("span") | |||
:addClass("infobox-game-blocks__game") | |||
:wikitext(block.game) | |||
:done() | |||
:tag("ul") | |||
:addClass("infobox-game-blocks__game-list") | |||
local listItems = block.listItems | |||
if string.find(listItems, "<br") then | |||
_utilsError().warn(BR_TAGS_MSG) | |||
categories = categories..CATEGORY_BR_TAGS | |||
gameList:tag("li") | |||
:wikitext(listItems) | |||
:done() | |||
else | |||
listItems = utilsString.split(listItems) | |||
for j, listItem in ipairs(listItems) do | |||
gameList:tag("li") | |||
:wikitext(listItem) | |||
end | |||
end | |||
end | |||
return tostring(html), categories | |||
end | end | ||