Module:Cite
From Zoophilia Wiki
Jump to navigationJump to search
| This Lua module is used on many 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 should only be used on articles that are near the post-expand include size limit, in order to prevent them from exceeding it. Unless there is a pressing technical need, use the appropriate CS1 and {{Citation}} templates. |
| This module depends on the following other modules: |
| {{Cite arXiv}} | arXiv preprints |
|---|---|
| {{Cite AV media}} | A/V media |
| {{Cite AV media notes}} | A/V media liner notes |
| {{Cite bioRxiv}} | bioRxiv preprints |
| {{Cite book}} | books and book chapters |
| {{Cite CiteSeerX}} | CiteSeerX papers |
| {{Cite conference}} | conference papers |
| {{Cite document}} | short, standalone offline documents |
| {{Cite encyclopedia}} | edited collections |
| {{Cite episode}} | podcast, radio or television episodes |
| {{Cite interview}} | interviews |
| {{Cite journal}} | academic journals |
| {{Cite magazine}} | magazines and other periodicals |
| {{Cite mailing list}} | public email lists |
| {{Cite map}} | maps |
| {{Cite medRxiv}} | medRxiv preprints |
| {{Cite news}} | journalism pieces |
| {{Cite newsgroup}} | online newsgroups |
| {{Cite podcast}} | podcasts |
| {{Cite press release}} | press releases |
| {{Cite report}} | reports |
| {{Cite serial}} | A/V serials |
| {{Cite sign}} | signs or plaques |
| {{Cite speech}} | recorded/transcribed speeches |
| {{Cite SSRN}} | SSRN papers |
| {{Cite tech report}} | technical reports |
| {{Cite thesis}} | scholarly theses |
| {{Cite web}} | online sources not covered above |
| See also | Specific-source templates Citation Style 1 wrapper templates |
Usage
This module may be used to replace any of the CS1/CS2 templates in articles that are nearing the post-expand include size limit. Such use should only be done to prevent an article from exceeding the limit. If necessary, this module may be used in templates that wrap a CS1/CS2 template.
Examples
This module requires no parameters, but does require the canonical name of a CS1 template, without the Cite prefix, a la Cite book → Book and Cite web → Web. To replace {{Citation}} templates, use Citation.
The structure for calls to this module is…
{{#invoke:Cite|<template name>|<CS1 parameters…>}}
…where:
#invoke:Cite– calls this module, Cite.|<template name>– is the canonical name of the template, without theCiteprefix; this is the#invoke:function call; it is case-insensitive.|<CS1 parameters…>– are all of the parameters required by {{Cite <template name>}}
To go from {{Cite book}}:
{{Cite book|last=Green|first=E.B.|year=1915|title=Title|publisher=PseudoRandom}}- Green, E.B. (1915). Title. PseudoRandom.
…use wiki markup that follows this rubric:
{{#invoke:Cite|book|last=Green|first=E.B.|year=1915|title=Title|publisher=PseudoRandom}}- Green, E.B. (1915). Title. PseudoRandom.
require("strict")
local cfg = mw.loadData("Module:Cite/config")
--[[--------------------------< S U B S T I T U T E >---------------------------
Substitutes $1, $2, etc. in <message> with data from <data_t>. Returns plain
text substituted string when <data_t> is not nil, else returns <message>.
]]
local function substitute(message, data_t)
return data_t and mw.message.newRawMessage(message, data_t):plain() or message
end
--[[---------------------< M A K E _ E R R O R _ M S G >------------------------
Assembles an error message from module name, message text, help link, and
error category.
]]
local function make_error_msg(frame, msg)
-- Get the module name for prefix and help-link label.
local module_name = frame:getTitle()
-- Used for categorization.
local namespace = mw.title.getCurrentTitle().namespace
local category_link = (0 == namespace) and substitute(
"[[Category:$1]]", {cfg.settings_t.err_category}
) or ""
return substitute(
'<span style="color: #d33;">Error: {{[[$1|#invoke:$2]]}}: ' ..
'$3 ([[:$4|$5]])</span>$6',
{
module_name, -- Module name with namespace.
module_name:gsub("Module:", ""), -- Module name without namespace.
msg, -- Error message.
cfg.settings_t.help_text_link, -- Help wikilink to text at help page.
cfg.settings_t.help, -- Help wikilink display text.
category_link -- Link to error category (for main namespace errors only).
}
)
end
--[[-------------------------------< C I T E >----------------------------------
Function to call Module:Citation/CS1/sandbox with appropriate parameters. For
use when an article exceeds the post-expand include size limit.
{{#invoke:Cite|book|title=Title}}
]]
local function cite(frame, template)
local args_t = require("Module:Arguments").getArgs(frame, {frameOnly = true})
template = template:lower() -- Lowercase for table indexes.
if not cfg.known_templates_t[template] then -- Do we recognize this template?
return make_error_msg(frame, substitute(
cfg.settings_t.unknown_name, {template}
)) -- Nope, abandon with error message.
end
local config_t = {
-- Set CitationClass value.
["CitationClass"] = cfg.citation_classes_t[template] or template
}
-- Go render the citation.
return require("Module:Citation/CS1")._citation(nil, args_t, config_t)
end
--[[----------------------------< E X P O R T S >-----------------------------]]
return setmetatable(
{},
{
-- This anonymous function called as function(TABLE, KEY) returns an empty
-- TABLE whose metatable has __index set so for any given KEY it returns:
__index = function(_, template)
return function(frame)
return cite(frame, template)
end -- Which then returns a function that calls cite() with the KEY name.
end
}
)