Module:Formatted appearance
Appearance
![]() | This Lua module is used on approximately 5,500 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Module:Formatted appearance is used to create a formatted style for first appearance and last appearance entries in Template:Infobox character or for other similar fictional elements.
Usage
{{#invoke:Formatted appearance|getFormattedAppearance|major_work=|minor_work=|date=}}
{{#invoke:Formatted appearance|getFormattedAppearance|major_work=|issue=|date=}}
Parameter list
Parameter | Explanation | Status |
---|---|---|
major_work
|
The title of the major work the fictional element appeared in. Major works include TV series, films, books, albums and games. See WP:MAJORWORK. | optional |
minor_work
|
The title of the minor work the fictional element appeared in. Minor works include TV episodes, chapters, songs and game missions. See WP:MINORWORK. | optional |
issue
|
The number of the comic book issue the fictional element appeared in. | optional |
date
|
The date of the publication/release of the minor work where the fictional element appeared in. | optional |
-- This module requires the use of Module:List.
local list = require('Module:List')
local p = {}
-- Local function which is used to get a correctly formatted entry.
-- Function checks if the array had a value added by checking the counter,
-- and returns the relevant result.
local function getFormattedEntry(args, counter)
if (counter == 1) then -- Check if the counter stayed the same.
return "" -- Nothing was added to array; Return empty string.
elseif (counter == 2) then -- Check if only one value was added to the array.
return args[1] -- Only one value was added to array; Return that value.
else -- The array had more than one value added.
return list.makeList("unbulleted", args) -- Call list.makeList() to retrieve the formatted plainlist.
end
end
--[[
Local function which is used to format an appearance for a comic book,
in the style of:
Line 1: <comic book title> #<volume number> (with comic book title in italics)
Line 2: <release date>
For other usages, see createGenericEntry().
The function works with the following combinations:
-- Only comic book title (example: "The Incredible Hulk").
-- Title and volume number (example: "The Incredible Hulk" and "181").
-- Title and release date (example: "The Incredible Hulk and "November 1974").
-- Title, volume number and release date (example: "The Incredible Hulk", "181" and "November 1974").
-- Only release date (example: "November 1974").
--]]
local function createComicEntry(appearanceMajor, appearanceMinor, appearanceDate)
local fullString = {} -- Variable to save the array.
local counter = 1 -- Variable to save the array counter.
if (appearanceMajor ~= nil) then -- Check if a comic book title was entered.
if (appearanceMinor == nil) then -- A comic book title was entered; Check if a volume number was entered.
fullString[counter] = appearanceMajor -- A volume was not entered; Add only the comic book title to the array.
counter = counter + 1 -- Increment counter by one.
else
fullString[counter] = appearanceMajor .. " " .. appearanceMinor -- A volume was entered; Add both to the array.
counter = counter + 1 -- Increment counter by one.
end
end
if (appearanceDate ~= nil) then -- Check if a release date was entered.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
end
return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry.
end
--[[
Local function which is used to format an appearance for most usages,
including television, film, books, songs and games, in the style of:
Line 1: <minor work title> (in quotes) (Minor works include: TV episodes, chapters, songs and game missions)
Line 2: <major work title> (in italics) (Major works include: TV series, films, books, albums and games)
Line 3: <release date>
For comic book usages, see createComicEntry().
The function works with the following combinations:
-- Only minor work title (example: "Live Together, Die Alone").
-- Minor work title and major work title (example: "Live Together, Die Alone" and "Lost").
-- Minor work title and release date (example: "Live Together, Die Alone" and "May 24, 2006").
-- Minor work title, major work title and release date (example: "Live Together, Die Alone", "Lost" and "May 24, 2006").
-- Only major work title (example: "Lost").
-- major work title and release date (example: "Lost" and "May 24, 2006").
-- Only release date (example: "May 24, 2006").
--]]
local function createGenericEntry(appearanceMajor, appearanceMinor, appearanceDate)
local fullString = {} -- Variable to save the array.
local counter = 1 -- Variable to save the array counter.
if (appearanceMinor ~= nil) then -- Check if a minor appearance was entered.
fullString[counter] = appearanceMinor -- A minor appearance was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
end
if (appearanceMajor ~= nil) then -- Check if a major appearance was entered.
fullString[counter] = appearanceMajor -- A major appearance was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
end
if (appearanceDate ~= nil) then -- Check if a release date was entered.
fullString[counter] = appearanceDate -- A release date was entered; Add it to the array.
counter = counter + 1 -- Increment counter by one.
end
return getFormattedEntry(fullString, counter) -- Call getFormattedEntry() to get a correctly formatted entry.
end
-- Local function which is used to format with a hash symbol comic book volumes.
-- For other minor works, see getFormattedGenericMinorWork().
local function getFormattedComicMinorWorkTitle(volume)
if (volume ~= nil) then -- Check if the volume is not nil.
if (string.find(volume, "#")) then -- Check if the volume already has a hash symbol.
return volume -- Hash symbol already present; Return volume.
else
local formattedString = string.gsub(volume, "%d+", "#%1") -- Hash symbol not found; Add the symbol before the volume number.
return formattedString -- Return volume.
end
else
return nil -- Volume is nil; Return nil.
end
end
-- Local function which is used to format with quotes a minor work title of most types.
-- For comic book volumes, see getFormattedComicMinorWork() (see [MOS:MINORWORK]).
local function getFormattedGenericMinorWorkTitle(title)
if (title ~= nil) then -- Check if the title is not nil.
return "\"" .. title .. "\"" -- Title is not nil; Add quotes to the title.
else
return nil -- Title is nil; Return nil.
end
end
-- Local function which is used to format with italics a major work title (see [MOS:MAJORWORK]).
local function getFormattedMajorWorkTitle(title)
if (title ~= nil) then -- Check if the title is not nil.
return "''" .. title .. "''" -- Title is not nil; Add italics to the title.
else
return nil -- Title is nil; Return nil.
end
end
-- Local function which does the actual main process.
local function _getFormattedAppearance(args)
local appearanceMajor = args['first_appearance_major_work'] or args['last_appearance_major_work'] -- Get the title of the major work.
local appearanceMinor = args['first_appearance_minor_work'] or args['last_appearance_minor_work'] -- Get the title of the minor work.
local appearanceDate = args['first_appearance_date'] or args['last_appearance_date'] -- Get the release date of the minor work.
local isComic = args['is_comic'] -- Get the value of "|is_comic=".
local formattedAppearanceMajor = getFormattedMajorWorkTitle(appearanceMajor) -- Call getFormattedMajorWorkTitle() to get a formatted major work title.
if (isComic == nil) then -- Check if the appearance is a comic book appearance.
-- The appearance is not a comic book appearance;
local formattedAppearanceMinor = getFormattedGenericMinorWorkTitle(appearanceMinor) -- Call getFormattedGenericMinorWorkTitle() to get a formatted minor work title.
return createGenericEntry(formattedAppearanceMajor, formattedAppearanceMinor, appearanceDate) -- Call createGenericEntry() to create an appearance entry.
else
-- The appearance is a comic book appearance.
local formattedAppearanceMinor = getFormattedComicMinorWorkTitle(appearanceMinor) -- Call getFormattedComicMinorWorkTitle() to get a formatted minor work title.
return createComicEntry(formattedAppearanceMajor, formattedAppearanceMinor, appearanceDate) -- Call createComicEntry() to create a comic book appearance entry.
end
end
--[[
Public function which is used to format the |first_appeared= and |last_appeared= fields.
The usage of this module allows for correct title formatting (see [MOS:MAJORWORK] and [MOS:MINORWORK]),
and correct line breaks based on guidelines (see [WP:UBLIST]).
Parameters:
-- |first_appearance_major_work= — optional; The title of the major work the fictional element first appeared in.
Major works include TV series, films, books, albums and games.
-- |last_appearance_major_work= — optional; The title of the major work the fictional element last appeared in.
-- |first_appearance_minor_work= — optional; The title of the minor work the fictional element first appeared in.
Minor works include TV episodes, chapters, songs and game missions.
-- |last_appearance_minor_work= — optional; The title of the minor work the fictional element last appeared in.
-- |first_appearance_date= — optional; The date of the publication/release of the minor work where the fictional element first appeared in.
-- |last_appearance_date= — optional; The date of the publication/release of the minor work where the fictional element last appeared in.
-- |is_comic= — optional; If the entry is a comic book volume, set to true for specialized formatting.
--]]
function p.getFormattedAppearance(frame)
local getArgs = require('Module:Arguments').getArgs; -- Use Module:Arguments to access module arguments.
local args = getArgs(frame); -- Get the arguments sent via the template.
return _getFormattedAppearance(args) -- Call _getFormattedAppearance() to perform the actual process.
end
return p