Module:links: Difference between revisions

No edit summary
No edit summary
Line 11: Line 11:
[[Module:languages]] and its submodules
[[Module:languages]] and its submodules
[[Module:gender and number]]
[[Module:gender and number]]
[[Module:debug/track]]
]=]
]=]


local anchors_module = "Module:anchors"
local anchors_module = "Module:anchors"
local debug_track_module = "Module:debug/track"
local form_of_module = "Module:form of"
local form_of_module = "Module:form of"
local gender_and_number_module = "Module:gender and number"
local gender_and_number_module = "Module:getn"
local languages_module = "Module:languages"
local languages_module = "Module:languages"
local load_module = "Module:load"
local load_module = "Module:load"
Line 50: Line 48:
anchor_encode = require(memoize_module)(mw.uri.anchorEncode, true)
anchor_encode = require(memoize_module)(mw.uri.anchorEncode, true)
return anchor_encode(...)
return anchor_encode(...)
end
local function debug_track(...)
debug_track = require(debug_track_module)
return debug_track(...)
end
end


Line 172: Line 165:
m_headword_data = load_data("Module:headword/data")
m_headword_data = load_data("Module:headword/data")
return m_headword_data
return m_headword_data
end
local function track(page, code)
local tracking_page = "links/" .. page
debug_track(tracking_page)
if code then
debug_track(tracking_page .. "/" .. code)
end
end
end


Line 237: Line 222:
--[==[Takes an input and splits on a double slash (taking account of escaping backslashes).]==]
--[==[Takes an input and splits on a double slash (taking account of escaping backslashes).]==]
function export.split_on_slashes(text)
function export.split_on_slashes(text)
if text:find("\\", nil, true) then
track("escaped", "split_on_slashes")
end
text = split(escape(text, "//"), "//", true) or {}
text = split(escape(text, "//"), "//", true) or {}
for i, v in ipairs(text) do
for i, v in ipairs(text) do
Line 303: Line 285:
--[==[Takes a link target and outputs the actual target and the fragment (if any).]==]
--[==[Takes a link target and outputs the actual target and the fragment (if any).]==]
function export.get_fragment(text)
function export.get_fragment(text)
if text:find("\\", nil, true) then
track("escaped", "get_fragment")
end
-- If there are no embedded links, process input.
-- If there are no embedded links, process input.
local open = find(text, "[[", nil, true)
local open = find(text, "[[", nil, true)
Line 337: Line 316:
if not target then
if not target then
return nil
return nil
elseif target:find("\\", nil, true) then
track("escaped", "get_link_page")
end
end


Line 344: Line 321:


if target:sub(1, 1) == ":" then
if target:sub(1, 1) == ":" then
track("initial colon")
-- FIXME, the auto_display (second return value) should probably remove the colon
-- FIXME, the auto_display (second return value) should probably remove the colon
return target:sub(2), orig_target
return target:sub(2), orig_target
Line 381: Line 357:
end
end
target, escaped = target:gsub("^(\\-)\\%*", "%1*")
target, escaped = target:gsub("^(\\-)\\%*", "%1*")
 
if reconstructed == 0 and lang:hasType("reconstructed") and not lang:hasType("conlang") then
orig_target = "*" .. target
reconstructed = 1
end
if not (sc and sc:getCode() ~= "None") then
if not (sc and sc:getCode() ~= "None") then
sc = lang:findBestScript(target)
sc = lang:findBestScript(target)
Line 404: Line 385:
-- Link to appendix for reconstructed terms and terms in appendix-only languages. Plain links interpret *
-- Link to appendix for reconstructed terms and terms in appendix-only languages. Plain links interpret *
-- literally, however.
-- literally, however.
if reconstructed == 1 then
if not lang:hasType("conlang") then
if lang:getFullCode() == "und" then
if lang:hasType("appendix-constructed") then
-- Return the original target as default display value. If we don't do this, we wrongly get
target = "wikt:Appendix:" .. lang:getFullName() .. "/" .. target
-- [Term?] displayed instead.
elseif reconstructed == 1 then -- asterisk found
return nil, orig_target
if lang:getFullCode() == "und" then
-- Return the original target as default display value. If we don't do this, we wrongly get
-- [Term?] displayed instead.
return nil, orig_target
end
target = "wikt:Reconstruction:" .. lang:getFullName() .. "/" .. target
elseif anti_asterisk ~= 1 and (lang:hasType("reconstructed") or lang:getFamilyCode() == "qfa-sub") then
--error("The specified language " .. lang:getCanonicalName()
--.. " is unattested, while the given term does not begin with '*' to indicate that it is reconstructed.")
orig_target = "*" .. target
end
end
target = "Reconstruction:" .. lang:getFullName() .. "/" .. target
-- Reconstructed languages and substrates require an initial *.
elseif anti_asterisk ~= 1 and (lang:hasType("reconstructed") or lang:getFamilyCode() == "qfa-sub") then
error(("The specified language %s is unattested, while the term '%s' does not begin with '*' to indicate that it is reconstructed.")
:
format(lang:getCanonicalName(), orig_target))
elseif lang:hasType("appendix-constructed") then
target = "Appendix:" .. lang:getFullName() .. "/" .. target
else
target = target
end
end
target = (lang:hasType("conlang") and "Contionary:" or "wikt:") .. target


