Modul:Submit an edit request
This module is rated as ready for general use. It has reached a mature form and is thought to be bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
This module implements the {{submit an edit request}} and {{submit an edit request/link}} templates.
Usage from wikitext
To use this template from wikitext, you should normally use the {{submit an edit request}} and {{submit an edit request/link}} templates. However, the module can also be used directly from #invoke. For the edit request button, use {{#invoke:Submit an edit request|button|args}}
, and for the edit request link only, use {{#invoke:Submit an edit request|link|args}}
. Please see the respective template pages for a list of available parameters.
Usage from Lua modules
To use this module from other Lua modules, first load the module.
local mEditRequest = require('Module:Submit an edit request')
You can then use the _button function to generate an edit request button, and the _link function to generate an edit request link.
mEditRequest._button(args)
mEditRequest._link(args)
The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the documentation of {{Submit an edit request}} and {{Submit an edit request/link}}.
Configuration
This module can be translated and configured for other wikis by editing Module:Submit an edit request/config.
The above documentation is transcluded from Modul:Submit an edit request/doc. (edit | history) Subpages of this module. |
-- 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' .. (((args.language and cfg['default-display-value-' .. args.language]) and '-' .. args.language) or ''))
)
end
function p._button(args)
return require('Module:Clickable button 2').luaMain{
[1] = args.display or message('default-display-value' .. (((args.language and cfg['default-display-value-' .. args.language]) and '-' .. args.language) or '')),
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