Content deleted Content added
sync from sandbox; |
replace target_check() with call to target_check() in Module:Footnotes, which has full wrapper/whitelist functionality |
||
(20 intermediate revisions by 6 users not shown) | |||
Line 1:
require('
local code_open_tag = '<code
local lock_icons = { --icon classes are defined in Module:Citation/CS1/styles.css
['
['
}
--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------
check to see if target of harvc exists in the page somewhere. Uses the target check mechanism from Module:Footnotes
setting |ignore-errors=yes in {{harvc}} will override this check
]]
local function target_check (anchor_id, ignore)
local whitelist_check = require('Module:Footnotes').target_check
local args = {ignore=ignore, template='Harvc', show=true}
return whitelist_check(anchor_id, args)
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Whether variable is set or not. A
]]
Line 30 ⟶ 44:
c. YYYY
YYYY–YYYY (separator is endash)
YYYY–YY (separator is endash)
when anchor_year present, year portion must be same as year param and must have disambiguator
Line 49 ⟶ 64:
'^(nd)%l?$', -- nd
'^(c%. %d%d%d%d?)%l?$', -- c. YYY or c. YYYY
'^(%d%d%d%d–%d%d%d%d)%l?$', -- YYYY–YYYY
'^(%d%d%d%d–%d%d)%l?$' -- YYYY–YY
}
Line 72 ⟶ 88:
if not ay then
return ' invalid ' .. code_open_tag .. '|anchor-year</code>.';
end
-- if not anchor_year:match ('%l$') then
-- return ' ' .. code_open_tag .. '|anchor-year=</code> missing dab.';
-- end
if y ~= ay then
Line 134 ⟶ 150:
local source = ''; -- editor/author date list that forms a CITEREF link to a full citation
local in_text = ' In ';
local result; -- the assemby of the above output▼
-- form the CITEREF anchor
if is_set (args.id) then
args.id = mw.uri.anchorEncode (args.id)
span_open_tag = '<span id="' .. args.id .. '" class="citation">'; -- for use when contributor name is same as source name
else
citeref = mw.uri.anchorEncode (citeref);
span_open_tag = '<span id="' .. citeref .. '" class="citation">';
end
--[[
form the contributors display list:
if |name-list-
if |display-authors= is empty or omitted, display is similar to cs1|2: display all names in last, first order
if |display-authors=etal then displays all author names in last, first order and append et al.
if value assigned to |display-authors= is less than the number of author last names, displays the specified number of author names in last, first order followed by et al.
]]
if 'harv' ~= args.
local i = 1;
local count;
Line 174 ⟶ 192:
count = #args.last; -- set count to display all of the authors
end
while i <= count do
if is_set (contributors) then
Line 185 ⟶ 203:
if true == etal then
contributors = contributors .. ' et al.'; -- append et al.
elseif '
contributors = contributors:gsub('; ([^;]+)$', ' & %1') -- replace last separator with ' & '
end
Line 218 ⟶ 236:
--assemble CITEREF wikilink
local anchor_id;
source = "[[#CITEREF" .. mw.uri.anchorEncode(table.concat ({args.in1, args.in2, args.in3, args.in4, args.year})) .. "|" .. source .. "]]";▼
local target_err_msg;
if '' ~= args.ref then
anchor_id = mw.uri.anchorEncode (args.ref)
else
▲
end
target_err_msg = target_check (anchor_id, args.ignore); -- see if there is a target for this anchor_id
source = '[[#' .. anchor_id .. "|" .. source .. "]]";
-- special case for afterword, foreword, introduction, preface
local no_quotes = ({['afterword']=true, ['foreword']=true, ['introduction']=true, ['preface']=true})[args.contribution:lower()];
--combine contribution with url to make external link
Line 237 ⟶ 268:
end
end
end
Line 269 ⟶ 297:
-- and put it all together
table.insert (result, span_open_tag);
table.insert (result, contributors);
table.insert (result, no_quotes and ' ' or ' "'); -- foreword, afterword, introduction, preface contributions are not quoted; all other contributions are
table.insert (result, args.contribution);
table.insert (result, no_quotes and '' or '"'); -- foreword, afterword, introduction, preface contributions are not quoted; all other contributions are
table.insert (result, args.sepc);
table.insert (result, in_text);
table.insert (result, source);
table.insert (result, args.p);
table.insert (result, args.ps);
table.insert (result, args.err_msg);
if not is_set(args.err_msg) then
table.insert (result, target_err_msg)
end
table.insert (result, '</span>');
return table.concat (result); -- make a string and done
end
Line 311 ⟶ 354:
args.display_authors = pframe.args['display-authors']; -- the number of contributor names to display; cs1|2 format includes first names
args.
args.
▲ args.last_author_amp = args.last_author_amp:lower(); -- make it case agnostic
if is_set (pframe.args.last) or is_set (pframe.args.last1) or
is_set (pframe.args.author) or is_set (pframe.args.author1) then -- must have at least this to continue
Line 337 ⟶ 378:
end
end
args.p = pframe.args.p or pframe.args.page or ''; -- source page number(s) or ___location
args.pp = pframe.args.pp or pframe.args.pages or '';
args.loc = pframe.args.loc or '';
args.ref = pframe.args.ref or pframe.args.Ref or ''; -- used to match |ref=<text> in cs1|2 source template
args.ignore = 'yes' == pframe.args['ignore-err']; -- suppress false-positive 'no target' errors
if 'cs2' == pframe.args.mode then
Line 385 ⟶ 432:
end
return table.concat ({
end
|