Anonymous

Module:Infobox: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
1,373 bytes removed ,  8 November 2023
no edit summary
(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.)
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 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 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 Using Captions]]"
local CATEGORY_PARAM_CAPTION = "[[Category:Infoboxes using captions]]"
local CATEGORY_PARAM_NAME = "[[Category:Infoboxes Using the Name Parameter]]"
local CATEGORY_PARAM_NAME = "[[Category:Infoboxes using the name parameter]]"
local CATEGORY_BR_TAGS = "[[Category:Infoboxes Using br Tags]]"
local CATEGORY_BR_TAGS = "[[Category:Infoboxes using br tags]]"
local CATEGORY_EXP_GAME = "[[Category:Infoboxes Using Exp Game]]"
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 MSG_BR_TAGS = "Using <code><nowiki><br></nowiki></code> tags to create lists is discouraged. See [[:Category:Infoboxes Using br Tags]] for more information."
local MSG_COMMA_ESCAPE = "Lowercase character detected following comma. In infoboxes, commas are used to separate list items. All list items should be in sentence case. Literal commas can be escaped using {{Template|,}}."
local MSG_EXP_GAME = "One or more infobox fields are using {{Template|Exp Game}} when they should be using {{Template|Infobox Game Blocks}}. See [[:Category:Infoboxes Using Exp Game]] for more information"
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
function p.List(frame)
local categories = ""
listItems = frame.args[1]
listItems = listItems and utilsString.trim(listItems)
if listItems == nil or listItems == "" then
return nil
end
if string.find(listItems, "plainlist") then
return listItems -- input is already a list
end
if string.find(listItems, ", %l") then
h.warn(MSG_COMMA_ESCAPE)
categories = categories..CATEGORY_INVALID_ARGS
end
if string.find(listItems, "<br") then
h.warn(MSG_BR_TAGS)
categories = categories..CATEGORY_BR_TAGS
listItems = utilsString.split(listItems, "<br/?>")
else
listItems = utilsString.split(listItems, '%s*,%s*%f[%a]') -- %f[%a] is so we don't split numbers on their thousands separator (e.g., 1,500)
end
local listItemsUsingExpGame = utilsTable.filter(listItems, function(listItem)
return string.find(listItem, "exp%-game")
end)
if #listItems > 1 and #listItemsUsingExpGame == #listItems then
h.warn(MSG_EXP_GAME)
categories = categories..CATEGORY_EXP_GAME
end
if #listItems == 1 then
return listItems[1], categories
else
return utilsMarkup.list(listItems), categories
end
end
end
end
Line 131: Line 94:


if string.find(games, "<br") then
if string.find(games, "<br") then
h.warn(MSG_BR_TAGS)
categories = categories..CATEGORY_BR_TAGS_GAME
categories = categories..CATEGORY_BR_TAGS
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(MSG_COMMA_ESCAPE)
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(MSG_BR_TAGS)
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*,%s*%f[%a]') -- %f[%a] is so we don't split numbers on their thousands separator (e.g., 1,500)
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, ...)
_utilsError().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 Templates"},
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 Templates|infobox templates]] to turn comma-separated [[Data:Franchise|game codes]] into lists of games.",
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 Templates|infobox templates]] to generate an image when [[Template:Media]] is not used.",
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"},
},
},
},
},
List = {
desc = "Used by [[:Category:Infobox Templates|infobox templates]] to turn comma-separated input into lists.",
frameParams = {
[1] = {
name = "param",
desc = "The infobox parameter",
},
},
cases = {
{
args = {"A, B, C"}
},
{
desc = "Spaces between list elements are optional, but recommended for readability.",
args = {"A,B,C"}
},
{
desc = "Digit separators don't count.",
args = {"1,500 Rupees"},
},
{
desc = "{{Template|,}} can be used to escape commas when an item itself contains a comma.",
args = {"[[The Way of Sumo{{,}} Part I]], [[The Way of Sumo{{,}} Part II]], [[The Way of Sumo{{,}} Part III]]"},
},
{
args = {"A"},
},
{
args = {""},
},
{
args = {},
},
{
desc = "br tags are discouraged due to the poor HTML semantics.",
args = {"A<br>B<br>C"},
}
},
},
},
},