Module:Interwiki extra/data explained

-- This module processes data from mw.site.interwikiMap for use with-- . 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 tend

for prefix, data in pairs(mw.site.interwikiMap) do local prefixData = for k, v in pairs(data) do prefixData[k] = v end prefixes[prefix] = prefixData

local urlData = makeCountedData(urls[urlText], 'prefixes', 'nPrefixes', prefix, prefixData ) urlData.url = prefixData.url urls[urlData.url] = urlDataend

for url, urlData in pairs(urls) do local urlObj = mw.uri.new(url) -- We can't output URI objects as they have metatables if not urlObj or not urlObj.host then error(string.format("could not find a host in URL '%s'; " .. "please check your wiki's interwiki data", tostring(url) )) end local hostData = makeCountedData(hosts[urlObj.host], 'urls', 'nUrls', url, urlData ) hostData.host = urlObj.host hosts[urlObj.host] = hostDataend

return