Module:Hatnote: Difference between revisions

format p._main to accept a list of page/display tables as input
(update main function description)
(format p._main to accept a list of page/display tables as input)
Line 202:
-- Produces a link to a main article or articles. If used in category or
-- category talk space, produces "The main article for this category is xxx".
-- Otherwise, produces "Main article: xxx". Accepts aan tableunlimited ofnumber arguments.of
-- page/display tables. Non-table inputs will result in an error. The first
-- Numerical keys for this table are the page names. If the first page name is
-- notvalue in mainspace,the usestable "page"should insteadbe ofthe "article"page name. IfOmitting morethis thanwill oneresult pagein isan
-- error, except in the case of the first table, which uses the page name as a
-- specified, the function uses plural forms. Display names can be specified for
-- fallaback. The second value in the table is an optional display value for
-- each page name by using the arguments l1, l2, etc.
-- the link. If the first page name is not in mainspace, the output uses "page"
-- instead of "article". If more than one page is specified, the function uses
-- plural forms.
--------------------------------------------------------------------------------
 
function p._main(args...)
-- Get the list of pages. If no first page was specified we use the current
-- Initialize variables.
-- page name.
local links, firstPage
local pages = {...}
local currentTitle = mw.title.getCurrentTitle()
local firstPageTable = pages[1]
 
local links, firstPage
-- Make the list of formatted links and find the link for the first page.
if firstPageTable then
local nums = mTableTools.numKeys(args)
firstPage = args[numsfirstPageTable[1]]
if nums[1] then
firstPage = args[nums[1]]
links = {}
else
firstPage = currentTitle.text
linksfirstPageTable = {formatLink(firstPage)}
pages[1] = firstPageTable
end
 
for i, num in ipairs(nums) do
-- Make the list of formatted links and find the link for the first page.
local link = args[num]
local displaylinks = args['l' .. tostring(num)]{}
for i, numt in ipairs(numspages) do
local link = argst[num1]
local display = t[2]
links[#links + 1] = formatLink(link, display)
end
Line 261 ⟶ 267:
end
 
function f.main(args)
p.main = makeInvokeFunction(p._main)
local pages = {}
for k, v in pairs(args) do
if type(k) == 'number' then
local display = args['l' .. tostring(k)]
local page = {v, display}
pages[k] = page
end
end
pages = mTableTools.compressSparseArray(pages)
return p._main(unpack(pages))
end
 
p.main = makeInvokeFunction(pf._mainmain)
 
return p