Module:Sandbox/Jackmcbarn: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
Jackmcbarn (talk | contribs)
use new module
Line 3:
local getPagetype = require('Module:Pagetype')._main
local makeMessageBox = require('Module:Message box').main
local effectiveProtectionLevel = require('Module:Effective protection level').main
 
----------------------------------------------------------------------
Line 34 ⟶ 35:
local success, obj = pcall(mw.title.new, ...)
if not (success and obj) then return end
 
local function getProtectionLevel(obj, protectionType)
-- Gets the protection level of a title object. Current possible values on enwiki (as of October 2013) are "autoconfirmed", "templateeditor" and "sysop".
local frame = mw.getCurrentFrame()
local level = frame:callParserFunction('PROTECTIONLEVEL', protectionType, obj.prefixedText)
if level == '' then -- Make unprotected pages return "unprotected" rather than the blank string.
level = 'unprotected'
end
return level
end
 
-- Add a protectionLevel property.
elseifif obj.exists then
if obj.namespace == 8 then -- page is in the MediaWiki namespace
obj.protectionLevel = effectiveProtectionLevel('sysopedit', obj)
elseif obj.namespace == 2 and (mw.ustring.find(obj.text, '/.*%.js$') or mw.ustring.find(obj.text, '/.*%.css$')) then -- user .js or .css page
obj.protectionLevel = 'sysop'
elseif obj.exists then
obj.protectionLevel = getProtectionLevel(obj, 'edit')
else
obj.protectionLevel = getProtectionLeveleffectiveProtectionLevel(obj, 'create', obj)
-- Unprotected pages that don't exist get treated as semi-protected, so that requests to create pages don't get flagged as having the wrong protection level
-- Unregistered users can create talk pages (odd numbered namespaces) and drafts (namespace 118), so exclude them
if obj.protectionLevel == 'unprotected' and obj.namespace % 2 == 0 and obj.namespace ~= 118 then
obj.protectionLevel = 'autoconfirmed'
end
end
 
if level == '' then -- Make unprotected pages return "unprotected" rather than the blank string.
if obj.protectionLevel == 'sysop' then
levelobj.protectionLevel = 'unprotected'
end