Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(fix colon-removing pattern) |
(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 |
-- function will not work if the link is enclosed in double brackets. If the |
||
-- removeColon parameter is set to true, the function will remove initial |
|||
-- the link has been escaped with the colon trick. |
|||
-- 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('^:(.*)') |
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' |
||