Module:Hatnote: Difference between revisions

199 bytes added ,  10 years ago
factor out some of the main code to a shared function
m>Mr. Stradivarius
(format p._main to accept a list of page/display tables as input)
m>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
-- Make the list of formatted links
local links = {}
for i, t in ipairs(pages) do
local link = t[1]
local display = t[2]
links[#links + 1] = formatLink(link, display)
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 = #links > 1
local isPlural = #pages > 1
local currentNs = currentTitle.namespace
local currentNs = currentTitle.namespace
local isCategoryNamespace = currentNs - currentNs % 2 == 14
local isCategoryNamespace = currentNs - currentNs % 2 == 14
links = mw.text.listToText(links)
local stringToFormat
local stringToFormat
if isCategoryNamespace then
if isCategoryNamespace then
Anonymous user