Editing Module:Footnotes

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
require('Module:No globals');
+
f = {
local getArgs = require ('Module:Arguments').getArgs;
+
args_default = {
 
+
bracket_left = "",
 
+
bracket_right = "",
--[[--------------------------< A R G S _ D E F A U L T >------------------------------------------------------
+
bracket_year_left = "",
 
+
bracket_year_right = "",
a table to specify initial values.
+
postscript = "",
 
+
page = "",
]]
+
pages = "",
 
+
location = "",
local args_default = {
+
page_sep = ", p.&nbsp;",
bracket_left = '',
+
pages_sep = ", pp.&nbsp;",
bracket_right = '',
+
ref = "",
bracket_year_left = '',
+
P1 = "",
bracket_year_right = '',
+
P2 = "",
postscript = '',
+
P3 = "",
page = '',
+
P4 = "",
pages = '',
+
P5 = ""
location = '',
 
page_sep = ", p.&nbsp;",
 
pages_sep = ", pp.&nbsp;",
 
ref = '',
 
template = 'harv', -- if template name not provided in {{#invoke:}} use this
 
};
 
 
 
 
 
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
 
 
 
look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list
 
 
 
the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside
 
a template that wraps another template; 'multiple targets' error may not be suppressed
 
 
 
]]
 
 
 
local function target_check (anchor_id, args)
 
local namespace = mw.title.getCurrentTitle().namespace;
 
local anchor_id_list_module = mw.loadData ('Module:Footnotes/anchor_id_list');
 
local anchor_id_list = anchor_id_list_module.anchor_id_list;
 
local article_whitelist = anchor_id_list_module.article_whitelist;
 
local template_list = anchor_id_list_module.template_list;
 
 
local whitelist_module = mw.loadData ('Module:Footnotes/whitelist');
 
local whitelist = whitelist_module.whitelist;
 
local special_patterns = whitelist_module.special_patterns;
 
local DNB_special_patterns = whitelist_module.DNB_special_patterns;
 
local DNB_template_names = whitelist_module.DNB_template_names;
 
 
 
if 10 == namespace then
 
return ''; -- automatic form of |no-tracking=yes; TODO: is this too broad?
 
end
 
 
 
local tally = anchor_id_list[anchor_id]; -- nil when anchor_id not in list; else a tally
 
local msg;
 
local category;
 
 
 
if not tally then
 
if args.ignore then
 
return ''; -- if ignore is true then no message, no category
 
end
 
 
if article_whitelist and article_whitelist[anchor_id] then -- if an article-local whitelist and anchor ID is in it
 
return ''; -- done
 
end
 
 
local wl_anchor_id = anchor_id; -- copy to be modified to index into the whitelist
 
 
if args.year then -- for anchor IDs created by this template (not in |ref=) that have a date
 
if args.year:match ('%d%l$') or -- use the date value to determine if we should remove the disambiguator
 
args.year:match ('n%.d%.%l$') or
 
args.year:match ('nd%l$') then
 
wl_anchor_id = wl_anchor_id:gsub ('%l$', ''); -- remove the disambiguator
 
end
 
end
 
 
 
local t_tbl = whitelist[wl_anchor_id]; -- get list of templates associated with this anchor ID
 
 
 
if t_tbl then -- when anchor ID not whitelisted t_tbl is nil
 
for _, t in ipairs (t_tbl) do -- spin through the list of templates associated with this anchor ID
 
if template_list[t] then -- if associated template is found in the list of templates in the article
 
return ''; -- anchor ID is whitlisted and article has matching template so no error
 
end
 
end
 
end
 
 
 
for _, pattern in ipairs (special_patterns) do -- spin through the spcial patterns and try to match
 
if anchor_id:match (pattern) then
 
return '';
 
end
 
end
 
 
 
for _, dnb_t in ipairs (DNB_template_names or {}) do -- getting desparate now, are there any DNB templates? DNB_template_names may be nil; empty table prevents script error
 
if template_list[dnb_t] then -- if the article has this DNB template
 
for _, pattern in ipairs (DNB_special_patterns) do -- spin through the DNB-specifiec wildcard patterns
 
if anchor_id:match (pattern) then -- and attempt a match
 
return ''; -- found a match
 
end
 
end
 
end
 
end
 
 
 
msg = 'no target: ' .. anchor_id; -- anchor_id not found
 
category = '[[Category:Harv and Sfn no-target errors]]';
 
 
 
elseif 1 < tally then
 
msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id; -- more than one anchor_id in this article
 
category = '[[Category:Harv and Sfn multiple-target errors]]';
 
end
 
 
 
-- category = 0 == namespace and '[[Category:Harv and Sfn template errors]]' or ''; -- only categorize in article space
 
category = 0 == namespace and category or ''; -- only categorize in article space
 
 
 
--use this version to show error messages
 
-- return msg and '<span class="error harv-error" style="display: inline; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
 
--use this version to hide error messages
 
return msg and '<span class="error harv-error" style="display: none; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
 
 
 
end
 
 
 
 
 
--[[--------------------------< I S _ Y E A R >----------------------------------------------------------------
 
 
 
evaluates param to see if it is one of these forms with or without lowercase letter disambiguator:
 
YYYY
 
n.d.
 
nd
 
c. YYYY
 
YYYY–YYYY (separator is endash)
 
YYYY–YY (separator is endash)
 
 
 
return true when param has a recognized form; false else
 
 
 
]]
 
 
 
local patterns_date= {
 
'^%d%d%d%d?%l?$',
 
'^n%.d%.%l?$',
 
'^nd%l?$',
 
'^c%. %d%d%d%d?%l?$',
 
'^%d%d%d%d–%d%d%d%d%l?$',
 
'^%d%d%d%d–%d%d%l?$',
 
 
}
 
}
 +
};
  
