Jump to content

Module:Top icon

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Top icon/doc

local bodge = require "Module:mw"

local z = {}

local function topicon(args, config, data, categories)
    local pagename = config.pagename or ""
    local namespace = config.namespace or "0"
    local cat = categories[tostring(namespace)] or categories[1]
    if cat then cat = "[[Category:" .. cat .. "]]" else cat = "" end
    local number = data.number or data.icon_nr or 0
    local width = data.width or 15
    local offset = data.offset or data.extra_offset or 0
    local pixels = number * (12 + width + offset)
    local style = "display:none; right:" .. pixels .. "px; " .. (data.style or "")
    local class="metadata topicon nopopups " .. (data.class or "")
    local id = data.id
    local link = data.link or data.wikilink or ""
    local description = data.text or data.description or ""
    local alt = data.alt or ""
    local text = "[[File:" .. (data.image or data.imagename or "") .. "|" .. (args.width or "15") .. "px|link=" .. link .. "|alt=" .. alt .. "|" .. description .. "]]"
    return mw.text.tag({name="div",contents=text,params={class=class,style=style,id=id}}) .. cat
end

-- This is used by template {{good article}}.
function z.good(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself    
    local categories = { ["0"] = "Good articles" }
    local data = { imagename = "symbol support vote.svg", wikilink = "Wikipedia:Good articles", description = "This is a good article. Click here for more information.", id = "good-star", alt = "Good article star" }
    return topicon(args, config, data, categories)
end

-- This is used by template {{featured article}}.
function z.featured(frame)
    local pframe = frame:getParent()
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself    
    local categories = { ["0"] = "Featured articles" }
    local data = { imagename = "cscr-featured.svg", wikilink = "Wikipedia:Featured articles", description = "This is a featured article. Click here for more information.", id = "featured-star", alt = "Featured article star" }
    return topicon(args, config, data, categories)
end

return z