Jump to content

Module:Pp-meta

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Pp-meta/doc

local z = {
    wikitext = require "Module:Wikitext"
}
local padlocks = { full="", semi = "-silver", move = "-olive", indef = "-red", office = "-black", create = "-skyblue" }
local categories = {
    ["0"] = "Wikipedia indefinitely semi-protected pages",
    ["3"] = "Wikipedia semi-protected user pages",
    ["4"] = "Wikipedia semi-protected user talk pages",
    ["6"] = "Semi-protected images",
    ["10"] = "Wikipedia semi-protected templates",
    ["12"] = "Semi-protected project pages",
    ["100"] = "Semi-protected portals"
}

function process(level, namespace, pagename, expiry, reason)
    if ( nil == level or "" == level ) then return "" end
    if ("autoconfirmed" == level) then level = "semi" end
    local categoryname = categories[tostring(namespace)]
    local category
    if ( nil ~= categoryname ) then
        category = "[[Category:" .. categoryname .. "|" .. pagename .. "]]"
    else
        category = ""
    end
    local colour = padlocks[level]
    local Padlock = "Padlock" .. (colour or "-green") .. ".svg"
    if ( nil ~= expiry ) then expiry = " until " .. expiry else expiry = "" end
    reason = reason or ""
    local message = "This page is " .. level .. "protected" .. expiry .. "."  .. reason
    local icon = "[[File:" .. Padlock .. "|20px|alt=Page " .. level .. "protected|link=Wikipedia:Protection policy#" .. level .. "|" .. message .. "]]" .. category
    return z.wikitext.mw.text.tag({name="div",params={class="metadata topicon",id="protected-icon",style="display:none; right:55px;"},contents=icon})
end

-- This is used by {{pp-meta}}
function z.main(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 namespace = config.namespace
    local pagename = config.pagename
    local expiry = args.expiry
    local reason = args.reason
    
    local EditText = process(config["level-edit"], namespace, pagename, expiry, reason)
    local MoveText = process(config["level-move"], namespace, pagename, expiry, reason)
    local CreateText = process(config["level-create"], namespace, pagename, expiry, reason)
    return EditText .. MoveText .. CreateText
end

return z