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
 

















Module:Pagelist






Аԥсшәа
العربية
تۆرکجه
Basa Bali

Беларуская (тарашкевіца)

Bosanski
Català
Cymraeg
Dansk
Ελληνικά
فارسی
Føroyskt
Galego

  / Gõychi Konknni

Հայերեն
Bahasa Indonesia
Jawa

Latviešu
ि


مصرى
Bahasa Melayu


Norsk bokmål
Oʻzbekcha / ўзбекча


Português
Română
Sakizaya
Scots
Simple English
Slovenščina
Soomaaliga
کوردی
Српски / srpski
Tagalog
Taqbaylit
 

Тоҷикӣ
Türkçe
Українська
اردو
Tiếng Vit


 

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
 




In other projects  



Wikimedia Commons
MediaWiki
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 


This is a Lua implementation of {{pagelist}}. Please see the template page for documentation.

local p = {}

local separators = {
 dot = true,
 pipe = true,
 comma = true,
 ['tpt-languages'] = true
}

local function getSeparator(sep)
 if type(sep) ~= 'string' then
  return nil
 end
 if separators[sep] then
  return mw.message.new(sep .. '-separator'):plain()
 else
  return sep
 end
end

local function generateLink(page, nspace, delim, endDelim)
 if not page then
  return nil
 end
 local pagename = mw.title.new(page)
 if not pagename then
  -- Default to the args we were passed if our page
  -- object was nil.
  pagename = page
 else
  pagename = pagename.text
 end
 delim = delim or ''
 endDelim = endDelim or delim
 nspace = nspace or ''
 if nspace == 'all' then
  nspace = ''
  pagename = page
 end
 local outStr = mw.ustring.gsub( 
  string.format( 
   '%s[[:%s:%s|%s]]%s',
   delim, nspace, pagename, page, endDelim
  ),
   ':+',
   ':' 
 )
 return outStr
end

function p._main(args)
 local t = {}
 local separator = getSeparator(args.separator)
 local conjunction = getSeparator(args.conjunction)
 for i, v in ipairs(args) do
  table.insert(t, generateLink(
   v, args.nspace, args.delim, args.edelim
  ))
 end
 return mw.text.listToText(t, separator, conjunction)
end

function p.main(frame)
 local origArgs = require('Module:Arguments').getArgs(frame, {
  trim = false,
  removeBlanks = false,
  wrappers = 'Template:Pagelist'
 })

 -- Process integer args. Allow for explicit positional arguments that are
 -- specified out of order, e.g. {{br separated entries|3=entry3}}.
 -- After processing, the args can be accessed accurately from ipairs.
 local args = {}
 for k, v in pairs(origArgs) do
  if type(k) == 'number' and 
   k >= 1 and
   math.floor(k) == k and
   string.match(v, '%S') then -- Remove blank or whitespace values.
   table.insert(args, k)
  end
 end
 table.sort(args)
 for i, v in ipairs(args) do
  args[i] = origArgs[v]
  -- Trim whitespace.
  if type(args[i]) == 'string' then
   args[i] = mw.text.trim(args[i])
  end
 end

 -- Get old named args. We don't need to remove blank values
 -- as for the nspace and edelim parameters the behaviour is different
 -- depending on whether the parameters are blank or absent, and for
 -- the delim parameter the default should be the blank string anyway.
 args.delim = origArgs.delim
 args.edelim = origArgs.edelim
 args.nspace = origArgs.nspace

 -- Get new named args, "separator" and "conjunction", and strip blank values.
 if origArgs.separator and origArgs.separator ~= '' then
  args.separator = origArgs.separator
 end
 if origArgs.conjunction and origArgs.conjunction ~= '' then
  args.conjunction = origArgs.conjunction
 end

 return p._main(args)
end

return p

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

Category: 
Modules subject to page protection
Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 20 July 2017, at 22:11 (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