return target, orig_target, escaped > 0
return target, orig_target, escaped > 0
Line 514: Line 497:
if prefix ~= "category" and not (prefix and load_data("Module:data/interwikis")[prefix]) then
if prefix ~= "category" and not (prefix and load_data("Module:data/interwikis")[prefix]) then
if (link.fragment or link.target:sub(-1) == "#") and not plain then
if (link.fragment or link.target:sub(-1) == "#") and not plain then
track("fragment", lang:getFullCode())
if cats then
if cats then
insert(cats, lang:getFullName() .. " links with manual fragments")
insert(cats, lang:getFullName() .. " links with manual fragments")
Line 576: Line 558:
local function check_params_ignored_when_embedded(alt, lang, id, cats)
local function check_params_ignored_when_embedded(alt, lang, id, cats)
if alt then
if alt then
track("alt-ignored")
if cats then
if cats then
insert(cats, lang:getFullName() .. " links with ignored alt parameters")
insert(cats, lang:getFullName() .. " links with ignored alt parameters")
Line 582: Line 563:
end
end
if id then
if id then
track("id-ignored")
if cats then
if cats then
insert(cats, lang:getFullName() .. " links with ignored id parameters")
insert(cats, lang:getFullName() .. " links with ignored id parameters")
Line 761: Line 741:
error(
error(
"The first argument to the function language_link must be a table. See Module:links/documentation for more information.")
"The first argument to the function language_link must be a table. See Module:links/documentation for more information.")
elseif data.term and data.term:find("\\", nil, true) or data.alt and data.alt:find("\\", nil, true) then
track("escaped", "language_link")
end
end


Line 788: Line 766:
error(
error(
"The first argument to the function plain_link must be a table. See Module:links/documentation for more information.")
"The first argument to the function plain_link must be a table. See Module:links/documentation for more information.")
elseif data.term and data.term:find("\\", nil, true) or data.alt and data.alt:find("\\", nil, true) then
track("escaped", "plain_link")
end
end


Line 810: Line 786:
error(
error(
"The first argument to the function embedded_language_links must be a table. See Module:links/documentation for more information.")
"The first argument to the function embedded_language_links must be a table. See Module:links/documentation for more information.")
elseif data.term and data.term:find("\\", nil, true) or data.alt and data.alt:find("\\", nil, true) then
track("escaped", "embedded_language_links")
end
end


Line 840: Line 814:
tag = { '<span class="mention-gloss-double-quote">“</span><span class="mention-gloss">',
tag = { '<span class="mention-gloss-double-quote">“</span><span class="mention-gloss">',
'</span><span class="mention-gloss-double-quote">”</span>' }
'</span><span class="mention-gloss-double-quote">”</span>' }
if type(text) == "string" and text:match("^''[^'].*''$") then
-- Temporary tracking for mention glosses that are entirely italicized or bolded, which is probably
-- wrong. (Note that this will also find bolded mention glosses since they use triple apostrophes.)
track("italicized-mention-gloss", lang and lang:getFullCode() or nil)
end
elseif item_type == "tr" then
elseif item_type == "tr" then
if face == "term" then
if face == "term" then
Line 1,195: Line 1,164:
error("The first argument to the function full_link must be a table. "
error("The first argument to the function full_link must be a table. "
.. "See Module:links/documentation for more information.")
.. "See Module:links/documentation for more information.")
elseif data.term and data.term:find("\\", nil, true) or data.alt and data.alt:find("\\", nil, true) then
track("escaped", "full_link")
end
end


Line 1,339: Line 1,306:
if data.tr[1] then
if data.tr[1] then
local full_code = lang:getFullCode()
local full_code = lang:getFullCode()
track("manual-tr", full_code)
end
end


Line 1,461: Line 1,427:
if type(link) ~= "string" then
if type(link) ~= "string" then
error("The first argument to section_link was a " .. type(link) .. ", but it should be a string.")
error("The first argument to section_link was a " .. type(link) .. ", but it should be a string.")
elseif link:find("\\", nil, true) then
track("escaped", "section_link")
end
end