Module:links: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(38 intermediate revisions by the same user not shown)
Line 12: Line 12:
[[Module:utilities]]
[[Module:utilities]]
[[Module:string]]
[[Module:string]]
[[Module:debug]]
]=]
]=]


Line 64: Line 63:
if target:sub(1, 1) == "/" then
if target:sub(1, 1) == "/" then
return ":" .. target
return ":" .. target
-- Link to appendix for reconstructed terms and terms in appendix-only languages
elseif target:sub(1, 1) == "*" and #target > 1 then
if lang:getCode() == "und" then
return nil
end
target = "Reconstruction:" .. lang:getCanonicalName() .. "/" .. usub(target, 2)
elseif lang:getType() == "reconstructed" then
error("The specified language " .. lang:getCanonicalName()
.. " is unattested, while the given word is not marked with '*' to indicate that it is reconstructed")
elseif lang:getType() == "appendix-constructed" then
target = "Appendix:" .. lang:getCanonicalName() .. "/" .. target
end
end


Line 89: Line 75:
or langCode:find("^sj[dektu]$") then
or langCode:find("^sj[dektu]$") then
if link.display and link.display:find("'") then
if link.display and link.display:find("'") then
require("Module:debug").track("links/Sami apostrophe display")
elseif link.target and link.target:find("'") then
elseif link.target and link.target:find("'") then
require("Module:debug").track("links/Sami apostrophe target")
end
end
end
end
Line 129: Line 113:
end
end
end
end
 
-- Process the target
-- Process the target
link.target = link.nocont and link.target:gsub("^%*", "Reconstruction:" .. lang:getCanonicalName() .. "/") or link.target
link.target = export.getLinkPage(link.target, lang)
link.target = export.getLinkPage(link.target, lang)


Line 159: Line 144:


if not prefixes[prefix] then
if not prefixes[prefix] then
if link.fragment or link.target:find("#$") then
require("Module:debug").track {
"links/fragment",
"links/fragment/" .. lang:getCode()
}
end


if not link.fragment and lang:getCode() ~= "und" then
if not link.fragment and lang:getCode() ~= "und" then
Line 179: Line 158:
end
end


return "[[" .. link.target .. (link.fragment and "#" .. link.fragment or "") .. "|" .. link.display .. "]]"
return "[[" .. (link.nocont and "wikt:" or "Contionary:") .. link.target .. "#" .. lang:getCanonicalName() .. "|" .. link.display .. "]]"
end
end


Line 226: Line 205:
local allReconstructed = false
local allReconstructed = false


if find(text, "^*.") then
if text:find("^*.") then
allReconstructed = true
allReconstructed = true
end
end


-- Do we have embedded wikilinks?
-- Do we have embedded wikilinks?
if find(text, "[[", nil, true) then
if text:find("[[", nil, true) then
--[=[
[[Special:WhatLinksHere/Template:tracking/links/alt-ignored]]
[[Special:WhatLinksHere/Template:tracking/links/id-ignored]]
]=]


if data.alt then
if data.alt then
require("Module:debug").track("links/alt-ignored")
mw.log("(from Module:links)", "text with embedded wikilinks:", text,
mw.log("(from Module:links)", "text with embedded wikilinks:", text,
"ignored alt:", data.alt, "lang:", data.lang:getCode())
"ignored alt:", data.alt, "lang:", data.lang:getCode())
Line 244: Line 218:


if data.id then
if data.id then
require("Module:debug").track("links/id-ignored")
mw.log("(from Module:links)", "text with embedded wikilinks:", text,
mw.log("(from Module:links)", "text with embedded wikilinks:", text,
"ignored id:", data.id, "lang:", data.lang:getCode())
"ignored id:", data.id, "lang:", data.lang:getCode())
Line 250: Line 223:


