Module:Term List

local p = {} local h = {}

local Franchise = require("Module:Franchise") local Term = require("Module:Term") local utilsArg = require("Module:UtilsArg") local utilsCargo = require("Module:UtilsCargo") local utilsMarkup = require("Module:UtilsMarkup") local utilsString = require("Module:UtilsString")

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Term List"]) local categories = err and err.categoryText or "" local pages = args.pages or {} local game = args.game or "Series" local terms = p.termList(game, pages, args) if args.listType == "bullet" then terms = utilsMarkup.bulletList(terms) elseif args.listType == "plain" then terms = utilsMarkup.list(terms) else terms = table.concat(terms, ", ") end return terms, categories end

function p.termList(game, entries, options) local formattedTerms = {} local terms = {} local pages = {} for i, page in ipairs(entries) do		local pageEnd = string.find(page, "[<%[]") -- assumption: anything starting with < or [ isn't part of the page, but additional info to append after the term local additionalInfo = "" if pageEnd then additionalInfo = string.sub(page, pageEnd, #page) page = string.sub(page, 1, pageEnd - 1) if utilsString.endsWith(page, " ") then page = utilsString.trim(page) additionalInfo = " "..additionalInfo end end local pageInput = page page = mw.text.unstrip(page) if page ~= pageInput then additionalInfo = additionalInfo..string.gsub(pageInput, page, "") end formattedTerms[i] = Term.printTerm(page, game, options)..additionalInfo terms[i] = Term.fetchTerm(page, game, options) or page terms[i] = string.gsub(terms[i], , "") -- Remove quotes and formatting which may be stored with book terms, e.g. Cuccodex'' terms[i] = string.gsub(terms[i], ", "")		pages[i] = page	end	if options.storeAs then		h.storeSequence(game, options.storeAs, pages)	end

return formattedTerms, terms, pages end

function h.storeSequence(game, sequence, pages) local queryResult = utilsCargo.query("Sequences", "_pageName", {		where = utilsCargo.allOf( {				game = game, sequence = sequence },			string.format("_pageName != '%s'", mw.title.getCurrentTitle.fullText) )	})	local pageAlreadyStoringSequence = queryResult[1] and queryResult[1]._pageName if pageAlreadyStoringSequence then local utilsError = require("Module:UtilsError") utilsError.warn(string.format("The page %s is already storing sequence  for game  . This sequence will not be stored.", pageAlreadyStoringSequence, sequence, game)) return end local seenPages = {} -- prevents duplicates local ordinality = 1 for i, page in ipairs(pages) do		if not seenPages[page] then seenPages[page] = true mw.getCurrentFrame:expandTemplate({				title = "Term List/Store",				args = {					game = game,					sequence = sequence,					subject = page,					ordinality = ordinality,				}			}) ordinality = ordinality + 1 end end end

function p.Documentation return { termList = { params = {"game", "pages", "options"}, returns = { "A list the same size as  with Module:Term applied to each page.", "A list the same size as  with Module:Term applied to each page. The page name is returned as-is if it stores no terms.", },			cases = { {					desc = "Link's relatives", args = {"TWWHD", {"Link's Grandma", "Aryll (little sister) "}, { link = true }}, expect = { {							"Grandma", "Aryll (little sister) ", },						{"Grandma", "Aryll"}, },				},			}		}	} end

p.Templates = { ["Term List"] = { purpose = "Applies or  to a list of page names.", paramOrder = {1, 2, "link", "plural", "listType", "storeAs"}, params = { [1] = {				name = "game", required = true, enum = Franchise.enum({ includeSeries = true }), type = "string", desc = "A game code.", nilIfEmpty= true, },			[2] = {				name = "pages", required = true, type = "content", desc = "Comma-separated list of wiki page names.", trim = true, nilIfEmpty= true, split = true, },			link = { type = "boolean", desc = "If present, the  option of  is applied.", canOmit = true, },			plural = { type = "boolean", desc = "If present, is used instead of .", canOmit = true, },			listType = { type = "string", enum = {"bullet", "comma", "plain"}, default = "comma", desc = "Sets the list formatting.", canOmit = true, },			storeAs = { type = "string", desc = "Stores the list in the Sequences Cargo table for use by Template:Sort Value and Module:Sequences.", canOmit = true, trim = true, nilIfEmpty = true, },		}	},	["Term List/Store"] = { purpose = "Stores in-game sequences that can be used by Template:Sort Value, Module:Sequences, and maybe some day Template:Translation Page.", storesData = true, usage = "This template is automatically used via Template:Gallery List or Template:Term List when the  parameter is set.", paramOrder = {"game", "sequence", "subject", "ordinality"}, params = { game = { type = "string", required = true, desc = "A game code from Data:Franchise.", },			sequence = { type = "string", required = true, desc = "A sequence name.", },			subject = { type = "wiki-page-name", required = true, desc = "An article name on the wiki.", },			ordinality = { type = "number", required = true, desc = "The position of  in the given sequence.", },		},	}, }

return p