local function is_year (param, args)
+
function trim( str )
args.year = ''; -- used for harv error;
+
if str == nil then
+
return nil;
for _, pattern in ipairs (patterns_date) do
 
if mw.ustring.match (param, pattern) then
 
args.year = param; -- used for harv error;
 
return true;
 
end
 
 
end
 
end
end
+
return str:match( "^%s*(.-)%s*$");
 
+
end   
 
 
--[[--------------------------< C O R E >----------------------------------------------------------------------
 
 
 
returns an anchor link (CITEREF) formed from one to four author names, year, and insource location (|p=, |pp=, loc=)
 
 
 
]]
 
  
local function core( args )
+
function core( args )
 
local result;
 
local result;
local err_msg = ''
 
 
if args.P5 ~= '' then
 
if is_year (args.P5, args) then
 
result = table.concat ({args.P1, ' et al. ', args.bracket_year_left, args.P5, args.bracket_year_right});
 
else
 
args.P5 = ''; -- when P5 not a year don't include in anchor
 
result = table.concat ({args.P1, ' et al.'}); -- and don't render it
 
end
 
 
elseif args.P4 ~= '' then
 
if is_year (args.P4, args) then
 
result = table.concat ({args.P1, ', ', args.P2, ' &amp; ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right}); -- three names and a year
 
else
 
result = table.concat ({args.P1, ' et al.'}); -- four names
 
end
 
  
elseif args.P3 ~= '' then
+
if args.P5 ~= "" then
if is_year (args.P3, args) then
+
result = args.P1 .. ' et al. ' .. args.bracket_year_left .. args.P5 ..
result = table.concat ({args.P1, ' &amp; ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right}); -- two names and a year
+
args.bracket_year_right;
else
+
elseif args.P4 ~= "" then
result = table.concat ({args.P1, ', ', args.P2, ' ', ' &amp; ', args.P3}); -- three names
+
result = args.P1 .. ', ' .. args.P2 .. ' &amp; ' .. args.P3 .. ' ' ..
end
+
args.bracket_year_left .. args.P4 .. args.bracket_year_right;
+
elseif args.P3 ~= "" then
elseif args.P2 ~= '' then
+
result = args.P1 .. ' &amp; ' .. args.P2 .. ' ' .. args.bracket_year_left ..
if is_year (args.P2, args) then
+
args.P3 .. args.bracket_year_right;
result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right}); -- one name and year
 
else
 
result = table.concat ({args.P1, ' &amp; ', args.P2}); -- two names
 
end
 
 
 
else
 
else
result = args.P1; -- one name
+
result = trim( args.P1 .. ' ' .. args.bracket_year_left .. args.P2 ..
 +
args.bracket_year_right )
 
end
 
end
-- when author-date result ends with a dot (typically when the last positional parameter holds 'n.d.')
+
 
-- and when no in-source location (no |p=, |pp=, or |loc=)
 
-- and when the first or only character in args.postscript is a dot
 
-- remove the author-date result trailing dot
 
-- the author-date result trailing dot will be replaced later with the content of args.postscript (usually a dot)
 
if ('.' == result:sub(-1)) and ('.' == args.postscript:sub(1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then
 
result = result:gsub ('%.$', '');
 
end
 
 
 
if args.ref ~= 'none' then
 
if args.ref ~= 'none' then
local anchor_id;
+
if args.ref ~= "" then
if args.ref ~= '' then
+
result = "[[#" .. mw.uri.anchorEncode(args.ref) .. "|" .. result .. "]]";
anchor_id = mw.uri.anchorEncode (args.ref);
 
err_msg = target_check (anchor_id, args);
 
result = table.concat ({'[[#', anchor_id, '|', result, ']]'});
 
 
else
 
else
anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5}));
+
result = "[[#CITEREF" .. mw.uri.anchorEncode(args.P1 .. args.P2 .. args.P3 .. args.P4 .. args.P5) .. "|" .. result .. "]]";
err_msg = target_check (anchor_id, args);
 
result = table.concat ({'[[#', anchor_id, '|', result, ']]'});
 
 
end
 
end
 
end
 
end
  
if args.page ~= '' then
+
if args.page ~= "" then
result = table.concat ({result, args.page_sep, args.page});
+
result = result .. args.page_sep .. args.page;
elseif args.pages ~= ''then
+
elseif args.pages ~= "" then
result = table.concat ({result, args.pages_sep, args.pages});
+
result = result .. args.pages_sep .. args.pages;
 
end       
 
end       
  
if args.location ~= '' then
+
if args.location ~= "" then
result = table.concat ({result, ', ', args.location});
+
result = result .. ", " .. args.location;
 
end
 
end
  
result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' '); -- strip redundant spaces
+
result = args.bracket_left .. result .. args.bracket_right .. args.postscript;
return result .. err_msg;
+
return result;
 
