Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage from wikitext  





2 Usage from other Lua modules  














Module:DYK nompage links






تۆرکجه
فارسی
Français
اردو
 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


This module produces the list of links used on Wikipedia:Did you know nomination pages. It implements {{DYK nompage links}}.

Usage from wikitext

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.

Usage from other Lua modules

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').horizontal

local function makeWikitextError(msg)
 return string.format('<strong class="error">Error: %s</strong>', 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 == dykSubpage then
  return string.format(
   '[[Template talk:Did you know#%s|Back to T:TDYK]]',
   nominationPage
  )
 else
  return makeFullUrl(
   dykSubpage,
   {action = 'edit'},
   'Comment'
  ) .. string.format(" or [[%s|view]]",dykSubpage)
 end
end

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 = {
   class = 'inline',
  }
  for _, page in ipairs(historyPages) do
   table.insert(list_args, makeFullUrl(
    page,
    {action = 'history'},
    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],
   {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)
 end
end

function p.main(frame)
 local args = require('Module:Arguments').getArgs(frame, {
  wrappers = 'Template:DYK nompage links'
 })
 local nominationPage = args.nompage
 local historyPages = require('Module:TableTools').compressSparseArray(args)
 return p._main(nominationPage, historyPages)
end

return p

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:DYK_nompage_links&oldid=1207430325"

Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 14 February 2024, at 20:24 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki