Module:Hatnote: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(update main function description) |
(format p._main to accept a list of page/display tables as input) |
||
Line 202: | Line 202: | ||
-- Produces a link to a main article or articles. If used in category or |
-- 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". |
-- category talk space, produces "The main article for this category is xxx". |
||
-- Otherwise, produces "Main article: xxx". Accepts |
-- Otherwise, produces "Main article: xxx". Accepts an unlimited number 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 |
|||
-- |
-- value in the table should be the page name. Omitting this will result in an |
||
-- 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( |
function p._main(...) |
||
-- Get the list of pages. If no first page was specified we use the current |
|||
-- Initialize variables. |
|||
-- page name. |
|||
⚫ | |||
local pages = {...} |
|||
local currentTitle = mw.title.getCurrentTitle() |
local currentTitle = mw.title.getCurrentTitle() |
||
local firstPageTable = pages[1] |
|||
⚫ | |||
⚫ | |||
if firstPageTable then |
|||
local nums = mTableTools.numKeys(args) |
|||
⚫ | |||
if nums[1] then |
|||
⚫ | |||
links = {} |
|||
else |
else |
||
firstPage = currentTitle.text |
firstPage = currentTitle.text |
||
firstPageTable = {firstPage} |
|||
pages[1] = firstPageTable |
|||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
local links = {} |
|||
⚫ | |||
⚫ | |||
local display = t[2] |
|||
links[#links + 1] = formatLink(link, display) |
links[#links + 1] = formatLink(link, display) |
||
end |
end |
||
Line 261: | Line 267: | ||
end |
end |
||
function f.main(args) |
|||
⚫ | |||
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 |
return p |