This module generates a link to an unsupported link, for use by Template:unsupported. See Module:unsupported titles/data to edit the list of unsupported titles. See also Appendix:Unsupported titles.
local export = {}
-- This function returns a link to an unsupported title.
-- text -> The 1st argument given to ], consisting of the unsupported title to format as a link. If the wanted page is "Unsupported titles/Low line", you can use "_", "low line", "underline", etc., provided the page is listed in ].
-- altText -> The 2nd argument given to ], consisting of the alternative text to be displayed, if applicable.
-- noError -> If true, it returns nil if the entry does not exist, instead of an error. This may be used to test if an entry exists as an unsupported title, because an error would need to be fixed, but a simple test may not need fixing.
-- onlyActualPageTitle -> If true, the module only accepts the actual page title, and not any of the aliases. For example, the module would only accept "_", and not "low line", "underscore" or "underline". This may be used to test if an entry exists as an unsupported title, so for example "underscore" would not be recognized as an unsupported title.
function export.parse(text, altText, noError, onlyActualPageTitle)
-- allTitles -> a list of all unsupported titles, located at "Module:unsupported titles/data".
local allTitles = mw.loadData("Module:unsupported titles/data")
-- englishObject -> the English language object, to be used later for the "ucfirst" function.
local englishObject = mw.language.new("en")
-- The code below parses a text like this, in the "allTitles" argument from "Module:unsupported titles/data":
-- m = {display=".", "period",}
-- The "display" value is optional, but if it exists, this is the displayed text.
for k, v in pairs(allTitles) do
local pagename = text
if v then pagename = englishObject:ucfirst(v) end
-- First, check the table keys for page names.
if text == k then
return " or k) .. "]]"
end
-- Second, check the table values for page names. This is ignored if onlyActualPageTitle is true.
if onlyActualPageTitle ~= true then
for l, m in pairs(v) do
if text == m then
return " or k) .. "]]"
end
end
end
end
if noError == true then
return null
else
error ("Unable to recognize the first template argument as an unsupported page title.")
end
end
function export.link(frame)
local text = frame:getParent().args
local altText = frame:getParent().args
local noError = frame:getParent().args
return export.parse(text, altText, noError)
end
return export