Anonymous user
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
-- page/display tables. Non-table inputs will result in an error. The first
--
-- error, except in the case of the first table, which uses the page name as a
-- fallaback. The second value in the table is an optional display value for
-- 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(
-- Get the list of pages. If no first page was specified we use the current
-- page name.
local links, firstPage▼
local pages = {...}
local currentTitle = mw.title.getCurrentTitle()
local firstPageTable = pages[1]
-- Make the list of formatted links and find the link for the first page.▼
if firstPageTable then
▲ firstPage = args[nums[1]]
else
firstPage = currentTitle.text
pages[1] = firstPageTable
end
for i, num in ipairs(nums) do▼
local link = args[num]▼
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
return p
|