local p = local horizontal = require('Module:List').horizontal
local function makeWikitextError(msg) return string.format('Error: %s', msg)end
local function makeFullUrl(page, query, display) local url = mw.uri.fullUrl(page, query) if not url then url = makeWikitextError(string.format('"%s" is not a valid page name', tostring(page) )) end return string.format('[%s %s]', tostring(url), display )end
local function make_nomination_link(nominationPage) local currentPage = mw.title.getCurrentTitle.prefixedText local dykSubpage = 'Template:Did you know nominations/' .. nominationPage if currentPage
function p._main(nominationPage, historyPages) -- Deal with bad input. if not nominationPage then return makeWikitextError('no nomination page specified') end if not historyPages or not historyPages[1] then return makeWikitextError('no articles specified') end
-- Find out whether we are dealing with multiple history pages. local isMulti = #historyPages > 1
local nominationLink = make_nomination_link(nominationPage)
if isMulti then local list_args = for _, page in ipairs(historyPages) do table.insert(list_args, makeFullUrl(page, , page )) end local multi_root = mw.html.create('div') multi_root:addClass('dyk-nompage-links plainlinks') :wikitext(string.format('(%s)', nominationLink)) local list_root = mw.html.create('div') list_root:wikitext(string.format('(Article history links: %s)', horizontal(list_args) )) return tostring(multi_root:node(list_root)) else local historyLink = makeFullUrl(historyPages[1], , 'Article history' ) local single_root = mw.html.create('div') single_root:addClass('dyk-nompage-links plainlinks') :wikitext(string.format('(%s)', horizontal )) return tostring(single_root) endend
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) local nominationPage = args.nompage local historyPages = require('Module:TableTools').compressSparseArray(args) return p._main(nominationPage, historyPages)end
return p