Module:links: Difference between revisions
No edit summary |
Tag: Undo |
||
| (6 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 form_of_module = "Module:form of" | local form_of_module = "Module:form of" | ||
local gender_and_number_module = "Module: | 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 | 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 | 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) | ||
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 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 | ||
end | end | ||
| Line 344: | Line 321: | ||
if target:sub(1, 1) == ":" then | if target:sub(1, 1) == ":" then | ||
local link_target = target:sub(2) | |||
link_target = (lang:hasType("conlang") and "Contionary:" or "wikt:") .. link_target | |||
return | return link_target, orig_target | ||
end | end | ||
| Line 380: | Line 357: | ||
end | end | ||
end | end | ||
target, escaped = target:gsub("^(\\-)\\%*", "%1*") | target, escaped = target:gsub("^(\\-)\\%%*", "%1*") | ||
if reconstructed == 0 and lang:hasType("reconstructed") 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 386: | ||
-- 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 | |||
end | end | ||
else | else | ||
target = target | if reconstructed == 1 then | ||
target = "*" .. target | |||
end | |||
end | end | ||
target = (lang:hasType("conlang") and "Contionary:" or "wikt:") .. target | |||
return target, orig_target, escaped > 0 | return target, orig_target, escaped > 0 | ||
| Line 468: | Line 456: | ||
-- 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 476: | Line 463: | ||
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 514: | Line 498: | ||
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 576: | Line 559: | ||
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 582: | Line 564: | ||
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 761: | Line 742: | ||
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.") | ||
end | end | ||
| Line 788: | Line 767: | ||
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.") | ||
end | end | ||
| Line 810: | Line 787: | ||
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.") | ||
end | end | ||
| Line 840: | Line 815: | ||
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,195: | Line 1,165: | ||
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,339: | Line 1,307: | ||
if data.tr[1] then | if data.tr[1] then | ||
local full_code = lang:getFullCode() | local full_code = lang:getFullCode() | ||
end | end | ||
| Line 1,461: | Line 1,428: | ||
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 | ||