end
 
end
  
 +
function f.harvard_core( frame )
 +
local args = {};
 +
local pframe = frame:getParent();
  
--[[--------------------------< A R G S  _ F E T C H >---------------------------------------------------------
+
args.bracket_left = pframe.args.BracketLeft or "";
 
+
args.bracket_right = pframe.args.BracketRight or "";
Because all of the templates share a common set of parameters, a single common function to fetch those parameters
+
args.bracket_year_left = pframe.args.BracketYearLeft or "";
from frame and parent frame.
+
args.bracket_year_right = pframe.args.BracketYearRight or "";
 
+
args.postscript = pframe.args.Postscript or "";
]]
 
 
 
local function args_fetch (frame, ps)
 
local args = args_default; -- create a copy of the default table
 
local pframe = frame:getParent(); -- point to the template's parameter table
 
 
 
for k, v in pairs (frame.args) do -- override defaults with values provided in the #invoke: if any
 
args[k] = v;  
 
end
 
 
args.postscript = pframe.args.postscript or pframe.args.ps or ps;
 
 
if 'none' == args.postscript then
 
if 'none' == args.postscript then
 
args.postscript = '';
 
args.postscript = '';
 
end
 
end
args.page = pframe.args.p or pframe.args.page or '';
 
args.pages = pframe.args.pp or pframe.args.pages or '';
 
args.location = pframe.args.loc or '';
 
args.ref = pframe.args.ref or pframe.args.Ref or '';
 
