Title: Module:Footnotes - freem
URL Source: https://freemwiki.com/wiki/Module:Footnotes/
Markdown Content:
[Jump to content](https://freemwiki.com/wiki/Module:Footnotes/#bodyContent)
- [x] Main menu
Main menu
move to sidebar hide
Navigation
* [Main page](https://freemwiki.com/wiki/Main_Page "Visit the main page [alt-shift-z]")
* [Recent changes](https://freemwiki.com/wiki/Special:RecentChanges "A list of recent changes in the wiki [alt-shift-r]")
* [Random page](https://freemwiki.com/wiki/Special:Random "Load a random page [alt-shift-x]")
* [Help about MediaWiki](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents)
Legal
* [Terms](https://freemwiki.com/wiki/Terms_of_Service)
* [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy)
* [About](https://freemwiki.com/wiki/About)
* [Contact](https://freemwiki.com/wiki/Contact)
[**freem**](https://freemwiki.com/wiki/Main_Page)
[Search](https://freemwiki.com/wiki/Special:Search "Search freem [alt-shift-f]")
Search
- [x] Appearance
* [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3AFootnotes "You are encouraged to create an account and log in; however, it is not mandatory")
* [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AFootnotes "You are encouraged to log in; however, it is not mandatory [alt-shift-o]")
- [x] Personal tools
* [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3AFootnotes "You are encouraged to create an account and log in; however, it is not mandatory")
* [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3AFootnotes "You are encouraged to log in; however, it is not mandatory [alt-shift-o]")
Pages for logged out editors [learn more](https://freemwiki.com/wiki/Help:Introduction)
* [Contributions](https://freemwiki.com/wiki/Special:MyContributions "A list of edits made from this IP address [alt-shift-y]")
* [Talk](https://freemwiki.com/wiki/Special:MyTalk "Discussion about edits from this IP address [alt-shift-n]")
# Module:Footnotes
- [x] Add languages
* [Module](https://freemwiki.com/wiki/Module:Footnotes "View the module page [alt-shift-c]")
* [Discussion](https://freemwiki.com/index.php?title=Module_talk:Footnotes&action=edit&redlink=1 "Discussion about the content page (page does not exist) [alt-shift-t]")
- [x] English
* [Read](https://freemwiki.com/wiki/Module:Footnotes)
* [Edit source](https://freemwiki.com/index.php?title=Module:Footnotes&action=edit "Edit the source code of this page [alt-shift-e]")
* [View history](https://freemwiki.com/index.php?title=Module:Footnotes&action=history "Past revisions of this page [alt-shift-h]")
- [x] Tools
Tools
move to sidebar hide
Actions
* [Read](https://freemwiki.com/wiki/Module:Footnotes)
* [Edit source](https://freemwiki.com/index.php?title=Module:Footnotes&action=edit "Edit the source code of this page [alt-shift-e]")
* [View history](https://freemwiki.com/index.php?title=Module:Footnotes&action=history)
General
* [What links here](https://freemwiki.com/wiki/Special:WhatLinksHere/Module:Footnotes "A list of all wiki pages that link here [alt-shift-j]")
* [Related changes](https://freemwiki.com/wiki/Special:RecentChangesLinked/Module:Footnotes "Recent changes in pages linked from this page [alt-shift-k]")
* [Special pages](https://freemwiki.com/wiki/Special:SpecialPages "A list of all special pages [alt-shift-q]")
* [Printable version](javascript:print(); "Printable version of this page [alt-shift-p]")
* [Permanent link](https://freemwiki.com/index.php?title=Module:Footnotes&oldid=580068 "Permanent link to this revision of this page")
* [Page information](https://freemwiki.com/index.php?title=Module:Footnotes&action=info "More information about this page")
Appearance
move to sidebar hide
From freem
(Redirected from [Module:Footnotes/](https://freemwiki.com/index.php?title=Module:Footnotes/&redirect=no "Module:Footnotes/"))
_Documentation for this module may be created at [Module:Footnotes/doc](https://freemwiki.com/index.php?title=Module:Footnotes/doc&action=edit&redlink=1 "Module:Footnotes/doc (page does not exist)")_
[](https://freemwiki.com/wiki/Module:Footnotes/#L-1)require('strict');[](https://freemwiki.com/wiki/Module:Footnotes/#L-2)local getArgs = require (['Module:Arguments'](https://freemwiki.com/wiki/Module:Arguments)).getArgs;[](https://freemwiki.com/wiki/Module:Footnotes/#L-3)[](https://freemwiki.com/wiki/Module:Footnotes/#L-4)[](https://freemwiki.com/wiki/Module:Footnotes/#L-5)--[[--------------------------< A R G S _ D E F A U L T >------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-6)[](https://freemwiki.com/wiki/Module:Footnotes/#L-7)a table to specify initial values.[](https://freemwiki.com/wiki/Module:Footnotes/#L-8)[](https://freemwiki.com/wiki/Module:Footnotes/#L-9)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-10)[](https://freemwiki.com/wiki/Module:Footnotes/#L-11)local args_default = {[](https://freemwiki.com/wiki/Module:Footnotes/#L-12) group = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-13)bracket_left = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-14)bracket_right = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-15)bracket_year_left = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-16)bracket_year_right = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-17)postscript = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-18)page = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-19)pages = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-20)location = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-21)page_sep = ", p. ",[](https://freemwiki.com/wiki/Module:Footnotes/#L-22)pages_sep = ", pp. ",[](https://freemwiki.com/wiki/Module:Footnotes/#L-23)ref = '',[](https://freemwiki.com/wiki/Module:Footnotes/#L-24)template = 'harv',-- if template name not provided in {{#invoke:}} use this[](https://freemwiki.com/wiki/Module:Footnotes/#L-25)};[](https://freemwiki.com/wiki/Module:Footnotes/#L-26)[](https://freemwiki.com/wiki/Module:Footnotes/#L-27)[](https://freemwiki.com/wiki/Module:Footnotes/#L-28)--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-29)[](https://freemwiki.com/wiki/Module:Footnotes/#L-30)look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list[](https://freemwiki.com/wiki/Module:Footnotes/#L-31)[](https://freemwiki.com/wiki/Module:Footnotes/#L-32)the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside[](https://freemwiki.com/wiki/Module:Footnotes/#L-33)a template that wraps another template; 'multiple targets' error may not be suppressed[](https://freemwiki.com/wiki/Module:Footnotes/#L-34)[](https://freemwiki.com/wiki/Module:Footnotes/#L-35)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-36)[](https://freemwiki.com/wiki/Module:Footnotes/#L-37)local function target_check (anchor_id, args)[](https://freemwiki.com/wiki/Module:Footnotes/#L-38)local namespace = mw.title.getCurrentTitle().namespace;[](https://freemwiki.com/wiki/Module:Footnotes/#L-39)local anchor_id_list_module = mw.loadData (['Module:Footnotes/anchor_id_list'](https://freemwiki.com/wiki/Module:Footnotes/anchor_id_list));[](https://freemwiki.com/wiki/Module:Footnotes/#L-40)local anchor_id_list = anchor_id_list_module.anchor_id_list;[](https://freemwiki.com/wiki/Module:Footnotes/#L-41)local article_whitelist = anchor_id_list_module.article_whitelist;[](https://freemwiki.com/wiki/Module:Footnotes/#L-42)local template_list = anchor_id_list_module.template_list;[](https://freemwiki.com/wiki/Module:Footnotes/#L-43) local citeref_patterns = anchor_id_list_module.citeref_patterns[](https://freemwiki.com/wiki/Module:Footnotes/#L-44)[](https://freemwiki.com/wiki/Module:Footnotes/#L-45)local whitelist_module = mw.loadData (['Module:Footnotes/whitelist'](https://freemwiki.com/wiki/Module:Footnotes/whitelist));[](https://freemwiki.com/wiki/Module:Footnotes/#L-46)local whitelist = whitelist_module.whitelist;[](https://freemwiki.com/wiki/Module:Footnotes/#L-47)[](https://freemwiki.com/wiki/Module:Footnotes/#L-48)local tally = anchor_id_list[anchor_id];-- nil when anchor_id not in list; else a tally[](https://freemwiki.com/wiki/Module:Footnotes/#L-49)local msg;[](https://freemwiki.com/wiki/Module:Footnotes/#L-50)local category;[](https://freemwiki.com/wiki/Module:Footnotes/#L-51)[](https://freemwiki.com/wiki/Module:Footnotes/#L-52)if not tally then[](https://freemwiki.com/wiki/Module:Footnotes/#L-53)if args.ignore then[](https://freemwiki.com/wiki/Module:Footnotes/#L-54)return '';-- if ignore is true then no message, no category[](https://freemwiki.com/wiki/Module:Footnotes/#L-55)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-56)[](https://freemwiki.com/wiki/Module:Footnotes/#L-57)if article_whitelist and article_whitelist[anchor_id] then-- if an article-local whitelist and anchor ID is in it[](https://freemwiki.com/wiki/Module:Footnotes/#L-58)return '';-- done[](https://freemwiki.com/wiki/Module:Footnotes/#L-59)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-60)[](https://freemwiki.com/wiki/Module:Footnotes/#L-61)local wl_anchor_id = anchor_id;-- copy to be modified to index into the whitelist[](https://freemwiki.com/wiki/Module:Footnotes/#L-62)[](https://freemwiki.com/wiki/Module:Footnotes/#L-63)if args.year then-- for anchor IDs created by this template (not in |ref=) that have a date[](https://freemwiki.com/wiki/Module:Footnotes/#L-64)if args.year:match ('%d%l$') or-- use the date value to determine if we should remove the disambiguator[](https://freemwiki.com/wiki/Module:Footnotes/#L-65)args.year:match ('n%.d%.%l$') or[](https://freemwiki.com/wiki/Module:Footnotes/#L-66)args.year:match ('nd%l$') then[](https://freemwiki.com/wiki/Module:Footnotes/#L-67)wl_anchor_id = wl_anchor_id:gsub ('%l$', '');-- remove the disambiguator[](https://freemwiki.com/wiki/Module:Footnotes/#L-68)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-69)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-70)[](https://freemwiki.com/wiki/Module:Footnotes/#L-71)local t_tbl = whitelist[wl_anchor_id];-- get list of templates associated with this anchor ID[](https://freemwiki.com/wiki/Module:Footnotes/#L-72)[](https://freemwiki.com/wiki/Module:Footnotes/#L-73)if t_tbl then-- when anchor ID not whitelisted t_tbl is nil[](https://freemwiki.com/wiki/Module:Footnotes/#L-74)for _, t in ipairs (t_tbl) do-- spin through the list of templates associated with this anchor ID[](https://freemwiki.com/wiki/Module:Footnotes/#L-75)if template_list[t] then-- if associated template is found in the list of templates in the article[](https://freemwiki.com/wiki/Module:Footnotes/#L-76)return '';-- anchor ID is whitlisted and article has matching template so no error[](https://freemwiki.com/wiki/Module:Footnotes/#L-77)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-78)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-79)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-80)[](https://freemwiki.com/wiki/Module:Footnotes/#L-81) for _, pattern in ipairs(citeref_patterns) do -- load patterns for wrapper templates on this page[](https://freemwiki.com/wiki/Module:Footnotes/#L-82) if anchor_id:match(pattern) then -- spin through the special patterns and try to match[](https://freemwiki.com/wiki/Module:Footnotes/#L-83) return ''[](https://freemwiki.com/wiki/Module:Footnotes/#L-84) end[](https://freemwiki.com/wiki/Module:Footnotes/#L-85) end[](https://freemwiki.com/wiki/Module:Footnotes/#L-86) [](https://freemwiki.com/wiki/Module:Footnotes/#L-87)[](https://freemwiki.com/wiki/Module:Footnotes/#L-88)msg = 'no target: ' .. anchor_id;-- anchor_id not found[](https://freemwiki.com/wiki/Module:Footnotes/#L-89)mw.log(msg)[](https://freemwiki.com/wiki/Module:Footnotes/#L-90) if namespace == 10 and not args.show then -- do not generate error message in template namespace[](https://freemwiki.com/wiki/Module:Footnotes/#L-91) return ''[](https://freemwiki.com/wiki/Module:Footnotes/#L-92) end[](https://freemwiki.com/wiki/Module:Footnotes/#L-93)category = '[[Category:Harv and Sfn no-target errors]]';[](https://freemwiki.com/wiki/Module:Footnotes/#L-94)[](https://freemwiki.com/wiki/Module:Footnotes/#L-95)elseif 1 < tally then[](https://freemwiki.com/wiki/Module:Footnotes/#L-96)msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id;-- more than one anchor_id in this article[](https://freemwiki.com/wiki/Module:Footnotes/#L-97)mw.log(msg)[](https://freemwiki.com/wiki/Module:Footnotes/#L-98) if namespace == 10 and not args.show then -- do not generate error message in template namespace[](https://freemwiki.com/wiki/Module:Footnotes/#L-99) return ''[](https://freemwiki.com/wiki/Module:Footnotes/#L-100) end[](https://freemwiki.com/wiki/Module:Footnotes/#L-101)category = 0 == namespace and '[[Category:Harv and Sfn multiple-target errors]]' or '';-- only categorize in article space[](https://freemwiki.com/wiki/Module:Footnotes/#L-102)return ' ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])' .. category;[](https://freemwiki.com/wiki/Module:Footnotes/#L-103)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-104)[](https://freemwiki.com/wiki/Module:Footnotes/#L-105)-- category = 0 == namespace and '[[[Category:Harv and Sfn template errors]]](https://freemwiki.com/wiki/Category:Harv_and_Sfn_template_errors "Category:Harv and Sfn template errors")' or ''; -- only categorize in article space[](https://freemwiki.com/wiki/Module:Footnotes/#L-106)category = 0 == namespace and category or '';-- only categorize in article space[](https://freemwiki.com/wiki/Module:Footnotes/#L-107)[](https://freemwiki.com/wiki/Module:Footnotes/#L-108)-- display based on args.show (no display by default)[](https://freemwiki.com/wiki/Module:Footnotes/#L-109) local display = args.show and 'inline' or 'none'[](https://freemwiki.com/wiki/Module:Footnotes/#L-110) return msg and ' ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])' .. category or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-111)[](https://freemwiki.com/wiki/Module:Footnotes/#L-112)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-113)[](https://freemwiki.com/wiki/Module:Footnotes/#L-114)[](https://freemwiki.com/wiki/Module:Footnotes/#L-115)--[[--------------------------< I S _ Y E A R >----------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-116)[](https://freemwiki.com/wiki/Module:Footnotes/#L-117)evaluates param to see if it is one of these forms with or without lowercase letter disambiguator:[](https://freemwiki.com/wiki/Module:Footnotes/#L-118) YYYY[](https://freemwiki.com/wiki/Module:Footnotes/#L-119) n.d.[](https://freemwiki.com/wiki/Module:Footnotes/#L-120) nd [](https://freemwiki.com/wiki/Module:Footnotes/#L-121) c. YYYY[](https://freemwiki.com/wiki/Module:Footnotes/#L-122) YYYY–YYYY (separator is endash)[](https://freemwiki.com/wiki/Module:Footnotes/#L-123) YYYY–YY (separator is endash)[](https://freemwiki.com/wiki/Module:Footnotes/#L-124)[](https://freemwiki.com/wiki/Module:Footnotes/#L-125)return true when param has a recognized form; false else[](https://freemwiki.com/wiki/Module:Footnotes/#L-126)[](https://freemwiki.com/wiki/Module:Footnotes/#L-127)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-128)[](https://freemwiki.com/wiki/Module:Footnotes/#L-129)local patterns_date= {[](https://freemwiki.com/wiki/Module:Footnotes/#L-130)'^%d%d%d%d?%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-131)'^n%.d%.%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-132)'^nd%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-133)'^c%. %d%d%d%d?%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-134)'^%d%d%d%d–%d%d%d%d%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-135)'^%d%d%d%d–%d%d%l?$',[](https://freemwiki.com/wiki/Module:Footnotes/#L-136)}[](https://freemwiki.com/wiki/Module:Footnotes/#L-137)[](https://freemwiki.com/wiki/Module:Footnotes/#L-138)local function is_year (param, args)[](https://freemwiki.com/wiki/Module:Footnotes/#L-139)args.year = '';-- used for harv error; [](https://freemwiki.com/wiki/Module:Footnotes/#L-140)[](https://freemwiki.com/wiki/Module:Footnotes/#L-141)for _, pattern in ipairs (patterns_date) do[](https://freemwiki.com/wiki/Module:Footnotes/#L-142)if mw.ustring.match (param, pattern) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-143)args.year = param;-- used for harv error; [](https://freemwiki.com/wiki/Module:Footnotes/#L-144)return true;[](https://freemwiki.com/wiki/Module:Footnotes/#L-145)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-146)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-147)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-148)[](https://freemwiki.com/wiki/Module:Footnotes/#L-149)[](https://freemwiki.com/wiki/Module:Footnotes/#L-150)--[[--------------------------< C O R E >----------------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-151)[](https://freemwiki.com/wiki/Module:Footnotes/#L-152)returns an anchor link (CITEREF) formed from one to four author names, year, and insource location (|p=, |pp=, loc=)[](https://freemwiki.com/wiki/Module:Footnotes/#L-153)[](https://freemwiki.com/wiki/Module:Footnotes/#L-154)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-155)[](https://freemwiki.com/wiki/Module:Footnotes/#L-156)local function core( args )[](https://freemwiki.com/wiki/Module:Footnotes/#L-157)local result;[](https://freemwiki.com/wiki/Module:Footnotes/#L-158)local err_msg = ''[](https://freemwiki.com/wiki/Module:Footnotes/#L-159)[](https://freemwiki.com/wiki/Module:Footnotes/#L-160)if args.P5 ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-161)if is_year (args.P5, args) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-162)result = table.concat ({args.P1, ' et al. ', args.bracket_year_left, args.P5, args.bracket_year_right});[](https://freemwiki.com/wiki/Module:Footnotes/#L-163)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-164)args.P5 = '';-- when P5 not a year don't include in anchor[](https://freemwiki.com/wiki/Module:Footnotes/#L-165)result = table.concat ({args.P1, ' et al.'});-- and don't render it[](https://freemwiki.com/wiki/Module:Footnotes/#L-166)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-167)[](https://freemwiki.com/wiki/Module:Footnotes/#L-168)elseif args.P4 ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-169)if is_year (args.P4, args) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-170)result = table.concat ({args.P1, ', ', args.P2, ' & ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right});-- three names and a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-171)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-172)result = table.concat ({args.P1, ' et al.'});-- four names[](https://freemwiki.com/wiki/Module:Footnotes/#L-173)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-174)[](https://freemwiki.com/wiki/Module:Footnotes/#L-175)elseif args.P3 ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-176)if is_year (args.P3, args) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-177)result = table.concat ({args.P1, ' & ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right});-- two names and a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-178)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-179)result = table.concat ({args.P1, ', ', args.P2, ' ', ' & ', args.P3});-- three names[](https://freemwiki.com/wiki/Module:Footnotes/#L-180)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-181)[](https://freemwiki.com/wiki/Module:Footnotes/#L-182)elseif args.P2 ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-183)if is_year (args.P2, args) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-184)result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right});-- one name and year[](https://freemwiki.com/wiki/Module:Footnotes/#L-185)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-186)result = table.concat ({args.P1, ' & ', args.P2});-- two names[](https://freemwiki.com/wiki/Module:Footnotes/#L-187)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-188)[](https://freemwiki.com/wiki/Module:Footnotes/#L-189)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-190)result = args.P1;-- one name[](https://freemwiki.com/wiki/Module:Footnotes/#L-191)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-192)-- when author-date result ends with a dot (typically when the last positional parameter holds 'n.d.')[](https://freemwiki.com/wiki/Module:Footnotes/#L-193)-- and when no in-source location (no |p=, |pp=, or |loc=)[](https://freemwiki.com/wiki/Module:Footnotes/#L-194)-- and when the first or only character in args.postscript is a dot[](https://freemwiki.com/wiki/Module:Footnotes/#L-195)-- remove the author-date result trailing dot[](https://freemwiki.com/wiki/Module:Footnotes/#L-196)-- the author-date result trailing dot will be replaced later with the content of args.postscript (usually a dot)[](https://freemwiki.com/wiki/Module:Footnotes/#L-197)if ('.' == result:sub(-1)) and ('.' == args.postscript:sub(1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-198)result = result:gsub ('%.$', '');[](https://freemwiki.com/wiki/Module:Footnotes/#L-199)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-200)[](https://freemwiki.com/wiki/Module:Footnotes/#L-201)if args.ref ~= 'none' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-202)local anchor_id;[](https://freemwiki.com/wiki/Module:Footnotes/#L-203)if args.ref ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-204)anchor_id = mw.uri.anchorEncode (args.ref);[](https://freemwiki.com/wiki/Module:Footnotes/#L-205)err_msg = target_check (anchor_id, args);[](https://freemwiki.com/wiki/Module:Footnotes/#L-206)result = table.concat ({'[[#', anchor_id, '|', result, ']]'});[](https://freemwiki.com/wiki/Module:Footnotes/#L-207)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-208)anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5}));[](https://freemwiki.com/wiki/Module:Footnotes/#L-209)err_msg = target_check (anchor_id, args);[](https://freemwiki.com/wiki/Module:Footnotes/#L-210)result = table.concat ({'[[#', anchor_id, '|', result, ']]'});[](https://freemwiki.com/wiki/Module:Footnotes/#L-211)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-212)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-213)[](https://freemwiki.com/wiki/Module:Footnotes/#L-214)if args.page ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-215)result = table.concat ({result, args.page_sep, args.page});[](https://freemwiki.com/wiki/Module:Footnotes/#L-216)elseif args.pages ~= ''then[](https://freemwiki.com/wiki/Module:Footnotes/#L-217)result = table.concat ({result, args.pages_sep, args.pages});[](https://freemwiki.com/wiki/Module:Footnotes/#L-218)end [](https://freemwiki.com/wiki/Module:Footnotes/#L-219)[](https://freemwiki.com/wiki/Module:Footnotes/#L-220)if args.location ~= '' then[](https://freemwiki.com/wiki/Module:Footnotes/#L-221)result = table.concat ({result, ', ', args.location});[](https://freemwiki.com/wiki/Module:Footnotes/#L-222)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-223)[](https://freemwiki.com/wiki/Module:Footnotes/#L-224)result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' ');-- strip redundant spaces[](https://freemwiki.com/wiki/Module:Footnotes/#L-225)return result .. err_msg;[](https://freemwiki.com/wiki/Module:Footnotes/#L-226)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-227)[](https://freemwiki.com/wiki/Module:Footnotes/#L-228)[](https://freemwiki.com/wiki/Module:Footnotes/#L-229)--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-230)[](https://freemwiki.com/wiki/Module:Footnotes/#L-231)Converts a hyphen to a dash under certain conditions. The hyphen must separate[](https://freemwiki.com/wiki/Module:Footnotes/#L-232)like items; unlike items are returned unmodified. These forms are modified:[](https://freemwiki.com/wiki/Module:Footnotes/#L-233) letter - letter (A - B)[](https://freemwiki.com/wiki/Module:Footnotes/#L-234) digit - digit (4-5)[](https://freemwiki.com/wiki/Module:Footnotes/#L-235) digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)[](https://freemwiki.com/wiki/Module:Footnotes/#L-236) letterdigit - letterdigit (A1-A5) (an optional separator between letter and[](https://freemwiki.com/wiki/Module:Footnotes/#L-237) digit is supported – a.1-a.5 or a-1-a-5)[](https://freemwiki.com/wiki/Module:Footnotes/#L-238) digitletter - digitletter (5a - 5d) (an optional separator between letter and[](https://freemwiki.com/wiki/Module:Footnotes/#L-239) digit is supported – 5.a-5.d or 5-a-5-d)[](https://freemwiki.com/wiki/Module:Footnotes/#L-240)[](https://freemwiki.com/wiki/Module:Footnotes/#L-241)any other forms are returned unmodified.[](https://freemwiki.com/wiki/Module:Footnotes/#L-242)[](https://freemwiki.com/wiki/Module:Footnotes/#L-243)str may be a comma- or semicolon-separated list[](https://freemwiki.com/wiki/Module:Footnotes/#L-244)[](https://freemwiki.com/wiki/Module:Footnotes/#L-245)This code copied from Module:Citation/CS1. The only modification is to require Module:Citation/CS1/Utilities[](https://freemwiki.com/wiki/Module:Footnotes/#L-246)so that it has access to the functions is_set() and has_accept_as_written()[](https://freemwiki.com/wiki/Module:Footnotes/#L-247)[](https://freemwiki.com/wiki/Module:Footnotes/#L-248)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-249)[](https://freemwiki.com/wiki/Module:Footnotes/#L-250)local function hyphen_to_dash( str )[](https://freemwiki.com/wiki/Module:Footnotes/#L-251)local utilities = require (['Module:Citation/CS1/Utilities'](https://freemwiki.com/wiki/Module:Citation/CS1/Utilities));-- only modification so that this function has access to is_set() and has_accept_as_written()[](https://freemwiki.com/wiki/Module:Footnotes/#L-252)[](https://freemwiki.com/wiki/Module:Footnotes/#L-253)if not utilities.is_set (str) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-254)return str;[](https://freemwiki.com/wiki/Module:Footnotes/#L-255)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-256)[](https://freemwiki.com/wiki/Module:Footnotes/#L-257)local accept; -- Boolean[](https://freemwiki.com/wiki/Module:Footnotes/#L-258)[](https://freemwiki.com/wiki/Module:Footnotes/#L-259)str = str:gsub ('&[nm]dash;', {['–'] = '–', ['—'] = '—'});-- replace — and – entities with their characters; semicolon mucks up the text.split[](https://freemwiki.com/wiki/Module:Footnotes/#L-260)str = str:gsub ('-', '-'); -- replace HTML numeric entity with hyphen character[](https://freemwiki.com/wiki/Module:Footnotes/#L-261)[](https://freemwiki.com/wiki/Module:Footnotes/#L-262)str = str:gsub (' ', ' '); -- replace entity with generic keyboard space character[](https://freemwiki.com/wiki/Module:Footnotes/#L-263)[](https://freemwiki.com/wiki/Module:Footnotes/#L-264)local out = {};[](https://freemwiki.com/wiki/Module:Footnotes/#L-265)local list = mw.text.split (str, '%s*[,;]%s*');-- split str at comma or semicolon separators if there are any[](https://freemwiki.com/wiki/Module:Footnotes/#L-266)[](https://freemwiki.com/wiki/Module:Footnotes/#L-267)for _, item in ipairs (list) do-- for each item in the list[](https://freemwiki.com/wiki/Module:Footnotes/#L-268)item, accept = utilities.has_accept_as_written (item);-- remove accept-this-as-written markup when it wraps all of item[](https://freemwiki.com/wiki/Module:Footnotes/#L-269)if not accept and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then-- if a hyphenated range or has endash or emdash separators[](https://freemwiki.com/wiki/Module:Footnotes/#L-270)if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or-- letterdigit hyphen letterdigit (optional separator between letter and digit)[](https://freemwiki.com/wiki/Module:Footnotes/#L-271)item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or-- digitletter hyphen digitletter (optional separator between digit and letter)[](https://freemwiki.com/wiki/Module:Footnotes/#L-272)item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or-- digit separator digit hyphen digit separator digit[](https://freemwiki.com/wiki/Module:Footnotes/#L-273)item:match ('^%d+%s*%-%s*%d+$') or-- digit hyphen digit[](https://freemwiki.com/wiki/Module:Footnotes/#L-274)item:match ('^%a+%s*%-%s*%a+$') then-- letter hyphen letter[](https://freemwiki.com/wiki/Module:Footnotes/#L-275)item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2');-- replace hyphen, remove extraneous space characters[](https://freemwiki.com/wiki/Module:Footnotes/#L-276)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-277)item = mw.ustring.gsub (item, '%s*[–—]%s*', '–');-- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace[](https://freemwiki.com/wiki/Module:Footnotes/#L-278)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-279)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-280)table.insert (out, item);-- add the (possibly modified) item to the output table[](https://freemwiki.com/wiki/Module:Footnotes/#L-281)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-282)[](https://freemwiki.com/wiki/Module:Footnotes/#L-283)local temp_str = '';-- concatenate the output table into a comma separated string[](https://freemwiki.com/wiki/Module:Footnotes/#L-284)temp_str, accept = utilities.has_accept_as_written (table.concat (out, ', ')); -- remove accept-this-as-written markup when it wraps all of concatenated out[](https://freemwiki.com/wiki/Module:Footnotes/#L-285)if accept then[](https://freemwiki.com/wiki/Module:Footnotes/#L-286)temp_str = utilities.has_accept_as_written (str);-- when global markup removed, return original str; do it this way to suppress boolean second return value[](https://freemwiki.com/wiki/Module:Footnotes/#L-287)return temp_str;[](https://freemwiki.com/wiki/Module:Footnotes/#L-288)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-289)return temp_str;-- else, return assembled temp_str[](https://freemwiki.com/wiki/Module:Footnotes/#L-290)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-291)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-292)[](https://freemwiki.com/wiki/Module:Footnotes/#L-293)[](https://freemwiki.com/wiki/Module:Footnotes/#L-294)--[[--------------------------< A R G S _ F E T C H >---------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-295)[](https://freemwiki.com/wiki/Module:Footnotes/#L-296)Because all of the templates share a common set of parameters, a single common function to fetch those parameters[](https://freemwiki.com/wiki/Module:Footnotes/#L-297)from frame and parent frame.[](https://freemwiki.com/wiki/Module:Footnotes/#L-298)[](https://freemwiki.com/wiki/Module:Footnotes/#L-299)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-300)[](https://freemwiki.com/wiki/Module:Footnotes/#L-301)local function args_fetch (frame, ps)[](https://freemwiki.com/wiki/Module:Footnotes/#L-302)local args = args_default;-- create a copy of the default table[](https://freemwiki.com/wiki/Module:Footnotes/#L-303)local pframe = frame:getParent();-- point to the template's parameter table[](https://freemwiki.com/wiki/Module:Footnotes/#L-304)[](https://freemwiki.com/wiki/Module:Footnotes/#L-305)for k, v in pairs (frame.args) do-- override defaults with values provided in the #invoke: if any[](https://freemwiki.com/wiki/Module:Footnotes/#L-306)args[k] = v; [](https://freemwiki.com/wiki/Module:Footnotes/#L-307)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-308)[](https://freemwiki.com/wiki/Module:Footnotes/#L-309)args.postscript = pframe.args.postscript or pframe.args.ps or ps;[](https://freemwiki.com/wiki/Module:Footnotes/#L-310)if 'none' == args.postscript then[](https://freemwiki.com/wiki/Module:Footnotes/#L-311)args.postscript = '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-312)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-313)args.group = pframe.args.group or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-314)args.page = pframe.args.p or pframe.args.page or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-315)args.pages = pframe.args.pp or pframe.args.pages or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-316)args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-317)args.location = pframe.args.at or pframe.args.loc or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-318)args.ref = pframe.args.ref or pframe.args.Ref or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-319)args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']);[](https://freemwiki.com/wiki/Module:Footnotes/#L-320)[](https://freemwiki.com/wiki/Module:Footnotes/#L-321)for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- loop through the five positional parameters and trim if set else empty string[](https://freemwiki.com/wiki/Module:Footnotes/#L-322)args[v] = (pframe.args[i] and mw.text.trim (pframe.args[i])) or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-323)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-324)[](https://freemwiki.com/wiki/Module:Footnotes/#L-325)if args.P5 and not is_year (args.P5, args) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-326)local i = 6;-- initialize the indexer to the sixth positional parameter[](https://freemwiki.com/wiki/Module:Footnotes/#L-327)while pframe.args[i] do-- in case there are too many authors loop through the authors looking for a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-328)local v = mw.text.trim (pframe.args[i]);-- trim[](https://freemwiki.com/wiki/Module:Footnotes/#L-329)if is_year (v, args) then-- if a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-330)args.P5 = v;-- overwrite whatever was in args.P5 with year[](https://freemwiki.com/wiki/Module:Footnotes/#L-331)break;-- and abandon the search[](https://freemwiki.com/wiki/Module:Footnotes/#L-332)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-333)i = i + 1;-- bump the indexer[](https://freemwiki.com/wiki/Module:Footnotes/#L-334)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-335)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-336)return args;[](https://freemwiki.com/wiki/Module:Footnotes/#L-337)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-338)[](https://freemwiki.com/wiki/Module:Footnotes/#L-339)[](https://freemwiki.com/wiki/Module:Footnotes/#L-340)--[[--------------------------< H A R V A R D _ C I T A T I O N >----------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-341)[](https://freemwiki.com/wiki/Module:Footnotes/#L-342)common entry point for:[](https://freemwiki.com/wiki/Module:Footnotes/#L-343) {{[harvard citation](https://freemwiki.com/wiki/Template:Harvard_citation "Template:Harvard citation")}} aka {{[harv](https://freemwiki.com/wiki/Template:Harv "Template:Harv")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-344) {{[Harvard citation no brackets](https://freemwiki.com/wiki/Template:Harvard_citation_no_brackets "Template:Harvard citation no brackets")}} aka {{[harvnb](https://freemwiki.com/wiki/Template:Harvnb "Template:Harvnb")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-345) {{[harvcol](https://freemwiki.com/wiki/Template:Harvcol "Template:Harvcol")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-346) {{[harvcolnb](https://freemwiki.com/wiki/Template:Harvcolnb "Template:Harvcolnb")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-347) {{[harvcoltxt](https://freemwiki.com/wiki/Template:Harvcoltxt "Template:Harvcoltxt")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-348) {{[Harvard citation text](https://freemwiki.com/wiki/Template:Harvard_citation_text "Template:Harvard citation text")}} aka {{[harvtxt](https://freemwiki.com/wiki/Template:Harvtxt "Template:Harvtxt")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-349) {{[Harvp](https://freemwiki.com/wiki/Template:Harvp "Template:Harvp")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-350)[](https://freemwiki.com/wiki/Module:Footnotes/#L-351)Distinguishing features (brackets and page separators) are specified in this module's {{#invoke}} in the respective templates.[](https://freemwiki.com/wiki/Module:Footnotes/#L-352)[](https://freemwiki.com/wiki/Module:Footnotes/#L-353)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-354)[](https://freemwiki.com/wiki/Module:Footnotes/#L-355)local function harvard_citation (frame)[](https://freemwiki.com/wiki/Module:Footnotes/#L-356)local args = args_fetch (frame, '');-- get the template and invoke parameters; default postscript is empty string[](https://freemwiki.com/wiki/Module:Footnotes/#L-357)[](https://freemwiki.com/wiki/Module:Footnotes/#L-358)return core (args);[](https://freemwiki.com/wiki/Module:Footnotes/#L-359)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-360)[](https://freemwiki.com/wiki/Module:Footnotes/#L-361)[](https://freemwiki.com/wiki/Module:Footnotes/#L-362)--[[--------------------------< S T R I P _ U R L >------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-363)[](https://freemwiki.com/wiki/Module:Footnotes/#L-364)used by sfn() and sfnm(). This function fixes an issue with reference tooltip gadget where the tooltip is not displayed[](https://freemwiki.com/wiki/Module:Footnotes/#L-365)when an insource locator (|p=, |pp=, |loc=) has an external wikilink that contains a # character[](https://freemwiki.com/wiki/Module:Footnotes/#L-366)[](https://freemwiki.com/wiki/Module:Footnotes/#L-367)strip uri-reserved characters from urls in |p=, |pp-, and |loc= parameters The researved characters are:[](https://freemwiki.com/wiki/Module:Footnotes/#L-368) !#$&'()*+,/:;=?@[][](https://freemwiki.com/wiki/Module:Footnotes/#L-369)[](https://freemwiki.com/wiki/Module:Footnotes/#L-370)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-371)[](https://freemwiki.com/wiki/Module:Footnotes/#L-372)local function strip_url (pages)[](https://freemwiki.com/wiki/Module:Footnotes/#L-373)local escaped_uri;[](https://freemwiki.com/wiki/Module:Footnotes/#L-374)if not pages or ('' == pages) then[](https://freemwiki.com/wiki/Module:Footnotes/#L-375)return pages;[](https://freemwiki.com/wiki/Module:Footnotes/#L-376)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-377)[](https://freemwiki.com/wiki/Module:Footnotes/#L-378)for uri in pages:gmatch ('%[(%a[%w%+%.%-]*://%S+)') do-- for each external link get the uri[](https://freemwiki.com/wiki/Module:Footnotes/#L-379)escaped_uri = uri:gsub ("([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );-- save a copy with lua pattern characters escaped[](https://freemwiki.com/wiki/Module:Footnotes/#L-380)uri = uri:gsub ("[!#%$&'%(%)%*%+,/:;=%?@%[%]%.%%]", '');-- remove reserved characters and '%' because '%20' (space character) is a lua 'invalid capture index'[](https://freemwiki.com/wiki/Module:Footnotes/#L-381)pages = pages:gsub (escaped_uri, uri, 1);-- replace original uri with the stripped version[](https://freemwiki.com/wiki/Module:Footnotes/#L-382)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-383)[](https://freemwiki.com/wiki/Module:Footnotes/#L-384)return pages;[](https://freemwiki.com/wiki/Module:Footnotes/#L-385)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-386)[](https://freemwiki.com/wiki/Module:Footnotes/#L-387)[](https://freemwiki.com/wiki/Module:Footnotes/#L-388)--[[--------------------------< S F N >------------------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-389)[](https://freemwiki.com/wiki/Module:Footnotes/#L-390)entry point for {{[sfn](https://freemwiki.com/wiki/Template:Sfn "Template:Sfn")}} and {{[sfnp](https://freemwiki.com/wiki/Template:Sfnp "Template:Sfnp")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-391)[](https://freemwiki.com/wiki/Module:Footnotes/#L-392)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-393)[](https://freemwiki.com/wiki/Module:Footnotes/#L-394)local function sfn (frame)[](https://freemwiki.com/wiki/Module:Footnotes/#L-395)local args = args_fetch (frame, '.');-- get the template and invoke parameters; default postscript is a dot[](https://freemwiki.com/wiki/Module:Footnotes/#L-396)[](https://freemwiki.com/wiki/Module:Footnotes/#L-397)local result = core (args);-- go make a CITEREF anchor[](https://freemwiki.com/wiki/Module:Footnotes/#L-398)-- put it all together and then strip redundant spaces[](https://freemwiki.com/wiki/Module:Footnotes/#L-399)local name = table.concat ({'FOOTNOTE', args.P1, args.P2, args.P3, args.P4, args.P5, strip_url (args.page), strip_url (args.pages), strip_url (args.location)}):gsub ('%s+', ' ');[](https://freemwiki.com/wiki/Module:Footnotes/#L-400)[](https://freemwiki.com/wiki/Module:Footnotes/#L-401)return frame:extensionTag ({name='ref', args={group=args.group, name=name}, content=result});[](https://freemwiki.com/wiki/Module:Footnotes/#L-402)[](https://freemwiki.com/wiki/Module:Footnotes/#L-403)[](https://freemwiki.com/wiki/Module:Footnotes/#L-404)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-405)[](https://freemwiki.com/wiki/Module:Footnotes/#L-406)[](https://freemwiki.com/wiki/Module:Footnotes/#L-407)--[[--------------------------< S F N M >----------------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-408)[](https://freemwiki.com/wiki/Module:Footnotes/#L-409)common entry point for {{[sfnm](https://freemwiki.com/wiki/Template:Sfnm "Template:Sfnm")}} and {{[sfnmp](https://freemwiki.com/wiki/Template:Sfnmp "Template:Sfnmp")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-410)[](https://freemwiki.com/wiki/Module:Footnotes/#L-411)Distinguishing features (brackets) are specified in this module's {{#invoke}} in the respective templates.[](https://freemwiki.com/wiki/Module:Footnotes/#L-412)[](https://freemwiki.com/wiki/Module:Footnotes/#L-413)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-414)[](https://freemwiki.com/wiki/Module:Footnotes/#L-415)local function sfnm (frame)[](https://freemwiki.com/wiki/Module:Footnotes/#L-416)local args = args_default;-- create a copy of the default table[](https://freemwiki.com/wiki/Module:Footnotes/#L-417)local pframe = frame:getParent();-- point to the template's parameter table[](https://freemwiki.com/wiki/Module:Footnotes/#L-418)[](https://freemwiki.com/wiki/Module:Footnotes/#L-419)local n = 1;-- index of source; this is the 'n' in na1, ny, etc[](https://freemwiki.com/wiki/Module:Footnotes/#L-420)local first_pnum = 1;-- first of a pair of positional parameters[](https://freemwiki.com/wiki/Module:Footnotes/#L-421)local second_pnum = 2;-- second of a pair of positional parameters[](https://freemwiki.com/wiki/Module:Footnotes/#L-422)[](https://freemwiki.com/wiki/Module:Footnotes/#L-423)local last_ps = 0;-- index of the last source with |nps= set[](https://freemwiki.com/wiki/Module:Footnotes/#L-424)local last_index = 0;-- index of the last source; these used to determine which of |ps= or |nps= will terminate the whole rendering[](https://freemwiki.com/wiki/Module:Footnotes/#L-425)[](https://freemwiki.com/wiki/Module:Footnotes/#L-426)local out = {};-- table to hold rendered sources[](https://freemwiki.com/wiki/Module:Footnotes/#L-427)local footnote = {'FOOTNOTE'};-- all author, date, insource location stuff becomes part of the reference's footnote id; added as we go[](https://freemwiki.com/wiki/Module:Footnotes/#L-428)[](https://freemwiki.com/wiki/Module:Footnotes/#L-429)for k, v in pairs (frame.args) do-- override defaults with values provided in the #invoke: if any[](https://freemwiki.com/wiki/Module:Footnotes/#L-430)args[k] = v; [](https://freemwiki.com/wiki/Module:Footnotes/#L-431)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-432)[](https://freemwiki.com/wiki/Module:Footnotes/#L-433)while true do[](https://freemwiki.com/wiki/Module:Footnotes/#L-434)if not pframe.args[table.concat ({n, 'a1'})] and not pframe.args[first_pnum] then[](https://freemwiki.com/wiki/Module:Footnotes/#L-435)break;-- no na1 or matching positional parameter so done[](https://freemwiki.com/wiki/Module:Footnotes/#L-436)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-437)[](https://freemwiki.com/wiki/Module:Footnotes/#L-438)if pframe.args[table.concat ({n, 'a1'})] then-- does this source use named parameters?[](https://freemwiki.com/wiki/Module:Footnotes/#L-439)for _, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- initialize for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-440)args[v] = '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-441)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-442)[](https://freemwiki.com/wiki/Module:Footnotes/#L-443)for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- extract author and year parameters for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-444)args[v] = pframe.args[table.concat ({n, 'a', i})] or '';-- attempt to assign author name[](https://freemwiki.com/wiki/Module:Footnotes/#L-445)if '' == args[v] then-- when there wasn't an author name[](https://freemwiki.com/wiki/Module:Footnotes/#L-446)args[v] = pframe.args[table.concat ({n, 'y'})] or '';-- attempt to assign year[](https://freemwiki.com/wiki/Module:Footnotes/#L-447)break;-- done with author/date for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-448)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-449)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-450)[](https://freemwiki.com/wiki/Module:Footnotes/#L-451)else-- this source uses positional parameters[](https://freemwiki.com/wiki/Module:Footnotes/#L-452)args.P1 = mw.text.trim (pframe.args[first_pnum]);-- yes, only one author supported[](https://freemwiki.com/wiki/Module:Footnotes/#L-453)args.P2 = (pframe.args[second_pnum] and mw.text.trim (pframe.args[second_pnum])) or '';-- when positional author, year must also be positional[](https://freemwiki.com/wiki/Module:Footnotes/#L-454)[](https://freemwiki.com/wiki/Module:Footnotes/#L-455)for _, v in ipairs ({'P3', 'P4', 'P5'}) do-- blank the rest of these for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-456)args[v] = '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-457)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-458)[](https://freemwiki.com/wiki/Module:Footnotes/#L-459)first_pnum = first_pnum + 2;-- source must use positional author and positional year[](https://freemwiki.com/wiki/Module:Footnotes/#L-460)second_pnum = first_pnum + 1;-- bump these for possible next positional source[](https://freemwiki.com/wiki/Module:Footnotes/#L-461)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-462)[](https://freemwiki.com/wiki/Module:Footnotes/#L-463)args.postscript = pframe.args[table.concat ({n, 'ps'})] or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-464)if 'none' == args.postscript then-- this for compatibility with other footnote templates; does nothing[](https://freemwiki.com/wiki/Module:Footnotes/#L-465)args.postscript = '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-466)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-467)args.group = pframe.args.group or '';-- reference group[](https://freemwiki.com/wiki/Module:Footnotes/#L-468)args.ref = pframe.args[table.concat ({n, 'ref'})] or '';-- alternate reference for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-469)[](https://freemwiki.com/wiki/Module:Footnotes/#L-470)args.page = pframe.args[table.concat ({n, 'p'})] or '';-- insource locations for this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-471)args.pages = pframe.args[table.concat ({n, 'pp'})] or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-472)args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-473)args.location = pframe.args[table.concat ({n, 'loc'})] or pframe.args[table.concat ({n, 'at'})] or '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-474)args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);[](https://freemwiki.com/wiki/Module:Footnotes/#L-475)[](https://freemwiki.com/wiki/Module:Footnotes/#L-476)table.insert (out, core (args));-- save the rendering of this source[](https://freemwiki.com/wiki/Module:Footnotes/#L-477)[](https://freemwiki.com/wiki/Module:Footnotes/#L-478)for k, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do-- create the FOOTNOTE id[](https://freemwiki.com/wiki/Module:Footnotes/#L-479)if '' ~= args[v] then[](https://freemwiki.com/wiki/Module:Footnotes/#L-480)table.insert (footnote, args[v]);[](https://freemwiki.com/wiki/Module:Footnotes/#L-481)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-482)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-483)for k, v in ipairs ({'page', 'pages', 'location'}) do-- these done separately so that we can strip uri-reserved characters from extlinked page numbers [](https://freemwiki.com/wiki/Module:Footnotes/#L-484)if '' ~= args[v] then[](https://freemwiki.com/wiki/Module:Footnotes/#L-485)table.insert (footnote, strip_url (args[v]))[](https://freemwiki.com/wiki/Module:Footnotes/#L-486)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-487)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-488)[](https://freemwiki.com/wiki/Module:Footnotes/#L-489)last_index = n;-- flags used to select terminal postscript from nps or from end_ps[](https://freemwiki.com/wiki/Module:Footnotes/#L-490)if '' ~= args.postscript then[](https://freemwiki.com/wiki/Module:Footnotes/#L-491)last_ps = n;[](https://freemwiki.com/wiki/Module:Footnotes/#L-492)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-493)[](https://freemwiki.com/wiki/Module:Footnotes/#L-494)n = n+1;-- bump for the next one[](https://freemwiki.com/wiki/Module:Footnotes/#L-495)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-496)[](https://freemwiki.com/wiki/Module:Footnotes/#L-497)local name = table.concat (footnote):gsub ('%s+', ' ');-- put the footnote together and strip redundant space[](https://freemwiki.com/wiki/Module:Footnotes/#L-498)[](https://freemwiki.com/wiki/Module:Footnotes/#L-499)args.end_ps = pframe.args.postscript or pframe.args.ps or '.';-- this is the postscript for the whole not for the individual sources[](https://freemwiki.com/wiki/Module:Footnotes/#L-500)if 'none' == args.end_ps then-- not an original sfnm parameter value; added for compatibility with other footnote templates[](https://freemwiki.com/wiki/Module:Footnotes/#L-501)args.end_ps = '';[](https://freemwiki.com/wiki/Module:Footnotes/#L-502)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-503)[](https://freemwiki.com/wiki/Module:Footnotes/#L-504)local result = table.concat ({table.concat (out, '; '), (last_index == last_ps) and '' or args.end_ps});[](https://freemwiki.com/wiki/Module:Footnotes/#L-505)return frame:extensionTag ({name='ref', args={group=args.group, name=name}, content=result});[](https://freemwiki.com/wiki/Module:Footnotes/#L-506)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-507)[](https://freemwiki.com/wiki/Module:Footnotes/#L-508)[](https://freemwiki.com/wiki/Module:Footnotes/#L-509)--[[--------------------------< S F N R E F >------------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-510)[](https://freemwiki.com/wiki/Module:Footnotes/#L-511)implements {{[sfnref](https://freemwiki.com/wiki/Template:Sfnref "Template:Sfnref")}}[](https://freemwiki.com/wiki/Module:Footnotes/#L-512)[](https://freemwiki.com/wiki/Module:Footnotes/#L-513)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-514)[](https://freemwiki.com/wiki/Module:Footnotes/#L-515)local function sfnref (frame)[](https://freemwiki.com/wiki/Module:Footnotes/#L-516)local args = getArgs (frame);[](https://freemwiki.com/wiki/Module:Footnotes/#L-517)local out = {};[](https://freemwiki.com/wiki/Module:Footnotes/#L-518)[](https://freemwiki.com/wiki/Module:Footnotes/#L-519)for i=1, 5 do-- get the first five args if there are five args[](https://freemwiki.com/wiki/Module:Footnotes/#L-520)if args[i] then[](https://freemwiki.com/wiki/Module:Footnotes/#L-521)out[i] = args[i];[](https://freemwiki.com/wiki/Module:Footnotes/#L-522)else[](https://freemwiki.com/wiki/Module:Footnotes/#L-523)break;-- less than 5 args break out[](https://freemwiki.com/wiki/Module:Footnotes/#L-524)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-525)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-526)[](https://freemwiki.com/wiki/Module:Footnotes/#L-527)if 5 == #out then-- when we have seen five args there may bemore[](https://freemwiki.com/wiki/Module:Footnotes/#L-528)local i = 6;-- initialize the indexer to the sixth positional parameter[](https://freemwiki.com/wiki/Module:Footnotes/#L-529)while args[i] do-- in case there are too many authors loop through the authors looking for a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-530)if is_year (args[i], args) then-- if a year[](https://freemwiki.com/wiki/Module:Footnotes/#L-531)out[5] = args[i];-- overwrite whatever was in args[5] with year[](https://freemwiki.com/wiki/Module:Footnotes/#L-532)break;-- and abandon the search[](https://freemwiki.com/wiki/Module:Footnotes/#L-533)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-534)i = i + 1;-- bump the indexer[](https://freemwiki.com/wiki/Module:Footnotes/#L-535)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-536)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-537)[](https://freemwiki.com/wiki/Module:Footnotes/#L-538)return mw.uri.anchorEncode ('CITEREF' .. table.concat (out));[](https://freemwiki.com/wiki/Module:Footnotes/#L-539)end[](https://freemwiki.com/wiki/Module:Footnotes/#L-540)[](https://freemwiki.com/wiki/Module:Footnotes/#L-541)[](https://freemwiki.com/wiki/Module:Footnotes/#L-542)--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------[](https://freemwiki.com/wiki/Module:Footnotes/#L-543)]][](https://freemwiki.com/wiki/Module:Footnotes/#L-544)[](https://freemwiki.com/wiki/Module:Footnotes/#L-545)return {[](https://freemwiki.com/wiki/Module:Footnotes/#L-546)harvard_citation = harvard_citation,[](https://freemwiki.com/wiki/Module:Footnotes/#L-547)sfn = sfn,[](https://freemwiki.com/wiki/Module:Footnotes/#L-548)sfnm = sfnm,[](https://freemwiki.com/wiki/Module:Footnotes/#L-549)sfnref = sfnref,[](https://freemwiki.com/wiki/Module:Footnotes/#L-550) target_check = target_check,[](https://freemwiki.com/wiki/Module:Footnotes/#L-551)};
Retrieved from "[https://freemwiki.com/index.php?title=Module:Footnotes&oldid=580068](https://freemwiki.com/index.php?title=Module:Footnotes&oldid=580068)"
* This page was last edited on 21 October 2025, at 06:18.
* Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727).
* [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy)
* [About](https://freemwiki.com/wiki/About)
* [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service)
* [Mobile view](https://freemwiki.com/index.php?title=Module:Footnotes&mobileaction=toggle_view_mobile)