Module:Cite Print

local p = {} local h = {} local data = mw.loadData("Module:Cite Print/Data")

local Cite = require("Module:Cite") local Franchise = require("Module:Franchise") local Language = require("Module:Language") local utilsArg = require("Module:UtilsArg")

local CAT_BOOK_QUOTES = "" local CAT_INVALID_ARGS = ""

-- We encapsulate Module:Error so that it is only transcluded on pages that actually have errors local function errFn(msg, warn) local utilsError = require("Module:UtilsError") return utilsError.error(msg, warn) end local function warn(msg) local utilsError = require("Module:UtilsError") utilsError.warn(msg) end

function p.Book(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Cite Book"]) local categories = err and err.categoryText or "" if args.quote then categories = categories..CAT_BOOK_QUOTES end local bookTitle = args.book if args.book and not h.hasItalics(args.book) then local bookLink = Franchise.link(args.book) if not bookLink then warn(string.format(" must be a code from Data:Franchise or else be written with italics.", bookTitle)) categories = categories..CAT_INVALID_ARGS else bookTitle = bookLink end end local phraseLink = args.book and Franchise.phraseLink(args.book) -- for manga and comics and such if phraseLink and phraseLink ~= "" then local byAuthor = string.find(phraseLink, " by ") if byAuthor then phraseLink = phraseLink.sub(phraseLink, 1, byAuthor - 1) -- strip the "by " part end bookTitle = phraseLink end if not bookTitle then bookTitle = errFn("book title required", true) categories = categories..CAT_INVALID_ARGS end local publisher if args.book and args.lang then local bookData = data.books[args.book] and data.books[args.book][args.lang] if not bookData then warn(string.format("No data exists for book  in language  . See Module:Cite Print/Data.", args.book, args.lang)) categories = categories..CAT_INVALID_ARGS end bookTitle = string.format("%s", Franchise.article(args.book) or bookData.display, bookData.display) publisher = bookData.publisher end if not publisher then publisher = args.publisher and p.getPublisherFromShortcut(args.publisher) or (args.book and Franchise.publisher(args.book)) end if not publisher then -- if after all that we still didn't manage to get a publisher... publisher = errFn("publisher required", true) categories = categories..CAT_INVALID_ARGS end local source = args source.title = bookTitle source.publisher = publisher local citation = h.printCitation(source, args.quote, args.character)

return citation, categories end -- Backwards compatibility for deprecated feature function p.getPublisherFromShortcut(publisher) local publishers = { ["enix"] = "Enix Corporation", ["nintendo"] = "Nintendo Co., Ltd.", ["piggyback"] = "Piggyback Interactive Limited", ["prima"] = "Prima Games", ["soleil"] = "Les Éditions Soleil", ["tokuma shoten"] = "Tokuma Shoten Publishing Co., Ltd.", }	local fullName = publishers[string.lower(publisher)] if fullName then warn(string.format("Publisher shortcuts are a deprecated feature. Please enter the full publisher name  instead of  ", fullName, publisher)) return fullName..CAT_INVALID_ARGS else return publisher end end

function p.Guide(frame) local Guide = require("Module:Guide")

local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Cite Guide"]) local categories = err and err.categoryText or "" if args.quote then categories = categories..CAT_BOOK_QUOTES end local guideArgs = {args.game, args.guide, "-"} local guideTitle, guideCategories, guidePublisher = Guide.guide(guideArgs, "Guide", true) categories = categories..guideCategories if args.year or args.edition then local editionYear = h.concat(", ", {args.edition, args.year}) guideTitle = guideTitle.." ("..editionYear..")" end local source = { title = guideTitle, publisher = guidePublisher, page = args.page, translation = args.translation, romanization = args.romanization, }	return h.printCitation(source, args.quote)..categories end

function p.Magazine(frame) local Magazine = require("Module:Magazine")

local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Cite Magazine"]) local categories = err and err.categoryText or "" if not args.magazine then return errFn("Magazine name required")..categories end -- We use italics as the cue for a custom magazine name - otherwise the magazine must be one supported by Template:Magazine if h.hasItalics(args.magazine) then args.title = args.magazine else local err = utilsArg.enum(Magazine.enum, args.magazine, "magazine") if err then categories = categories..""..err.category.."" end args.title = ""..args.magazine.."" if args.date then args.date = string.format("%s", args.magazine, args.date, args.date) end end return h.printCitation(args, args.quote, args.interviewee, args.url)..categories end

function p.Manual(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Cite Manual"]) local categories = err and err.categoryText or "" if not args.game and not args.product then categories = categories..CAT_INVALID_ARGS return errFn("game required"), categories end

if args.game then local gameLink = Franchise.link(args.game) if not gameLink then warn(string.format("Invalid game . See Data:Franchise for supported games.", args.game)) categories = categories..CAT_INVALID_ARGS else args.title = gameLink end end args.title = (args.title or args.game or args.product).." manual" if args.lang then local lect = Language.getLect(args.lang) if lect then args.title = string.format("%s, %s localization", args.title, lect.name) end end if args.version then args.title = string.format("%s, %s version", args.title, args.version) end return h.printCitation(args, args.quote), categories end

function h.printCitation(source, quote, speaker, archive) local sourceComponents = h.formatSourceComponents(source) local citation = Cite.printCitation({		quote = quote,		translation = source.translation,		romanization = source.romanization,		speaker = speaker,		sourceComponents = sourceComponents,	}) if archive then citation = string.format("%s ([%s archive])", citation, archive) end return citation end function h.formatSourceComponents(source) local volume, issue, page = source.volume, source.issue, source.page if volume then volume = "vol. "..volume end if issue then issue = "no. "..issue end if page then page = "pg. "..page else page = "&#91;which page?&#93;" end local title = mw.getCurrentFrame:preprocess(source.title) local titleVolumeIssue = h.concat(" ", {title, volume, issue}) local sourceComponents = {titleVolumeIssue, source.publisher, source.edition, source.date, page} return sourceComponents end function h.concat(separator, items) local strings = {} for i = 1, table.maxn(items) do		if items[i] and items[i] ~= "" then table.insert(strings, items[i]) end end return table.concat(strings, separator) end

function h.hasItalics(str) return string.find(str, ".*") end

function p.Data -- Performance optimization; importing this at the top with the others adds processing time to Template:Cite -- these dependencies are only needed on Module:Cite Print/Data/Documentation local Language = require("Module:Language") local utilsLayout = require("Module:UtilsLayout") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable") local tableRows = {} for i, bookCode in ipairs(Franchise.enum({ includeNonfiction = true })) do		local bookData = data.books[bookCode] if bookData then table.insert(tableRows, {				{					content = string.format(" ", Franchise.article(bookCode) or bookCode, bookCode),					rowspan = utilsTable.size(bookData) + 1,					styles = {						["text-align"] = "center",					},				},			}) for i, langCode in ipairs(Language.enum) do				local bookLangData = bookData[langCode] if bookLangData then local lect = Language.getLect(langCode) table.insert(tableRows, {						{							content = lect.flags[1] .. " " .. lect.abbr,							sortValue = lect.lang,						},						string.format("%s", Franchise.article(bookCode) or bookLangData.display, bookLangData.display),						bookLangData.publisher					}) end end end end local booksTable = utilsLayout.table({		headers = {"Book", "Language", "Displayed Title", "Publisher"},		rows = tableRows,		sortable = true,	}) booksTable = utilsMarkup.heading(3, utilsMarkup.anchor("books", "Books in Other Languages"))..booksTable

return booksTable end

function p.Schemas local Language = require("Module:Language") return { Data = { type = "record", required = true, properties = { {					name = "books", required = true, desc = "Associates a book code from Data:Franchise to information about the publication of the book in other languages. Used by Template:Cite Book.", type = "map", keyPlaceholder = "bookCode", keys = { type = "string" }, values = { type = "map", keyPlaceholder = "langCode", keys = { type = "string", enum = Language.enum, desc = "A language code from Module:Language/Data.", },						values = { type = "record", properties = { {									name = "display", required = true, type = "string", desc = "The text to display when referring to the book - typically its subtitle.", },								{									name = "publisher", required = true, type = "string", desc = "The book's publisher." },							},						},					},				},			},		},	} end

local params = { translation = { type = "content", desc = "A translation of  if the quote is not in English.", trim = true, nilIfEmpty = true, },	romanization = { type = "string", desc = "Romanization of  if the quote is not written in the Latin alphabet. This is primarily intended for term references and can be omitted when quoting entire sentences.", trim = true, nilIfEmpty = true, },	page = { desc = "The cited page(s).", type = "string", required = CATEGORY_MISSING_PAGE, trim = true, nilIfEmpty = true, }, } p.Templates = { ["Cite Book"] = { format = "inline", paramOrder = {"quote", "character", "book", "publisher", "lang", "edition", "volume", "issue", "page"}, boilerplate = { tabs = { {					label = "Fiction", desc = "For citing manga, comics, novels, and other works of fiction.", params = {"quote", "book", "character", "publisher", "page"}, },				{					label = "Nonfiction", desc = "For citing books such as .", params = {"quote", "book", "publisher", "page"}, },				{					label = "Nonfiction (Alternative Language)", desc = "For citing books such as in other languages.", params = {"quote", "book", "lang", "page"}, },				{					label = "All Parameters", params = {"quote", "character", "book", "publisher", "lang", "edition", "volume", "issue", "page"}, },			},		},		params = { quote = { desc = "The quote to cite.", type = "content", trim = true, nilIfEmpty = true, },			character = { desc = "The name of the character speaking the quote. Use this for works of fiction such as manga, comics, and gamebooks.", type = "string", trim = true, nilIfEmpty = true, },			book = { desc = " The code for a book entry at Data:Franchise. To cite a book that is not licensed by Nintendo and therefore not defined in Data:Franchise, write the name of the book with italics. A book name without italics is considered invalid if it is not in Data:Franchise. ", type = "content", required = true, trim = true, nilIfEmpty = true, },			lang = { type = "string", desc = "A language code - used when citing books such as in other languages. See Module:Cite Print/Data for supported languages.", trim = true, nilIfEmpty = true, },			publisher = { desc = " The publisher of the book. Leave this empty when citing a book from Data:Franchise - the publisher will be automatically generated. ", type = "content", trim = true, nilIfEmpty = true, },			edition = { desc = "The book's edition.", type = "string", trim = true, nilIfEmpty = true, },			volume = { desc = "The volume number for the book quote, if applicable.", type = "string", trim = true, nilIfEmpty = true, },			issue = { desc = "A comic issue number.", type = "string", trim = true, nilIfEmpty = true, },			page = params.page },	},	["Cite Guide"] = { format = "inline", paramOrder = {"quote", "game", "guide", "page", "edition", "year", "romanization", "translation"}, boilerplate = { hiddenParams = {"romanization", "translation"}, tabs = { {					label = "Guide", params = {"quote", "game", "guide", "page"}, },				{					label = "Guide Edition", params = {"quote", "game", "guide", "page", "edition", "year"}, },			},		},		params = { quote = { desc = "The quote to cite.", type = "content", trim = true, nilIfEmpty = true, },			translation = params.translation, romanization = params.romanization, game = { desc = "The game abbreviation associated with the guide. See Template:Guide.", type = "string", required = true, trim = true, nilIfEmpty = true, },			guide = { aliases = {"publisher"}, desc = "The guide abbreviation. See Template:Guide. This parameter was formerly named .", type = "string", required = true, trim = true, nilIfEmpty = true, },			page = params.page, edition = { desc = "The edition of the guide.", type = "string", trim = true, nilIfEmpty = true, },			year = { desc = "The year of release of the magazine edition.", type = "string", trim = true, nilIfEmpty = true, },		},		examples = { {				quote = "", game = "TLoZ", guide = "Nintendo", page = "5", },			{				quote = "", game = "TLoZ", guide = "NES Game Atlas", page = "5", },			{				quote = "This is a quote.", game = "TWWHD", guide = "Prima", page = "5", edition = "Premiere Edition", year = "2011", },			{				desc = "The  parameter was renamed to   but the former is still supported.", args = { quote = "", game = "ALttP", publisher = "Nintendo", page = "5", },			},			{				desc = "Error handling", args = { quote = "", game = "OoT3D", guide = "invalid guide", page = "", },			},			{				quote = "", game = "OoT", guide = "", page = "5", },			{				quote = "", game = "", guide = "", page = "5", }		},	},	["Cite Magazine"] = { purpose = "Citing magazines according to Guidelines:References.", format = "inline", paramOrder = {"quote", "translation", "romanization", "interviewee", "magazine", "publisher", "volume", "issue", "date", "page", "url"}, boilerplate = { hiddenParams = {"translation", "romanization"}, tabs = { {					label = "Magazine", params = {"quote", "magazine", "publisher", "volume", "issue", "date", "page", "url"}, },				{					label = "Magazine Interview", params = {"quote", "magazine", "interviewee", "publisher", "volume", "issue", "date", "page", "url"}, }			},			},		params = { quote = { desc = "The quote to cite.", type = "content", trim = true, nilIfEmpty = true, },			translation = params.translation, romanization = params.romanization, interviewee = { desc = "If  is an answer from an inteview, enter the interviewee's name.", type = "string", trim = true, nilIfEmpty= true, },			magazine = { desc = " The name of the magazine. Use a magazine name supported by Template:Magazine. To cite a magazine that is not licensed by Nintendo and therefore not supported by Template:Magazine, write the name of the magazine with italics. A magazine name without formatting is considered invalid if it is not supported by Template:Magazine. ", type = "content", required = true, trim = true, nilIfEmpty = true, },			publisher = { desc = " The publisher of the magazine. Leave this empty if citing a magazine supported by Template:Magazine. ", type = "content", trim = true, nilIfEmpty = true, },			date = { desc = "The of the cited magazine issue.", type = "string", required = true, trim = true, nilIfEmpty = true, },			volume = { desc = "The volume number of the cited magazine issue.", type = "string", trim = true, nilIfEmpty = true, },			issue = { desc = "The issue number of the cited magazine issue.", type = "string", trim = true, nilIfEmpty = true, },			url = { desc = "An archive.org URL where the magazine can be read. Use the URL specifically for the cited page.", type = "string", trim = true, nilIfEmpty = true, },			page = params.page, },		examples = { {				quote = "If you distract its attention and sneak up, you might be able to ride it.", magazine = "Nintendo Magazine", publisher = "", date = "Winter 2021", volume = "", issue = "", url = "https://archive.org/details/nintendomagazine-2021winter-english/16.jpg", page = "16", },			{				quote = "", magazine = "Nintendo Power", publisher = "", date = "July/August 1988", volume = "", issue = "1", url = "https://archive.org/details/nintendo_power_issue1/page/n25", page = "26", },			{				quote = "", magazine = "Nintendo Fun Club News", publisher = "", date = "Fall 1987", volume = "1", issue = "3", url = "https://archive.org/details/NintendoFunClubMagazines/Nintendo%20Fun%20Club%20News%20Issue%203%20%28Fall%201987%29/page/n7", page = "8", },			{				quote = "I have already talked to Mr. Miyamoto about this so I am comfortable releasing this information--this title [Skyward Sword] takes place before Ocarina of Time.", magazine = "Official Nintendo Magazine", date = "December 2010", issue = "62", page = "51", interviewee = "Eiji Aonuma", },			{				desc = "To cite a magazine not licensed by Nintendo, write the magazine name with italics.", args = { quote = "Out: 10/05", magazine = "CD-i Magazine", publisher = "Haymarket Publishing", date = "April 1996", volume = " ", issue = "17", url = "https://archive.org/details/cdi-uk-17", page = "12", },			},			{				desc = "Citing a magazine written in another language", args = { quote = "Ga verder naar het volgende level en dood de Jawbees.", translation = "Continue to the next level and kill the Jawbees.", magazine = "CD Interactief", volume = "2", issue = "11", date = "November 1995", publisher = "HUB Uitgevers", page = "30", },			},			{				desc = "Error handling", args = { magazine = "invalid magazine", date = "October 2022", page = "", }			},			{				magazine = "", },		}	},	["Cite Manual"] = { format = "inline", paramOrder = {"quote", "translation", "romanization", "game", "product", "lang", "version", "page"}, boilerplate = { tabs = { {					label = "Game Manual", params = {"quote", "game", "page"}, },				{					label = "Game Version", params = {"quote", "game", "version", "page"}, },				{					label = "Product Manual", params = {"quote", "product", "page"}, },				{					label = "Manual Translation", params = {"quote", "translation", "romanization", "game", "lang", "page"} },			},		},		params = { quote = { desc = "The quote to cite.", type = "content", trim = true, nilIfEmpty = true, },			translation = params.translation, romanization = params.romanization, game = { desc = "The game abbreviation associated with the manual. See Data:Franchise for supported games.", type = "string", trim = true, nilIfEmpty = true, },			lang = { type = "string", enum = Language.enum, desc = " A language code identifying the game localization cited in, if the quote is not from the North American localization.  Can also be omitted when citing a British localization, but only if that is the only English localization (e.g. ).", trim = true, nilIfEmpty = true, },			product = { desc = "Used instead of  to cite the manual of a product not defined at Data:Franchise - a console manual, for example.", type = "string", trim = true, nilIfEmpty = true, },			version = { desc = "Used to specify a specific port or game mode of the game, if applicable.", type = "string", trim = true, nilIfEmpty = true, },			page = { desc = "The cited page or pages (format: 54 or 34-36).", type = "string", required = CATEGORY_MISSING_PAGE, trim = true, nilIfEmpty = true, },		},	}, }

return p