args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']);
 
  
for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do -- loop through the five positional parameters and trim if set else empty string
+
args.page = pframe.args.Page or "";
args[v] = (pframe.args[i] and mw.text.trim (pframe.args[i])) or '';
+
args.pages = pframe.args.Pages or "";
end
+
args.location = pframe.args.Location or "";
 
+
args.page_sep = pframe.args.PageSep or "";
if args.P5 and not is_year (args.P5, args) then
+
args.pages_sep = pframe.args.PagesSep or "";
local i = 6; -- initialize the indexer to the sixth positional parameter
+
args.ref = pframe.args.REF or "{{{REF}}}";
while pframe.args[i] do -- in case there are too many authors loop through the authors looking for a year
+
args.P1 = trim( pframe.args.P1 ) or "";
local v = mw.text.trim (pframe.args[i]); -- trim
+
args.P2 = trim( pframe.args.P2 ) or "";
if is_year (v, args) then -- if a year
+
args.P3 = trim( pframe.args.P3 ) or "";
args.P5 = v; -- overwrite whatever was in args.P5 with year
+
args.P4 = trim( pframe.args.P4 ) or "";
break; -- and abandon the search
+
args.P5 = trim( pframe.args.P5 ) or "";
end
 
i = i + 1; -- bump the indexer
 
end
 
end
 
return args;
 
end
 
 
 
 
 
--[[--------------------------< H A R V A R D _ C I T A T I O N >----------------------------------------------
 
 
 
common entry point for:
 
{{harvard citation}} aka {{harv}}
 
{{Harvard citation no brackets}} aka {{harvnb}}
 
{{harvcol}}
 
{{harvcolnb}}
 
{{harvcoltxt}}
 
{{Harvard citation text}} aka {{harvtxt}}
 
{{Harvp}}
 
 
 
Distinguishing features (brackets and page separators) are specified in this module's {{#invoke}} in the respective templates.
 
 
 
]]
 
 
 
local function harvard_citation (frame)
 
local args = args_fetch (frame, ''); -- get the template and invoke parameters; default postscript is empty string
 
  
return core (args);
+
return core( args );
 
end
 
end
  
 +
function f.harvard_citation( frame )
 +
local args = f.args_default;
 +
pframe = frame:getParent();
  
--[[--------------------------< S T R I P _ U R L >------------------------------------------------------------
+
args.bracket_left = "(";
 
+
args.bracket_right = ")";
used by sfn() and sfnm(). This function fixes an issue with reference tooltip gadget where the tooltip is not displayed
+
args.page = pframe.args.p or pframe.args.page or "";
when an insource locator (|p=, |pp=, |loc=) has an external wikilink that contains a # character
+
args.pages = pframe.args.pp or pframe.args.pages or "";
 
+
args.location = pframe.args.loc or "";
strip uri-reserved characters from urls in |p=, |pp-, and |loc= parameters  The researved characters are:
+
args.ref = pframe.args.ref or pframe.args.Ref or "";
!#$&'()*+,/:;=?@[]
+
args.P1 = trim( pframe.args[1] ) or "";
+
args.P2 = trim( pframe.args[2] ) or "";
]]
+
args.P3 = trim( pframe.args[3] ) or "";
 +
args.P4 = trim( pframe.args[4] ) or "";
 +
args.P5 = trim( pframe.args[5] ) or "";
  
local function strip_url (pages)
+
return core( args );
local escaped_uri;
 
if not pages or ('' == pages) then
 
return pages;
 
end
 
 
for uri in pages:gmatch ('%[(%a[%w%+%.%-]*://%S+)') do -- for each external link get the uri
 
