87,250
edits
Rayolinels (talk | contribs) (Changed the list-split regex to not chop off the first character after the comma when the comma is not followed by whitespace. Also added a documentation case for this.) |
TriforceTony (talk | contribs) No edit summary |
||
(16 intermediate revisions by 4 users not shown) | |||
Line 7: | Line 7: | ||
local utilsArg = require("Module:UtilsArg") | local utilsArg = require("Module:UtilsArg") | ||
local utilsMarkup = require("Module:UtilsMarkup") | local utilsMarkup = require("Module:UtilsMarkup") | ||
local utilsString = require("Module:UtilsString") | local utilsString = require("Module:UtilsString") | ||
local utilsTable = require("Module:UtilsTable") | local utilsTable = require("Module:UtilsTable") | ||
local utilsVar = require("Module:UtilsVar") | local utilsVar = require("Module:UtilsVar") | ||
local CATEGORY_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]" | local CATEGORY_INVALID_ARGS = "[[Category:"..require("Module:Constants/category/invalidArgs").."]]" | ||
local CATEGORY_PARAM_CAPTION = "[[Category:Infoboxes | local CATEGORY_PARAM_CAPTION = "[[Category:Infoboxes using captions]]" | ||
local CATEGORY_PARAM_NAME = "[[Category:Infoboxes | local CATEGORY_PARAM_NAME = "[[Category:Infoboxes using the name parameter]]" | ||
local CATEGORY_BR_TAGS = "[[Category:Infoboxes | local CATEGORY_BR_TAGS = "[[Category:Infoboxes using br tags]]" | ||
local | local CATEGORY_BR_TAGS_GAME = "[[Category:Infoboxes using br tags in game fields]]" | ||
local CLASS_TOOLTIP = require("Module:Constants/class/tooltip") | local CLASS_TOOLTIP = require("Module:Constants/class/tooltip") | ||
local DEFAULT_IMG_SIZE = "320x320px" | local DEFAULT_IMG_SIZE = "320x320px" | ||
local VAR_IS_AFTER_INFOBOX = require("Module:Constants/var/isAfterInfobox") | local VAR_IS_AFTER_INFOBOX = require("Module:Constants/var/isAfterInfobox") | ||
Line 42: | Line 37: | ||
if args.caption and args.caption ~= "" then | if args.caption and args.caption ~= "" then | ||
categories = categories..CATEGORY_PARAM_CAPTION | categories = categories..CATEGORY_PARAM_CAPTION | ||
end | |||
for k, v in pairs(args) do | |||
if string.find(v, "<br") then | |||
h.warn("It appears the <code>%s</code> field may be using <code><nowiki><br></nowiki></code> tags to create a list. If so, please use [[Template:List]] or [[Template:Infobox Game Blocks]] instead. See [[:Category:Infoboxes using br tags]] for more information.", k) | |||
categories = categories..CATEGORY_BR_TAGS | |||
end | |||
end | end | ||
Line 79: | Line 81: | ||
end | end | ||
return image | return image | ||
end | end | ||
end | end | ||
Line 131: | Line 94: | ||
if string.find(games, "<br") then | if string.find(games, "<br") then | ||
categories = categories..CATEGORY_BR_TAGS_GAME | |||
categories = categories.. | |||
games = utilsString.split(games, "<br>") | games = utilsString.split(games, "<br>") | ||
games = utilsTable.flatMap(games, utilsString._split("<br/>")) | games = utilsTable.flatMap(games, utilsString._split("<br/>")) | ||
Line 156: | Line 118: | ||
return game | return game | ||
end | end | ||
local game, notes = utilsMarkup.separateMarkup(game) | |||
local link = Franchise.link(game) | local link = Franchise.link(game) | ||
local properCode = Franchise.code(game) | local properCode = Franchise.code(game) | ||
Line 164: | Line 127: | ||
h.warn(string.format("<code>%s</code> should be written as <code>%s</code>", game, properCode)) | h.warn(string.format("<code>%s</code> should be written as <code>%s</code>", game, properCode)) | ||
end | end | ||
return link | return link..notes | ||
end | end | ||
Line 218: | Line 181: | ||
listItems = listItems and utilsString.nilIfEmpty(listItems) | listItems = listItems and utilsString.nilIfEmpty(listItems) | ||
if listItems and string.find(listItems, ", %l") then | if listItems and string.find(listItems, ", %l") then | ||
h.warn( | h.warn("Lowercase character detected following comma. Within <code>Template:Infobox Game Blocks</code>, commas are used to separate list items. All list items should be in sentence case. Literal commas can be escaped using {{Template|,}}.") | ||
categories = categories..CATEGORY_INVALID_ARGS | categories = categories..CATEGORY_INVALID_ARGS | ||
end | end | ||
if listItems and string.find(listItems, "<br") then | if listItems and string.find(listItems, "<br") then | ||
h.warn( | h.warn("Using <code><nowiki><br></nowiki></code> tags to create lists is discouraged. Use commas instead, as this template treats them as delimiters. See [[Template:Infobox Game Blocks]] for more information.") | ||
categories = categories..CATEGORY_BR_TAGS | categories = categories..CATEGORY_BR_TAGS | ||
listItems = utilsString.split(listItems, "<br>") | listItems = utilsString.split(listItems, "<br>") | ||
listItems = utilsTable.flatMap(listItems, utilsString._split("<br/>")) | listItems = utilsTable.flatMap(listItems, utilsString._split("<br/>")) | ||
elseif listItems then | elseif listItems then | ||
listItems = utilsString.split(listItems, '%s*, | listItems = utilsString.split(listItems, '%s*,%f[^,%d]%s*') -- %f[^,%d] is so we don't split numbers on their thousands separator (e.g., 1,500) | ||
end | end | ||
if listItems then | if listItems then | ||
Line 237: | Line 200: | ||
local hasDiv = listItems and listItems[1] and string.find(listItems[1], "<div") -- See [[Minuet of Forest]] "Notes" field, for example | local hasDiv = listItems and listItems[1] and string.find(listItems[1], "<div") -- See [[Minuet of Forest]] "Notes" field, for example | ||
if listItems and #listItems > 1 or hasDiv then | if listItems and #listItems > 1 or hasDiv then | ||
blocks.compact = true | |||
end | |||
if listItems and listItems[1] and string.find(listItems[1], "plainlist") then | |||
blocks.compact = true | blocks.compact = true | ||
end | end | ||
Line 258: | Line 224: | ||
end | end | ||
function h.warn(msg) | function h.warn(msg, ...) | ||
local utilsError = require("Module:UtilsError") | |||
local warnMessage = string.format(msg, ...) | |||
utilsError.warn(warnMessage, { | |||
includeInstance = false, | includeInstance = false, | ||
}) | }) | ||
Line 274: | Line 242: | ||
format = "block", | format = "block", | ||
purpose = string.format("[[Guidelines:Articles#Infobox|Infobox]] for [[:Category:%s|%s]].", plural, string.lower(plural)), | purpose = string.format("[[Guidelines:Articles#Infobox|Infobox]] for [[:Category:%s|%s]].", plural, string.lower(plural)), | ||
categories = {"Infobox | categories = {"Infobox templates"}, | ||
boilerplate = { | boilerplate = { | ||
separateRequiredParams = false, | separateRequiredParams = false, | ||
Line 327: | Line 295: | ||
name = "producer", | name = "producer", | ||
desc = "The producer(s) of the film.", | desc = "The producer(s) of the film.", | ||
type = "content", | |||
}, | |||
{ | |||
name = "writer", | |||
desc = "The writer(s) of the film.", | |||
type = "content", | |||
}, | |||
{ | |||
name = "production", | |||
desc = "The companies producing the film.", | |||
type = "content", | |||
}, | |||
{ | |||
name = "distributor", | |||
desc = "The companies distributing the film.", | |||
type = "content", | type = "content", | ||
}, | }, | ||
Line 377: | Line 360: | ||
return { | return { | ||
Games = { | Games = { | ||
desc = "Used by [[:Category:Infobox | desc = "Used by [[:Category:Infobox templates|infobox templates]] to turn comma-separated [[Data:Franchise|game codes]] into lists of games.", | ||
frameParams = { | frameParams = { | ||
[1] = { | [1] = { | ||
Line 410: | Line 393: | ||
}, | }, | ||
Image = { | Image = { | ||
desc = "Used by [[:Category:Infobox | desc = "Used by [[:Category:Infobox templates|infobox templates]] to generate an image when [[Template:Media]] is not used.", | ||
frameParams = { | frameParams = { | ||
[1] = { | [1] = { | ||
Line 444: | Line 427: | ||
args = {"{{Plural|Series|Cyber Pico Bloom}} are never seen in-game"}, | args = {"{{Plural|Series|Cyber Pico Bloom}} are never seen in-game"}, | ||
}, | }, | ||
}, | }, | ||
}, | }, |
edits