-- Begins and ends with a wikilink tag
-- Begins and ends with a wikilink tag
if find(text, "^%[%[(.+)%]%]$") then
if text:find("^%[%[(.+)%]%]$") then
-- There are no [ ] in between.
-- There are no [ ] in between.
-- This makes the wikilink tag redundant.
-- This makes the wikilink tag redundant.
if find(text, "^%[%[[^%[%]]+%]%]$") then
if text:find("^%[%[[^%[%]]+%]%]$") then
require("Module:debug").track("links/redundant wikilink")
else
else
local temp = text:gsub("^%[%[(.+)%]%]$", "%1")
local temp = text:gsub("^%[%[(.+)%]%]$", "%1")
temp = temp:gsub("%]%], %[%[", "|")
temp = temp:gsub("%]%], %[%[", "|")
if not temp:find("[%[%]]") then
require("Module:debug").track("links/list")
end
end
end
end
end
Line 283: Line 251:
else
else
-- There is no embedded wikilink, make a link using the parameters.
-- There is no embedded wikilink, make a link using the parameters.
text = makeLangLink({ target = text, display = data.alt }, data.lang, data.id, allow_self_link)
text = makeLangLink({ target = text, display = data.alt, nocont = data.nocont}, data.lang, data.id, allow_self_link)
end
end


Line 333: Line 301:


if data.genders and #data.genders > 0 then
if data.genders and #data.genders > 0 then
local m_gen = require("Module:gender and number")
local m_gen = require("Module:getn")
table_insert(output, " " .. m_gen.format_list(data.genders, data.lang))
table_insert(output, " " .. m_gen.format_list(data.genders, data.lang))
end
end
Line 403: Line 371:


-- Is there any text to show?
-- Is there any text to show?
if (data.term or data.alt) then
if (data.term or data.alt) and data.term ~= "-" then
-- Try to detect the script if it was not provided
-- Try to detect the script if it was not provided
if not data.sc then
if not data.sc then
Line 410: Line 378:
-- Track uses of sc parameter
-- Track uses of sc parameter
local best = require("Module:scripts").findBestScript(data.alt or data.term, data.lang)
local best = require("Module:scripts").findBestScript(data.alt or data.term, data.lang)
require("Module:debug").track("links/sc")
if data.sc:getCode() == best:getCode() then
require("Module:debug").track("links/sc/redundant")
require("Module:debug").track("links/sc/redundant/" .. data.sc:getCode())
else
require("Module:debug").track("links/sc/needed")
require("Module:debug").track("links/sc/needed/" .. data.sc:getCode())
end
end
end


Line 457: Line 416:
Is there at least a transliteration we can work from? ]]
Is there at least a transliteration we can work from? ]]
link = require("Module:script utilities").request_script(data.lang, data.sc)
link = require("Module:script utilities").request_script(data.lang, data.sc)
 
if link == "" or not data.tr or data.tr == "-" then
if not data.sc then
data.sc = require("Module:scripts").findBestScript(data.alt or data.term, data.lang)
else
-- Track uses of sc parameter
local best = require("Module:scripts").findBestScript(data.alt or data.term, data.lang)
end
if link == "" or link == "-" or link == "?" or not data.tr or data.tr == "-" then
-- No link to show, and no transliteration either. Show a term request.
-- No link to show, and no transliteration either. Show a term request.
local category = ""
local category = ""
Line 486: Line 452:
-- is tight. `no_check_redundant_translit` is currently set when called ultimately from
-- is tight. `no_check_redundant_translit` is currently set when called ultimately from
-- {{multitrans|...|no-check-redundant-translit=1}}.)
-- {{multitrans|...|no-check-redundant-translit=1}}.)
if not (data.tr and (
if not data.tr then
no_check_redundant_translit or
mw.loadData("Module:links/data").high_memory_entries[mw.title.getCurrentTitle().text]
)) then
local automated_tr = data.lang:transliterate(export.remove_links(data.alt or data.term), data.sc)
local automated_tr = data.lang:transliterate(export.remove_links(data.alt or data.term), data.sc)


Line 519: Line 482:
-- Link to the transliteration entry for languages that require this
-- Link to the transliteration entry for languages that require this
if data.tr and data.lang:link_tr() then
if data.tr and data.lang:link_tr() then
data.tr = export.language_link { lang = data.lang, term = data.tr }
data.tr = require("Module:script utilities").tag_text(
export.language_link({ lang = data.lang, term = data.tr, nocont = data.nocont}, allow_self_link),
data.lang, data.sc, face, class)
--data.tr = export.language_link { lang = data.lang, term = data.tr, nocont = data.nocont}
elseif data.tr then
data.tr = "''" .. data.tr .. "''"
end
end


Line 526: Line 494:
return table_concat(output) .. table_concat(categories)
return table_concat(output) .. table_concat(categories)
end
end


--[[ Strips links: deletes category links,
--[[ Strips links: deletes category links,