Module:Interwiki extra/data
Appearance
-- This module processes data from mw.site.interwikiMap for use with
-- [[Module:Interwiki]]. By loading the data with mw.loadData we ensure that
-- this is only done once per page parse.
local prefixes, urls, hosts = {}, {}, {}
local function makeCountedData(t, storeKey, counterKey, itemKey, item)
t = t or {}
t[storeKey] = t[storeKey] or {}
t[storeKey][itemKey] = item
t[counterKey] = t[counterKey] and t[counterKey] + 1 or 1
return t
end
for prefix, data in pairs(mw.site.interwikiMap()) do
local prefixData = {}
for k, v in pairs(data) do
prefixData[k] = v
end
local urlText = prefixData.url
local urlObj = mw.uri.new(urlText)
prefixData.url = urlObj
prefixes[prefix] = prefixData
local urlData = makeCountedData(
urls[urlText],
'prefixes',
'nPrefixes',
prefix,
prefixData
)
urlData.url = urlObj
urls[urlText] = urlData
end
for urlText, urlData in pairs(urls) do
local host = urlData.url.host
if host then
local hostData = makeCountedData(
hosts[host],
'urls',
'nUrls',
urlText,
urlData
)
hostData.host = host
hosts[host] = hostData
end
end
return {
prefixes = prefixes,
urls = urls,
hosts = hosts
}