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:Top icon







Add links
 









Module
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
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 Outreach
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


-- This module implements {{top icon}}

local categoryHandler = require( 'Module:Category handler' ).main

local p = {}

local function makeName(sort, body)
 local sortnum = tonumber(sort)
 if sortnum then
  -- Zero-pad numbers so that they will sort properly in alphabetical
  -- order. (Yes, there really are decimal sort keys used on enwiki.)
  sort = string.format('%07.2f', sortnum)
 end
 math.randomseed(os.clock() * 1000000000)
 local ret = {}
 ret[#ret + 1] = sort
 -- There should always be a body value present. This will force numeric
 -- sort keys to sort alphabetically.
 ret[#ret + 1] = body
 -- Add a random number to stop names from duplicating others on a page
 ret[#ret + 1] = math.random(1, 100000)
 return table.concat(ret, '-')
end

local function makeFileLink(t)
 local ret = {}
 ret[#ret + 1] = '[[File:'
 ret[#ret + 1] = t.image
 ret[#ret + 1] = '|'
 ret[#ret + 1] = t.width or 20
 ret[#ret + 1] = 'x'
 ret[#ret + 1] = t.height or 20
 ret[#ret + 1] = 'px'
 if t.link then
  ret[#ret + 1] = '|link='
  ret[#ret + 1] = t.link
 end
 if t.alt then
  ret[#ret + 1] = '|alt='
  ret[#ret + 1] = t.alt
 end
 if t.text then
  ret[#ret + 1] = '|'
  ret[#ret + 1] = t.text
 end
 ret[#ret + 1] = ']]'
 return table.concat(ret)
end

local function renderCategories(args, title)
 local categories = categoryHandler{
  user = args.usercat,
  main = args.maincat,
  subpage = args.subpage or 'no',
  nocat = args.nocat,
  page = title.prefixedText
 }
 return categories or ''
end

function p._main(args, frame, title)
 frame = frame or mw.getCurrentFrame()
 title = title or mw.title.getCurrentTitle()
 local image = args.image or args.imagename
 if not image then
  error('no image name specified', 2)
 end
 local name = makeName(
  args.icon_nr or args.number,
  args.name or args.id or image
 )
 local fileLink = makeFileLink{
  image = image,
  width = args.width,
  height = args.height,
  link = args.link or args.wikilink,
  alt = args.alt,
  text = args.text or args.description
 }
 local nowiki = frame:extensionTag{name = 'nowiki'}
 local indicator = frame:extensionTag{
  name = 'indicator',
  args = {name = name},
  content = fileLink
 }
 local categories = renderCategories(args, title)
 return nowiki .. indicator .. categories
end

function p.main(frame)
 local origArgs = require('Module:Arguments').getArgs(frame, {
  parentOnly = true
 })
 -- Copy all the specified arguments over to minimise the number of times we
 -- have to access the frame object.
 local args = {}
 for k, v in pairs(origArgs) do
  args[k] = v
 end
 return p._main(args, frame)
end

return p

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





This page was last edited on 1 April 2015, at 14:55 (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