Module:links: Difference between revisions
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 11: | Line 11: | ||
[[Module:languages]] and its submodules | [[Module:languages]] and its submodules | ||
[[Module:gender and number]] | [[Module:gender and number]] | ||
]=] | ]=] | ||
local anchors_module = "Module:anchors" | local anchors_module = "Module:anchors" | ||
local gender_and_number_module = "Module:getn" | |||
local gender_and_number_module = "Module: | |||
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 | 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 | 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) | ||
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 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 | ||
end | end | ||
| Line 343: | Line 320: | ||
if target:sub(1, 1) == ":" then | if target:sub(1, 1) == ":" then | ||
-- 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 361: | Line 337: | ||
end | end | ||
end | end | ||
-- Check if the term is reconstructed and remove any asterisk. Also check for anti-asterisk (!!). | -- Check if the term is reconstructed and remove any asterisk. Also check for anti-asterisk (!!). | ||
-- Otherwise, handle the escapes. | -- Otherwise, handle the escapes. | ||
| Line 378: | Line 354: | ||
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 | ||
| Line 401: | Line 382: | ||
-- 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:hasType("appendix-constructed") then | |||
target = "wikt:Appendix:" .. lang:getFullName() .. "/" .. target | |||
elseif reconstructed == 1 then -- asterisk found | |||
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 | |||
else | |||
target = target | |||
end | end | ||
else | else | ||
target = target | target = "Contionary:" .. target | ||
end | end | ||
return target, orig_target, escaped > 0 | return target, orig_target, escaped > 0 | ||
end | end | ||
| Line 464: | Line 450: | ||
-- If `no_alt_ast` is true, use pcall to catch the error which will be thrown if this is a reconstructed lang and the alt text doesn't have *. | -- If `no_alt_ast` is true, use pcall to catch the error which will be thrown if this is a reconstructed lang and the alt text doesn't have *. | ||
if link.display == auto_display then | if link.display == auto_display then | ||
else | else | ||
local ok, check | local ok, check | ||
| Line 472: | Line 457: | ||
ok = true | ok = true | ||
check = export.get_link_page(orig_display, lang, sc, plain) | check = export.get_link_page(orig_display, lang, sc, plain) | ||
end | end | ||
end | end | ||
| Line 510: | Line 492: | ||
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 | ||
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 552: | ||
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 | ||
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 557: | ||
end | end | ||
if id then | if id then | ||
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 686: | Line 665: | ||
end | end | ||
term, alt = new_term, new_alt | term, alt = new_term, new_alt | ||
end | end | ||
end | end | ||
| Line 755: | Line 729: | ||
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.") | ||
end | end | ||
| Line 781: | Line 753: | ||
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.") | ||
end | end | ||
| Line 802: | Line 772: | ||
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.") | ||
end | end | ||
| Line 832: | Line 800: | ||
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>' } | ||
elseif item_type == "tr" then | elseif item_type == "tr" then | ||
if face == "term" then | if face == "term" then | ||
| Line 1,124: | Line 1,087: | ||
* 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) | ||
-- 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,093: | ||
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.") | ||
end | end | ||
| Line 1,190: | Line 1,148: | ||
if not data.sc[i] then | if not data.sc[i] then | ||
data.sc[i] = best | data.sc[i] = best | ||
end | end | ||
| Line 1,264: | Line 1,215: | ||
if data.tr[1] then | if data.tr[1] then | ||
local full_code = lang:getFullCode() | local full_code = lang:getFullCode() | ||
end | end | ||
| Line 1,279: | Line 1,229: | ||
if automated_tr or data.tr_fail then | if automated_tr or data.tr_fail then | ||
local manual_tr = data.tr[1] | local manual_tr = data.tr[1] | ||
if (not manual_tr) or lang:overrideManualTranslit(data.sc[1]) then | if (not manual_tr) or lang:overrideManualTranslit(data.sc[1]) then | ||
| Line 1,388: | Line 1,327: | ||
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.") | ||
end | end | ||