Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki

This module is the Lua interface for Special:CargoTables/TransclusionArguments, which stores information about which arguments are used with which templates/modules on what pages. It is not to be confused with Dev:Arguments nor Zelda Wiki's equivalent Module:UtilsArg, which parse and validate template arguments.

This is the main module for the following templates: In addition, this module exports the following functions.

query

query(args)

Returns

Examples

#InputOutput
Category:Articles Using Invalid Color Names#Summary
1
query({
  isValid = false,
  template = "Template:Color",
  limit = 3,
})
{
  {
    module = "Module:Color",
    argument = "TotK Shrine Quest",
    parameter = "1",
    pageInstance = "1",
    isValid = "0",
    template = "Template:Color",
    _pageName = "Dinraal",
  },
  {
    module = "Module:Color",
    argument = "TotK Red",
    parameter = "1",
    pageInstance = "1",
    isValid = "0",
    template = "Template:Color",
    _pageName = "Ganondorf",
  },
  {
    module = "Module:Color",
    argument = "TotK Red",
    parameter = "1",
    pageInstance = "2",
    isValid = "0",
    template = "Template:Color",
    _pageName = "Ganondorf",
  },
}

store

store(transclusion)

Stores data in Special:CargoTables/TransclusionArguments.

Parameters

  • transclusion
    [module]
    A module name. Defaults to mw.getCurrentFrame():getTitle().
    [args]
    Template/module arguments.
    [isValid]
    Indicates whether or not the template transclusion or module function call is valid.

Examples

#Input
2
store({
  module = "Module:Arguments",
  isValid = true,
  args = {"foo", bar = "baz"},
})

local p = {}

local utilsArg = require("Module:UtilsArg")
local utilsCargo = require("Module:UtilsCargo")

local TABLE = "TransclusionArguments"
local TABLE_LINK = "[[Special:CargoTables/"..TABLE.."]]"

