Module:Domain handler
local p = {}
function p.getTopLevelDomain(frame)
local args = frame.args
local domain = args.domain or args[1]
local context = args.context or "domains"
if domain and domain ~= "" then
domain = mw.text.trim(domain):lower()
domain = "." .. domain:gsub("^%.", "")
local category = "Category:Redirects from " .. domain ..
(context == "domains" and " domain names" or " URLs")
if mw.title.new(category).exists then
return " " .. domain
end
end
local currentTitle = mw.title.getCurrentTitle().text
currentTitle = currentTitle:lower():gsub("^https?://", "")
currentTitle = currentTitle:match("^([^/]+)") or currentTitle
local topLevelDomain = currentTitle:match("(%.[^.]+)$")
if topLevelDomain then
local category = "Category:Redirects from " .. topLevelDomain ..
(context == "domains" and " domain names" or " URLs")
if mw.title.new(category).exists then
return " " .. topLevelDomain
end
end
return ""
end
function p.adjustTitleCapitalization(frame)
local title = mw.title.getCurrentTitle().text
local lowercaseParameter = (frame.args.lowercase or ""):lower()
if lowercaseParameter == "yes" then
return title:sub(1,1):lower() .. title:sub(2)
end
if lowercaseParameter == "no" then
return title
end
return title:sub(2):find("%u") and title or title:sub(1,1):lower() .. title:sub(2)
end
return p