Modul:Submit an edit request

Moduldokumentasjon

Usage

This template is used in various interface messages and creates a link which aids users in making requests to protected pages.

Subtemplates

This template also uses:

See also



-- This module implements {{Submit an edit request}}.

-- Load necessary modules
local mRedirect = require('Module:Redirect')
local cfg = mw.loadData('Module:Submit an edit request/config')

local p = {}

local function message(key, ...)
	local params = {...}
	local msg = cfg[key]
	if #params < 1 then
		return msg
	else
		return mw.message.newRawMessage(msg):params(params):plain()
	end
end

function p.makeRequestUrl(level, titleObj)
	titleObj = titleObj or mw.title.getCurrentTitle()
	
	do
		local levels = {
			semi = true,
			template = true,
			full = true
		}
		level = level and levels[level] and level or 'full'
	end
	
	local editintro, requestTemplate, levelText
	do
		local messages = {
			semi = {
				editintro = 'semi-editintro',
				requestTemplate = 'semi-request-template',
				levelText = 'semi-protectionlevel'
			},
			template = {
				editintro = 'template-editintro',
				requestTemplate = 'template-request-template',
				levelText = 'template-protectionlevel'
			},
			full = {
				editintro = 'full-editintro',
				requestTemplate = 'full-request-template',
				levelText = 'full-protectionlevel'
			}
		}
		local levelMessages = messages[level]
		editintro = message(levelMessages.editintro)
		requestTemplate = message(levelMessages.requestTemplate)
		levelText = message(levelMessages.levelText)
	end
	
	local preloadtitle, talkpagename
	do
		-- Get the date text.
		local dateFormat = message('preload-title-date-format')
		local lang = mw.language.getContentLanguage()
		local date = lang:formatDate(dateFormat)
		
		-- Get the talk page name, and resolve it if it is a redirect.
		local namespace = titleObj.namespace
		talkpagename = mw.site.namespaces[namespace].talk.name
			.. ':'
			..  titleObj.text
		talkpagename = mRedirect.luaMain(talkpagename)
		preloadtitle = message('preload-title-text', levelText, date)
	end
	
	local preloadTemplate = message('preload-template')
	
	local function encode(key, value)
		key = mw.uri.encode(key)
		value = mw.uri.encode(value)
		return key .. '=' .. value
	end

	local query = {}
	query[#query + 1] = encode('preload', preloadTemplate)
	query[#query + 1] = encode('editintro', editintro)
	query[#query + 1] = encode('preloadparams[]', requestTemplate)
	query[#query + 1] = encode('preloadtitle', preloadtitle)
	query[#query + 1] = 'section=new'
	query[#query + 1] = encode('preloadparams[]', titleObj.prefixedText)
	
	local url = mw.uri.fullUrl(talkpagename, {action = 'edit'})
	url = tostring(url) .. '&' .. table.concat(query, '&')
	return url
end

function p._link(args)
	return string.format(
		'<span class="plainlinks">[%s %s]</span>',
		p.makeRequestUrl(args.type),
		args.display or message('default-display-value')
	)
end

function p._button(args)
	return require('Module:Clickable button 2').luaMain{
		[1] = args.display or message('default-display-value'),
		url = p.makeRequestUrl(args.type),
		class = 'mw-ui-progressive'
	}
end

local function makeInvokeFunc(func, wrapper)
	return function (frame)
		local args = require('Module:Arguments').getArgs(frame, {
			wrappers = {wrapper}
		})
		return func(args)
	end
end

p.link = makeInvokeFunc(p._link, message('link-wrapper-template'))
p.button = makeInvokeFunc(p._button, message('button-wrapper-template'))

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.