This module produces the list of links used on Wikipedia:Did you know nomination pages. It implements {{DYK nompage links}}.
Usually, this module should be used via the {{DYK nompage links}} template. However, it can also be used with the syntax {{#invoke:DYK nompage links|main|arguments}}
. See Template:DYK nompage links for a list of arguments.
To use this module from other Lua modules, first load the module:
local mDYKlinks = require('Module:DYK nompage links')
You can then use the _main function like this:
mDYKlinks._main(nominationPage, historyPages)
nominationPage is the nomination page name, as a string. historyPages is an array of page names to display (also strings). Both parameters are required, and historyPages must have a length of at least one.
local p = {}local horizontal = require('Module:List').horizontallocal function makeWikitextError(msg)return string.format('<strong class="error">Error: %s</strong>', msg)endlocal function makeFullUrl(page, query, display)local url = mw.uri.fullUrl(page, query)if not url thenurl = makeWikitextError(string.format('"%s" is not a valid page name',tostring(page)))endreturn string.format('[%s %s]',tostring(url),display)endlocal function make_nomination_link(nominationPage)local currentPage = mw.title.getCurrentTitle().prefixedTextlocal dykSubpage = 'Template:Did you know nominations/' .. nominationPageif currentPage == dykSubpage thenreturn string.format('[[Template talk:Did you know#%s|Back to T:TDYK]]',nominationPage)elsereturn makeFullUrl(dykSubpage,{action = 'edit'},'Comment') .. string.format(" or [[%s|view]]",dykSubpage)endendfunction p._main(nominationPage, historyPages)-- Deal with bad input.if not nominationPage thenreturn makeWikitextError('no nomination page specified')endif not historyPages or not historyPages[1] thenreturn makeWikitextError('no articles specified')end-- Find out whether we are dealing with multiple history pages.local isMulti = #historyPages > 1local nominationLink = make_nomination_link(nominationPage)if isMulti thenlocal list_args = {class = 'inline',}for _, page in ipairs(historyPages) dotable.insert(list_args, makeFullUrl(page,{action = 'history'},page))endlocal 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))elselocal historyLink = makeFullUrl(historyPages[1],{action = 'history'},'Article history')local single_root = mw.html.create('div')single_root:addClass('dyk-nompage-links plainlinks'):wikitext(string.format('( %s )',horizontal({class = 'inline',nominationLink,historyLink})))return tostring(single_root)endendfunction p.main(frame)local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:DYK nompage links'})local nominationPage = args.nompagelocal historyPages = require('Module:TableTools').compressSparseArray(args)return p._main(nominationPage, historyPages)endreturn p