Anonymous
×
Create a new article
Write your page title here:
We currently have 15 articles on TwistedFates Database. Type your article name above or click on one of the titles below and start writing!



TwistedFates Database
15Articles

Module:Effective protection level and Module:File link: Difference between pages

(Difference between pages)
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
-- This module provides a library for formatting file wikilinks.
local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType
local p = {}
local p = {}


-- Returns the permission required to perform a given action on a given title.
function p._main(args)
-- If no title is specified, the title of the page being displayed is used.
checkType('_main', 1, args, 'table')
function p._main(action, pagename)
 
local title
-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our
if type(pagename) == 'table' and pagename.prefixedText then
-- own function to get the right error level.
title = pagename
local function checkArg(key, val, level)
elseif pagename then
if type(val) ~= 'string' then
title = mw.title.new(pagename)
error(string.format(
else
"type error in '%s' parameter of '_main' (expected string, got %s)",
title = mw.title.getCurrentTitle()
key, type(val)
), level)
end
end
end
pagename = title.prefixedText
 
if action == 'autoreview' then
local ret = {}
local level = mw.ext.FlaggedRevs.getStabilitySettings(title)
 
level = level and level.autoreview
-- Adds a positional parameter to the buffer.
if level == 'review' then
local function addPositional(key)
return 'reviewer'
local val = args[key]
elseif level ~= '' then
if not val then
return level
return nil
else
return nil -- not '*'. a page not being PC-protected is distinct from it being PC-protected with anyone able to review. also not '', as that would mean PC-protected but nobody can review
end
end
elseif action ~= 'edit' and action ~= 'move' and action ~= 'create' and action ~= 'upload' and action ~= 'undelete' then
checkArg(key, val, 4)
error( 'First parameter must be one of edit, move, create, upload, undelete, autoreview', 2 )
ret[#ret + 1] = val
end
end
if title.namespace == 8 then -- MediaWiki namespace
 
if title.text:sub(-3) == '.js' or title.text:sub(-4) == '.css' or title.contentModel == 'javascript' or title.contentModel == 'css' then -- site JS or CSS page
-- Adds a named parameter to the buffer. We assume that the parameter name
return 'interfaceadmin'
-- is the same as the argument key.
else -- any non-JS/CSS MediaWiki page
local function addNamed(key)
return 'sysop'
local val = args[key]
end
if not val then
elseif title.namespace == 2 and title.isSubpage then
return nil
if title.contentModel == 'javascript' or title.contentModel == 'css' then -- user JS or CSS page
return 'interfaceadmin'
elseif title.contentModel == 'json' then -- user JSON page
return 'sysop'
end
end
checkArg(key, val, 4)
ret[#ret + 1] = key .. '=' .. val
end
end
if action == 'undelete' then
 
return 'sysop'
-- Filename
end
checkArg('file', args.file, 3)
local level = title.protectionLevels[action] and title.protectionLevels[action][1]
ret[#ret + 1] = 'File:' .. args.file
if level == 'sysop' or level == 'editprotected' then
 
return 'sysop'
-- Format
elseif title.cascadingProtection.restrictions[action] and title.cascadingProtection.restrictions[action][1] then -- used by a cascading-protected page
if args.format then
return 'sysop'
checkArg('format', args.format)
elseif level == 'templateeditor' then
if args.formatfile then
return 'templateeditor'
checkArg('formatfile', args.formatfile)
elseif action == 'move' then
ret[#ret + 1] = args.format .. '=' .. args.formatfile
local blacklistentry = mw.ext.TitleBlacklist.test('edit', pagename) -- Testing action edit is correct, since this is for the source page. The target page name gets tested with action move.
if blacklistentry and not blacklistentry.params.autoconfirmed then
return 'templateeditor'
elseif title.namespace == 6 then
return 'filemover'
elseif level == 'extendedconfirmed' then
return 'extendedconfirmed'
else
else
return 'autoconfirmed'
ret[#ret + 1] = args.format
end
end
end
end
local blacklistentry = mw.ext.TitleBlacklist.test(action, pagename)
 
if blacklistentry then
-- Border
if not blacklistentry.params.autoconfirmed then
if yesno(args.border) then
return 'templateeditor'
ret[#ret + 1] = 'border'
elseif level == 'extendedconfirmed' then
return 'extendedconfirmed'
else
return 'autoconfirmed'
end
elseif level == 'editsemiprotected' then -- create-semiprotected pages return this for some reason
return 'autoconfirmed'
elseif level then
return level
elseif action == 'upload' then
return 'autoconfirmed'
elseif action == 'create' and title.namespace % 2 == 0 and title.namespace ~= 118 then -- You need to be registered, but not autoconfirmed, to create non-talk pages other than drafts
return 'user'
else
return '*'
end
end
addPositional('location')
addPositional('alignment')
addPositional('size')
addNamed('upright')
addNamed('link')
addNamed('alt')
addNamed('page')
addNamed('class')
addNamed('lang')
addNamed('start')
addNamed('end')
addNamed('thumbtime')
addPositional('caption')
return string.format('[[%s]]', table.concat(ret, '|'))
end
end


setmetatable(p, { __index = function(t, k)
function p.main(frame)
return function(frame)
local origArgs = require('Module:Arguments').getArgs(frame, {
return t._main(k, frame.args[1])
wrappers = 'Template:File link'
})
if not origArgs.file then
error("'file' parameter missing from [[Template:File link]]", 0)
end
end
end })
 
-- Copy the arguments that were passed to a new table to avoid looking up
-- every possible parameter in the frame object.
local args = {}
for k, v in pairs(origArgs) do
-- Make _BLANK a special argument to add a blank parameter. For use in
-- conditional templates etc. it is useful for blank arguments to be
-- ignored, but we still need a way to specify them so that we can do
-- things like [[File:Example.png|link=]].
if v == '_BLANK' then
v = ''
end
args[k] = v
end
return p._main(args)
end


return p
return p

Latest revision as of 21:26, 21 May 2021

Documentation for this module may be created at Module:File link/doc

-- This module provides a library for formatting file wikilinks.

local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType

local p = {}

function p._main(args)
	checkType('_main', 1, args, 'table')

	-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our
	-- own function to get the right error level.
	local function checkArg(key, val, level)
		if type(val) ~= 'string' then
			error(string.format(
				"type error in '%s' parameter of '_main' (expected string, got %s)",
				key, type(val)
			), level)
		end
	end

	local ret = {}

	-- Adds a positional parameter to the buffer.
	local function addPositional(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = val
	end

	-- Adds a named parameter to the buffer. We assume that the parameter name
	-- is the same as the argument key.
	local function addNamed(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = key .. '=' .. val
	end

	-- Filename
	checkArg('file', args.file, 3)
	ret[#ret + 1] = 'File:' .. args.file

	-- Format
	if args.format then
		checkArg('format', args.format)
		if args.formatfile then
			checkArg('formatfile', args.formatfile)
			ret[#ret + 1] = args.format .. '=' .. args.formatfile
		else
			ret[#ret + 1] = args.format
		end
	end

	-- Border
	if yesno(args.border) then
		ret[#ret + 1] = 'border'
	end

	addPositional('location')
	addPositional('alignment')
	addPositional('size')
	addNamed('upright')
	addNamed('link')
	addNamed('alt')
	addNamed('page')
	addNamed('class')
	addNamed('lang')
	addNamed('start')
	addNamed('end')
	addNamed('thumbtime')
	addPositional('caption')

	return string.format('[[%s]]', table.concat(ret, '|'))
end

function p.main(frame)
	local origArgs = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:File link'
	})
	if not origArgs.file then
		error("'file' parameter missing from [[Template:File link]]", 0)
	end

	-- Copy the arguments that were passed to a new table to avoid looking up
	-- every possible parameter in the frame object.
	local args = {}
	for k, v in pairs(origArgs) do
		-- Make _BLANK a special argument to add a blank parameter. For use in
		-- conditional templates etc. it is useful for blank arguments to be
		-- ignored, but we still need a way to specify them so that we can do
		-- things like [[File:Example.png|link=]].
		if v == '_BLANK' then
			v = ''
		end
		args[k] = v
	end
	return p._main(args)
end

return p