Module:links: Difference between revisions

2,220 bytes removed ,  22 November 2025
no edit summary
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 gender_and_number_module = "Module:getn"
local gender_and_number_module = "Module:gender and number"
local languages_module = "Module:languages"
local languages_module = "Module:languages"
local load_module = "Module:load"
local load_module = "Module:load"
Line 49: Line 47:
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 171: Line 164:
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 236: Line 221:
--[==[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 302: Line 284:
--[==[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 336: Line 315:
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 343: Line 320:
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 407: Line 383:
return nil, orig_target
return nil, orig_target
end
end
target = "Reconstruction:" .. lang:getFullName() .. "/" .. target
if not lang:hasType("conlang") then
target = "Reconstruction:" .. lang:getFullName() .. "/" .. target
end
-- Reconstructed languages and substrates require an initial *.
-- Reconstructed languages and substrates require an initial *.
elseif anti_asterisk ~= 1 and (lang:hasType("reconstructed") or lang:getFamilyCode() == "qfa-sub") then
elseif anti_asterisk ~= 1 and (lang:hasType("reconstructed") or lang:getFamilyCode() == "qfa-sub") then
Line 417: Line 396:
target = target
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
end
end
Line 510: Line 491:
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 571: Line 551:
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 577: Line 556:
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 755: Line 733:
if type(data) ~= "table" then
if type(data) ~= "table" then
error("The first argument to the function language_link must be a table. See Module:links/documentation for more information.")
error("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 781: Line 757:
if type(data) ~= "table" then
if type(data) ~= "table" then
error("The first argument to the function plain_link must be a table. See Module:links/documentation for more information.")
error("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 802: Line 776:
if type(data) ~= "table" then
if type(data) ~= "table" then
error("The first argument to the function embedded_language_links must be a table. See Module:links/documentation for more information.")
error("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 832: Line 804:
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,124: Line 1,091:
* If <code class="n">show_qualifiers</code> is specified or the `show_qualifiers` field is set, left and right qualifiers, accent qualifiers, labels and references will be displayed, otherwise they will be ignored. (This is because a fair amount of code stores qualifiers, labels and/or references in these fields and displays them itself, rather than expecting {{code|lua|full_link()}} to display them.)]==]
* If <code class="n">show_qualifiers</code> is specified or the `show_qualifiers` field is set, left and right qualifiers, accent qualifiers, labels and references will be displayed, otherwise they will be ignored. (This is because a fair amount of code stores qualifiers, labels and/or references in these fields and displays them itself, rather than expecting {{code|lua|full_link()}} to display them.)]==]
function export.full_link(data, face, allow_self_link, show_qualifiers)
function export.full_link(data, face, allow_self_link, show_qualifiers)
if data.cats ~= nil then
track("cats")
end
-- Prevent data from being destructively modified.
-- Prevent data from being destructively modified.
local data = shallow_copy(data)
local data = shallow_copy(data)
Line 1,133: Line 1,097:
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,190: Line 1,152:
if not data.sc[i] then
if not data.sc[i] then
data.sc[i] = best
data.sc[i] = best
-- Track uses of sc parameter.
elseif data.track_sc then
if data.sc[i]:getCode() == best:getCode() then
insert(cats, lang:getFullName() .. " terms with redundant script codes")
else
insert(cats, lang:getFullName() .. " terms with non-redundant manual script codes")
end
end
end


Line 1,264: Line 1,219:
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,283: Line 1,237:
if (export.remove_links(manual_tr) == export.remove_links(automated_tr)) and (not data.tr_fail) then
if (export.remove_links(manual_tr) == export.remove_links(automated_tr)) and (not data.tr_fail) then
insert(cats, lang:getFullName() .. " terms with redundant transliterations")
insert(cats, lang:getFullName() .. " terms with redundant transliterations")
elseif not data.tr_fail then
-- Prevents Arabic root categories from flooding the tracking categories.
if NAMESPACE ~= 14 then -- Category:
insert(cats, lang:getFullName() .. " terms with non-redundant manual transliterations")
end
end
end
end
end
Line 1,388: Line 1,337:
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