Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
factor out some of the main code to a shared function
>Mr. Stradivarius (format p._main to accept a list of page/display tables as input) |
>Mr. Stradivarius (factor out some of the main code to a shared function) |
||
Line 93: | Line 93: | ||
return ret | return ret | ||
end | end | ||
local function formatPageTables(pages) | |||
-- Takes a list of page/display tables and returns it as a list of | |||
-- formatted links. Nil values are not allowed. | |||
local links = {} | |||
for i, t in ipairs(pages) do | |||
local link = t[1] | |||
local display = t[2] | |||
links[i] = formatLink(link, display) | |||
end | |||
return links | |||
end | |||
local function makeWikitextError(msg) | local function makeWikitextError(msg) | ||
Line 225: | Line 236: | ||
firstPageTable = {firstPage} | firstPageTable = {firstPage} | ||
pages[1] = firstPageTable | pages[1] = firstPageTable | ||
end | end | ||
Line 238: | Line 241: | ||
local firstPageNs = findNamespaceId(firstPage) | local firstPageNs = findNamespaceId(firstPage) | ||
local pagetype = firstPageNs == 0 and 'article' or 'page' | local pagetype = firstPageNs == 0 and 'article' or 'page' | ||
-- Make the formatted link text | |||
local links = formatPageTables(pages) | |||
links = mw.text.listToText(links) | |||
-- Build the text. | -- Build the text. | ||
local isPlural = # | local isPlural = #pages > 1 | ||
local currentNs = currentTitle.namespace | local currentNs = currentTitle.namespace | ||
local isCategoryNamespace = currentNs - currentNs % 2 == 14 | local isCategoryNamespace = currentNs - currentNs % 2 == 14 | ||
local stringToFormat | local stringToFormat | ||
if isCategoryNamespace then | if isCategoryNamespace then |