Changes
split out the namespace-detecting part of formatLink to a new function
-- Helper functions
--------------------------------------------------------------------------------
local function findNamespaceId(link)
-- Finds the namespace id (namespace number) of a link or a pagename. This
-- function will not work if the link is enclosed in double brackets or if
-- the link has been escaped with the colon trick.
local namespace = link:match('^(.-):')
if namespace then
local nsTable = mw.site.namespaces[namespace]
if nsTable then
return nsTable.id
end
end
return 0
end
local function formatLink(link, display)
-- colon trick for categories and files, as otherwise category links
-- categorise the page and file links display the file.
local namespace = findNamespaceId(link:match('^(.-):')
local colon
if namespace and mw.site.namespaces[namespace] then -- The start of the link is a valid namespace name; check whether it is -- a category or a file. local nsid = mw.site.namespaces[namespace].id if nsid == 6 or nsid namespace == 14 then colon = ':' else endcolon = ''
end
-- Find the display value.