Module:RCChronology
| This module depends on the following other modules: |
Module purpose
Module:RCChronology is a template-specific Lua module used by the {{Infobox song}} to generate a Rivers Cuomo song chronology row. It formats and displays the previous, current, and next song titles along with their corresponding RC# or COR# values.
This module is not designed for general-purpose use and should only be invoked through the relevant infobox template.
Usage
| headerXX = {{#if:{{{prev_rc_title|}}}{{{next_rc_title|}}}|Rivers Cuomo song chronology}}
| dataXX = {{#invoke:RCChronology|makeRcRow
| prev_rc_title = {{{prev_rc_title|}}}
| this_rc_title = {{{this_rc_title|}}}
| next_rc_title = {{{next_rc_title|}}}
| rc# = {{{rc#|}}}
| cor# = {{{cor#|}}}
| use_cor# = {{{use_cor#|}}}
| name = {{{name|}}}
}}
Parameters
prev_rc_title- The title of the previous song in the chronology.
this_rc_title- (Optional) The title of the current song. If omitted, the module will fall back to
name, and then to the page name. next_rc_title- The title of the next song in the chronology.
rc#- The RC (Rivers Cuomo) number for the current song. This is the default numbering used in the chronology unless
use_cor#is set to "yes". If provided, the value will also appear in the main infobox regardless of which number is used in the chronology row. cor#- The COR (Catalog o' Riffs) number for the current song. If
use_cor#is set to "yes", this value will be used instead ofrc#in the displayed chronology numbering. If provided, the value will also appear in the main infobox even if not used for the chronology. use_cor#- (Optional) If set to "yes", the chronology will use the
cor#value for numbering instead of the defaultrc#. This is useful in cases where the RC numbering is unclear or unavailable, and the COR numbering provides a more reliable reference. name- Optional fallback name for the current song (used if
this_rc_titleis not specified).
Behavior
- If
use_cor# = yes, the module will use COR numbering, and a missing or invalidcor#will trigger a preview warning. - If either
prev_rc_titleornext_rc_titleis provided, but neitherrc#norcor#is specified, a preview warning will be displayed. - If neither
prev_rc_titlenornext_rc_titleis present, no output is produced.
Error handling
Errors and warnings are only shown during preview using Module:If preview so that they do not affect live articles.
See also
local p = {}
local ifpreview = require('Module:If preview')
-- Helper function: builds the "previous" cell
local function makePrevCell(prev, rcnum, cornum, use_cor)
if not prev or prev == "" then
return '<td style="width: 33%; padding: .2em .1em .2em .1em;"></td>'
end
local info = '"' .. prev .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum - 1)
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum - 1)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum - 1)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum - 1)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
-- Helper function: builds the "current" cell
local function makeThisCell(this, rcnum, cornum, use_cor, name)
local display_title
if this and this ~= "" then
display_title = this
elseif name and name ~= "" then
display_title = name
else
display_title = mw.title.getCurrentTitle().rootText or "Unknown"
end
local info = '"' .. "'''" .. display_title .. "'''" .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum)
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
-- Helper function: builds the "next" cell
local function makeNextCell(next_, rcnum, cornum, use_cor)
if not next_ or next_ == "" then
return '<td style="width: 33%; padding: .2em .1em .2em .1em;"></td>'
end
local info = '"' .. next_ .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum + 1)
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum + 1)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum + 1)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum + 1)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
-- Main function
function p.makeRcRow(frame)
local args = frame.args
local prev = args["prev_rc_title"]
local this = args["this_rc_title"]
local next_ = args["next_rc_title"]
local rcnum = tonumber(args["rc#"])
local cornum = tonumber(args["cor#"])
local use_cor = args["use_cor#"]
local name = args["name"]
-- Show warning if use_cor# is "yes" but cor# is missing
if use_cor and use_cor:lower() == "yes" and not cornum then
return ifpreview._warning({ "'use_cor#' is set to 'yes' but 'cor#' is missing or invalid." })
end
-- Show warning if prev or next title is provided but neither rc# nor cor# is provided
if ((prev and prev ~= "") or (next_ and next_ ~= "")) and (not rcnum and not cornum) then
return ifpreview._warning({ "Please provide a valid number for 'rc#' or 'cor#', or both." })
end
-- Only show the row if either prev or next is given
if not (prev and prev ~= "") and not (next_ and next_ ~= "") then
return ""
end
local row = '<table style="background: transparent; color: inherit; width: 100%; min-width: 100%; border-collapse: collapse; display: inline-table;">\n'
row = row .. '<tr style="line-height: 1.4em;">\n'
row = row .. makePrevCell(prev, rcnum, cornum, use_cor)
row = row .. makeThisCell(this, rcnum, cornum, use_cor, name)
row = row .. makeNextCell(next_, rcnum, cornum, use_cor)
row = row .. '</tr></table>'
return row
end
return p