Διαφορά μεταξύ των αναθεωρήσεων του "Module:Submit an edit request"

Από Γνωσιακή Βάση Υπηρεσιών και Διαδικασιών του Δημοσίου Τομέα
Μετάβαση σε: πλοήγηση, αναζήτηση
μ (Εισήχθη 1 αναθεώρηση)
(Νέα σελίδα: -- This module implements {{Submit an edit request}}. -- Load necessary modules local mRedirect = require('Module:Redirect') local cfg = mw.loadData('Module:Submit an edit r...)
(Μία ενδιάμεση έκδοση από ένα χρήστη δεν εμφανίζεται)
Γραμμή 1: Γραμμή 1:
 
-- This module implements {{Submit an edit request}}.
 
-- This module implements {{Submit an edit request}}.
 
local CONFIG_MODULE = 'Module:Submit an edit request/config/sandbox'
 
  
 
-- Load necessary modules
 
-- Load necessary modules
 
local mRedirect = require('Module:Redirect')
 
local mRedirect = require('Module:Redirect')
local cfg = mw.loadData(CONFIG_MODULE)
+
local cfg = mw.loadData('Module:Submit an edit request/config')
local effectiveProtectionLevel = require('Module:Effective protection level')._main
 
local lang = mw.language.getContentLanguage()
 
  
 
local p = {}
 
local p = {}
 
local validLevels = {
 
semi = 'semi',
 
template = 'template',
 
full = 'full'
 
}
 
  
 
local function message(key, ...)
 
local function message(key, ...)
Γραμμή 25: Γραμμή 15:
 
return mw.message.newRawMessage(msg):params(params):plain()
 
return mw.message.newRawMessage(msg):params(params):plain()
 
end
 
end
end
 
 
local function isTranscludedOnMainPage(titleObj)
 
local mainPage = message('main-page')
 
for i, source in ipairs(titleObj.cascadingProtection.sources) do
 
if source == mainPage then
 
return true
 
end
 
end
 
return false
 
end
 
 
local function validateLevel(level)
 
return level and validLevels[level] or 'full'
 
end
 
 
local function getLevelInfo(level, field)
 
return cfg.protectionLevels[level][field]
 
end
 
 
local function resolveRedirect(page)
 
return mRedirect.luaMain(page)
 
end
 
 
local function isProtected(page)
 
local action = mw.title.new(page).exists and 'edit' or 'create'
 
return effectiveProtectionLevel(action, page) ~= '*'
 
 
end
 
end
  
 
function p.makeRequestUrl(level, titleObj)
 
function p.makeRequestUrl(level, titleObj)
 
titleObj = titleObj or mw.title.getCurrentTitle()
 
titleObj = titleObj or mw.title.getCurrentTitle()
if isTranscludedOnMainPage(titleObj) then
+
return tostring(mw.uri.fullUrl(message('main-page-request-page')))
+
do
 +
local levels = {
 +
semi = true,
 +
template = true,
 +
full = true
 +
}
 +
level = level and levels[level] and level or 'full'
 
end
 
end
local talkPageName = resolveRedirect(titleObj.talkPageTitle.prefixedText)
+
if isProtected(talkPageName) then
+
local editintro, requestTemplate, levelText
return tostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
+
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
 
end
level = validateLevel(level)
+
local url = mw.uri.fullUrl(talkPageName, {
+
local preloadtitle, talkpagename
action = 'edit',
+
do
editintro = getLevelInfo(level, 'editintro'),
+
-- Get the date text.
preload = message('preload-template'),
+
local dateFormat = message('preload-title-date-format')
preloadtitle = message(
+
local lang = mw.language.getContentLanguage()
'preload-title-text',
+
local date = lang:formatDate(dateFormat)
getLevelInfo(level, 'levelText'),
+
lang:formatDate(message('preload-title-date-format'))
+
-- Get the talk page name, and resolve it if it is a redirect.
),
+
local namespace = titleObj.namespace
section = 'new'
+
talkpagename = mw.site.namespaces[namespace].talk.name
})
+
.. ':'
url = tostring(url)
+
..  titleObj.text
 
+
talkpagename = mRedirect.luaMain(talkpagename)
-- Add the preload parameters. @TODO: merge this into the mw.uri.fullUrl
+
preloadtitle = message('preload-title-text', levelText, date)
-- query table once [[phab:T93059]] is fixed.
+
end
local function encodeParam(key, val)
+
return string.format('&%s=%s', mw.uri.encode(key), mw.uri.encode(val))
+
local preloadTemplate = message('preload-template')
 +
 +
local function encode(key, value)
 +
key = mw.uri.encode(key)
 +
value = mw.uri.encode(value)
 +
return key .. '=' .. value
 
end
 
end
url = url .. encodeParam('preloadparams[]', getLevelInfo(level, 'requestTemplate'))
 
url = url .. encodeParam('preloadparams[]', titleObj.prefixedText)
 
  
 +
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
 
return url
 
end
 
end

Αναθεώρηση της 21:00, 17 Νοεμβρίου 2014

Documentation for this module may be created at Module:Submit an edit request/τεκμηρίωση

-- 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