Module:Hatnote: Difference between revisions

120 bytes added ,  10 years ago
prevent categories escaped with the colon trick being displayed as "article"
m>Mr. Stradivarius
(fix colon-removing pattern)
m>Mr. Stradivarius
(prevent categories escaped with the colon trick being displayed as "article")
Line 36: Line 36:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local function findNamespaceId(link)
local function findNamespaceId(link, removeColon)
-- Finds the namespace id (namespace number) of a link or a pagename. This
-- 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
-- function will not work if the link is enclosed in double brackets. If the
-- the link has been escaped with the colon trick.
-- removeColon parameter is set to true, the function will remove initial
-- colons from the link.
if removeColon then
link = link:match('^:?(.*)')
end
local namespace = link:match('^(.-):')
local namespace = link:match('^(.-):')
if namespace then
if namespace then
Line 59: Line 63:
-- colon trick for categories and files, as otherwise category links
-- colon trick for categories and files, as otherwise category links
-- categorise the page and file links display the file.
-- categorise the page and file links display the file.
link = link:match('^:(.*)') or link -- Remove initial colon if specified.
link = link:match('^:?(.*)') -- Remove initial colon if specified.
local namespace = findNamespaceId(link)
local namespace = findNamespaceId(link)
local colon
local colon
Line 240: Line 244:


-- Find the pagetype.
-- Find the pagetype.
local firstPageNs = findNamespaceId(firstPage)
local firstPageNs = findNamespaceId(firstPage, true)
local pagetype = firstPageNs == 0 and 'article' or 'page'
local pagetype = firstPageNs == 0 and 'article' or 'page'


Anonymous user