escaped_uri = uri:gsub ("([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ); -- save a copy with lua pattern characters escaped
 
uri = uri:gsub ("[!#%$&'%(%)%*%+,/:;=%?@%[%]%.%%]", ''); -- remove reserved characters and '%' because '%20' (space character) is a lua 'invalid capture index'
 
pages = pages:gsub (escaped_uri, uri, 1); -- replace original uri with the stripped version
 
end
 
 
return pages;
 
 
end
 
end
  
 +
function f.harvard_citation_no_bracket( frame )
 +
local args = f.args_default;
 +
pframe = frame:getParent();
  
--[[--------------------------< S F N >------------------------------------------------------------------------
+
args.page = pframe.args.p or pframe.args.page or "";
 
+
args.pages = pframe.args.pp or pframe.args.pages or "";
entry point for {{sfn}} and {{sfnp}}
+
args.location = pframe.args.loc or "";
 
+
args.ref = pframe.args.ref or pframe.args.Ref or "";
]]
+
args.P1 = trim( pframe.args[1] ) or "";
 
+
args.P2 = trim( pframe.args[2] ) or "";
local function sfn (frame)
+
args.P3 = trim( pframe.args[3] ) or "";
local args = args_fetch (frame, '.'); -- get the template and invoke parameters; default postscript is a dot
+
args.P4 = trim( pframe.args[4] ) or "";
 
+
args.P5 = trim( pframe.args[5] ) or "";
local result = core (args); -- go make a CITEREF anchor
 
-- put it all together and then strip redundant spaces
 
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+', ' ');
 
 
 
return frame:extensionTag ({name='ref', args={name=name}, content=result});
 
  
+
return core( args );
 
end
 
end
  
 
+
function f.sfn( frame )
--[[--------------------------< S F N M >----------------------------------------------------------------------
+
local args = f.args_default;
 
+
for k, v in pairs( frame.args ) do -- for {{sfnp}}, override default with values provided in the #invoke:
common entry point for {{sfnm}} and {{sfnmp}}
 
 
 
Distinguishing features (brackets) are specified in this module's {{#invoke}} in the respective templates.
 
 
 
]]
 
 
 
local function sfnm (frame)
 
local args = args_default; -- create a copy of the default table
 
local pframe = frame:getParent(); -- point to the template's parameter table
 
 
local n = 1; -- index of source; this is the 'n' in na1, ny, etc
 
local first_pnum = 1; -- first of a pair of positional parameters
 
local second_pnum = 2; -- second of a pair of positional parameters
 
 
 
local last_ps = 0; -- index of the last source with |nps= set
 
local last_index = 0; -- index of the last source; these used to determine which of |ps= or |nps= will terminate the whole rendering
 
 
 
local out = {}; -- table to hold rendered sources
 
local footnote = {'FOOTNOTE'}; -- all author, date, insource location stuff becomes part of the reference's footnote id; added as we go
 
 
 
for k, v in pairs (frame.args) do -- override defaults with values provided in the #invoke: if any
 
 
args[k] = v;    
 
args[k] = v;    
 
end
 
end
 
 
while true do
+
pframe = frame:getParent();
if not pframe.args[table.concat ({n, 'a1'})] and not pframe.args[first_pnum] then
 
break; -- no na1 or matching positional parameter so done
 
end
 
 
if pframe.args[table.concat ({n, 'a1'})] then -- does this source use named parameters?
 
for _, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do -- initialize for this source
 
args[v] = '';
 
end
 
  
for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do -- extract author and year parameters for this source
+
args.postscript = pframe.args.postscript or pframe.args.ps or ".";
args[v] = pframe.args[table.concat ({n, 'a', i})] or ''; -- attempt to assign author name
+
if 'none' == args.postscript then
if '' == args[v] then -- when there wasn't an author name
+
args.postscript = '';
args[v] = pframe.args[table.concat ({n, 'y'})] or ''; -- attempt to assign year
 
break; -- done with author/date for this source
 
end
 
end
 
 
 
else -- this source uses positional parameters
 
args.P1 = mw.text.trim (pframe.args[first_pnum]); -- yes, only one author supported
 
args.P2 = (pframe.args[second_pnum] and mw.text.trim (pframe.args[second_pnum])) or ''; -- when positional author, year must also be positional
 
 
 
for _, v in ipairs ({'P3', 'P4', 'P5'}) do -- blank the rest of these for this source
 
args[v] = '';
 
end
 
 
 
first_pnum = first_pnum + 2; -- source must use positional author and positional year
 
second_pnum = first_pnum + 1; -- bump these for possible next positional source
 
end
 
 
args.postscript = pframe.args[table.concat ({n, 'ps'})] or '';
 
if 'none' == args.postscript then -- this for compatibility with other footnote templates; does nothing
 
args.postscript = '';
 
end
 
 
 
args.ref = pframe.args[table.concat ({n, 'ref'})] or ''; -- alternate reference for this source
 
 
 
args.page = pframe.args[table.concat ({n, 'p'})] or ''; -- insource locations for this source
 
args.pages = pframe.args[table.concat ({n, 'pp'})] or '';
 
args.location = pframe.args[table.concat ({n, 'loc'})] or '';
 
args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);
 