function p.Main(frame)
	local utilsLayout = require("Module:UtilsLayout")
	local utilsMarkup = require("Module:UtilsMarkup")
	local utilsTable = require("Module:UtilsTable")

	local args = utilsArg.parse(frame:getParent().args, p.Templates.Arguments)
	if args.isValid then
		args.isValid = args.isValid == "yes"
	end
	local limit = args.limit and tonumber(args.limit)
	args.limit = nil

	local arguments = p.query(args)
	local allPages = utilsTable.map(arguments, "_pageName")
	allPages = utilsTable.unique(allPages)
	arguments = utilsTable.groupBy(arguments, "argument")
	arguments = utilsTable.mapValues(arguments, utilsTable._map("_pageName"))
	arguments = utilsTable.mapValues(arguments, utilsTable.unique)
	
	local rows = {}
	for argument, pages in pairs(arguments) do
		argument = "<code>"..argument.."</code>"
		local pageLinks = utilsTable.map(pages, utilsMarkup.link)
		local pageList = table.concat(pageLinks, " • ")
		table.insert(rows, {argument, #pages, pageList})
	end
	-- sort descending by # of pages then ascending by argument value
	table.sort(rows, function(a, b)
		if a[2] == b[2] then
			return a[1] < b[1]
		else
			return a[2] > b[2]
		end
	end)
	
	if limit then
		rows = utilsTable.take(rows, limit)
	end
	
	local purgeLink = mw.title.getCurrentTitle():fullUrl({
		action = "purge"
	})
	local purgeButton = string.format('<span style="margin-left: 0.5rem; font-weight: normal;">&lsqb;[%s purge]&rsqb;</span>', purgeLink)

	local wikitable = utilsLayout.table({
		caption = string.format('<div style="text-align:left">Total pages: %d %s</span>', #allPages, purgeButton),
		headers = {args.header or args.parameter, "Page Count", "Pages"},
		rows = rows,
		sortable = true,
	})
	return wikitable
end

function p.query(args)
	local isValid = args.isValid
	if isValid ~= nil then
		isValid = isValid and "1" or "0"
	end
	local rows = utilsCargo.query(TABLE, "_pageName, template, module, pageInstance, parameter, argument, isValid", {
		where = utilsCargo.allOf({
			template = args.template,
			module = args.module,
			pageInstance = args.pageInstance,
			parameter = args.parameter,
			argument = args.argument,
			isValid = isValid
		}),
		limit = args.limit,
	})
	return rows
end

function p.store(transclusion)
	return utilsArg.store(transclusion)
end

p.Templates = {
	["Arguments"] = {
		format = "block",
		purpose = string.format("Uses %s to construct a table that identifies which pages use a certain template with certain arguments.", TABLE_LINK),
		usesData = true,
		paramOrder = {"template", "parameter", "header", "argument", "isValid", "limit"},
		params = {
			template = {
				required = true,
				desc = "A template name.",
				type = "wiki-template-name",
				trim = true,
			},
			parameter = {
				required = true,
				desc = "A parameter name for the given template.",
				type = "string",
				trim = true,
			},
			header = {
				required = true,
				desc = "A header value for the resulting table.",
				trim = true,
			},
			argument = {
				desc = "A specific argument value to query for, if desired.",
				type = "string",
			},
			isValid = {
				desc = "If empty, the query will be for all arguments. If <code>yes</code>, only valid arguments are included. If <code>no</code>, only invalid arguments are included.",
				enum = {"yes", "no"},
				trim = true,
				nilIfEmpty = true,
			},
			limit = {
				desc = "Limits the number of rows in the generated table.",
				trim = true,
			},
		},
		examples = {
			{
				desc = "Pages using {{Template|Icon|TWWHD Eighth Note}}",
				args = {
					template = "Template:Icon",
					parameter = "1",
					header = "Color Name",
					argument = "TWWHD Eighth Note",
				},
			},
			{
				desc = "[[:Category:Articles Using Invalid Icon Names#Summary]]",
				args = {
					template = "Template:Icon",
					parameter = "1",
					header = "Icon Code",
					isValid = "no",
					limit = "3",
				},
			},
		}
	},
	["Arguments/Store"] = {
		purpose = "Stores data regarding template/module usage for the benefit of [[Module:Arguments]].",
		storesData = true,
		categories = {"Metatemplates"},
		paramOrder = {"template", "module", "pageInstance", "parameter", "argument", "isValid"},
		params = {
			template = {
				desc = "The template being used.",
				type = "wiki-template-name",
			},
			module = {
				desc = "The module being used.",
				type = "wiki-page-name",
			},
			pageInstance = {
				desc = "Specifies the instance of the template, when a template is used multiple times on a page.",
				type = "number",
			},
			parameter = {
				desc = "A parameter name.",
				type = "string",
			},
			argument = {
				desc = "The value of the argument corresponding to <code>parameter</code>.",
				type = "string",
			},
			isValid = {
				desc = "<code>1</code> or <code>yes</code> if the argument is valid, <code>0</code> or <code>no</code> if it is not valid.",
				enum = {"1", "0", "yes", "no"},
			},
		}
	}
}

p.Schemas = {
	store = {
		transclusion = {
			type = "record",
			required = true,
			properties = {
				{
					name = "module",
					desc = "A module name. Defaults to <code>mw.getCurrentFrame():getTitle()</code>.",
				},
				{
					name = "args",
					desc = "Template/module arguments.",
					type = "map",
					keys = { 
						oneOf = {
							{
								type = "string"
							},
							{
								type = "number"
							},
						},
					},
					values = { type = "string" },
				},
				{
					name = "isValid",
					type = "boolean",
					desc = "Indicates whether or not the template transclusion or module function call is valid.",
				},
			},
		},
	},
}

p.Documentation = {
	query = {
		params = {"args"},
		returns = string.format("Data from %s.", TABLE_LINK),
		cases = {
			{
				desc = "[[:Category:Articles Using Invalid Color Names#Summary]]",
				args = {
					{
						template = "Template:Color",
						isValid = false,
						limit = 3,
					},
				},
			},
		},
	},
	store = {
		desc = string.format("Stores data in %s.", TABLE_LINK),
		params = {"transclusion"},
		returns = nil,
		cases = {
			{
				args = {
					{
						module = "Module:Arguments",
						isValid = true,
						args = {
							[1] = "foo",
							bar = "baz",
						},
					},
				},
			},
		},
	},
}

return p