Module:Editnotice

提供: VANGUARD FLIGHT wiki
移動先: 案内検索
This module is intended to deal with conditions when editnotices should be shown.
--[[  
 
This module is intended to deal with conditions when editnotices should be shown
]]

local ep = {}

--[[
canCreateInNS
 
This function returns true if anonymous users can create a page.
 
Usage:
{{#invoke:Editnotice|canCreateInNS|namespacenumber|pagename}}
OR
{{#invoke:Editnotice|canCreateInNS|NS=namespacenumber|pagename=pagename}}
 
Parameters
    namespacenumber: The namespacenumber the page should be created on.
    pagename: The name of the page that should be created.
 
Example
   {{#invoke:Editnotice|canCreateInNS|NS={{NAMESPACENUMBER}}|pagename={{PAGENAME}}}}
]]

-- please confer to [[Special:AbuseFilter/105]]
local allowednamespaces = {}
allowednamespaces[4]={'^Deletion requests/', '^Categories for discussion/'}
allowednamespaces[14]={}
allowednamespaces[102]={}

function ep.canCreateInNS( frame )
    local ns = tonumber(frame.args.NS or frame.args[1])
    local pagename = frame.args.pagename or frame.args[2]
    local nsinfo = allowednamespaces[ns]
    local nsinfofilled = nsinfo or {}
    local isPageGroupCreatable = false
    local can = true

    if #nsinfofilled == 0 then
        isPageGroupCreatable = true
    else
        for k, v in pairs( nsinfofilled ) do
            isPageGroupCreatable = isPageGroupCreatable or not not pagename:match(v)
        end
    end

    can = (not not nsinfo or ns % 2 > 0) and isPageGroupCreatable
    return can
end

return ep