-- args.ignore = 'yes' == pframe.args[table.concat ({n, 'ignore-err'})];
 
 
 
table.insert (out, core (args)); -- save the rendering of this source
 
 
for k, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do -- create the FOOTNOTE id
 
if '' ~= args[v] then
 
table.insert (footnote, args[v]);
 
end
 
end
 
for k, v in ipairs ({'page', 'pages', 'location'}) do -- these done separately so that we can strip uri-reserved characters from extlinked page numbers
 
if '' ~= args[v] then
 
table.insert (footnote, strip_url (args[v]))
 
end
 
end
 
 
last_index = n; -- flags used to select terminal postscript from nps or from end_ps
 
if '' ~= args.postscript then
 
last_ps = n;
 
end
 
 
n = n+1; -- bump for the next one
 
end
 
 
local name = table.concat (footnote):gsub ('%s+', ' '); -- put the footnote together and strip redundant space
 
 
args.end_ps = pframe.args.postscript or pframe.args.ps or '.'; -- this is the postscript for the whole not for the individual sources
 
if 'none' == args.end_ps then -- not an original sfnm parameter value; added for compatibility with other footnote templates
 
args.end_ps = '';
 
 
end
 
end
 +
args.page = pframe.args.p or pframe.args.page or "";
 +
args.pages = pframe.args.pp or pframe.args.pages or "";
 +
args.location = pframe.args.loc or "";
 +
args.ref = pframe.args.ref or pframe.args.Ref or "";
 +
args.P1 = trim( pframe.args[1] ) or "";
 +
args.P2 = trim( pframe.args[2] ) or "";
 +
args.P3 = trim( pframe.args[3] ) or "";
 +
args.P4 = trim( pframe.args[4] ) or "";
 +
args.P5 = trim( pframe.args[5] ) or "";
  
local result = table.concat ({table.concat (out, '; '), (last_index == last_ps) and '' or  args.end_ps});
+
local result = core( args );
return frame:extensionTag ({name='ref', args={name=name}, content=result});
+
local name = "FOOTNOTE" .. args.P1 .. args.P2 ..
end
+
args.P3 .. args.P4 .. args.P5 .. args.page .. args.pages .. args.location;
 
 
 
 
--[[--------------------------< S F N R E F >------------------------------------------------------------------
 
 
 
implements {{sfnref}}
 
  
]]
+
result = frame:extensionTag{ name = "ref", args = {name=name}, content=result };
  
local function sfnref (frame)
+
return result;
local args = getArgs (frame);
 
local out = {};
 
 
for i=1, 5 do -- get the first five args if there are five args
 
if args[i] then
 
out[i] = args[i];
 
else
 
break; -- less than 5 args break out
 
end
 
end
 
 
if 5 == #out then -- when we have seen five args there may bemore
 
local i = 6; -- initialize the indexer to the sixth positional parameter
 
while args[i] do -- in case there are too many authors loop through the authors looking for a year
 
if is_year (args[i], args) then -- if a year
 
out[5] = args[i]; -- overwrite whatever was in args[5] with year
 
break; -- and abandon the search
 
end
 
i = i + 1; -- bump the indexer
 
end
 
end
 
 
return mw.uri.anchorEncode ('CITEREF' .. table.concat (out));
 
 
end
 
end
  
 
+
return f;
--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
 
]]
 
 
 
return {
 
harvard_citation = harvard_citation,
 
sfn = sfn,
 
sfnm = sfnm,
 
sfnref = sfnref,
 
};
 

Please note that all contributions to All About Ayrshire may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see All About Ayrshire:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: