Module:Submit an edit request
![]() | This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
This module implements the {{submit an edit request}} and {{submit an edit request/link}} templates.
Usage from wikitext
To use this module 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.
-- This module implements {{Submit an edit request}}.
local cfg = {}
cfg['preload-template'] = 'Template:Submit an edit request/preload'
cfg['preload-title-text'] = '$1 edit request on $2'
cfg['preload-title-date-format'] = 'j F Y'
cfg['semi-editintro'] = 'Template:Edit semi-protected/editintro'
cfg['semi-request-template'] = 'edit semi-protected'
cfg['semi-protectionlevel'] = 'Semi-protected'
cfg['template-editintro'] = 'Template:Edit template-protected/editintro'
cfg['template-request-template'] = 'edit template-protected'
cfg['template-protectionlevel'] = 'Template-protected'
cfg['full-editintro'] = 'Template:Edit protected/editintro'
cfg['full-request-template'] = 'edit protected'
cfg['full-protectionlevel'] = 'Protected'
local mRedirect = require('Module:Redirect')
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()
local editintro, requestTemplate, levelText
do
local messages = {
semi = {
editintro = 'semi-editintro',
requestTemplate = 'semi-request-template',
protectionLevel = 'semi-protectionlevel'
},
template = {
editintro = 'template-editintro',
requestTemplate = 'template-request-template',
protectionLevel = 'template-protectionlevel'
},
full = {
editintro = 'full-editintro',
requestTemplate = 'full-request-template',
protectionLevel = '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
if namespace % 2 == 0 then
namespace = namespace + 1
end
talkpagename = mw.site.namespaces[namespace].name .. titleObj.text
talkpagename = mRedirect.main{talkpagename}
preloadtitle = message('preload-title-text', talkpagename, date)
end
local preloadTemplate = message('preload-template')
local function encode(key, value)
local ret = key .. '=' .. value
return mw.uri.encode(ret)
end
local query = {}
query[#query + 1] = 'action=edit'
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] = encode('preloadparams[]', titleObj.prefixedText)
local url = mw.uri.fullUrl(talkpagename, table.concat(query, '&'))
return tostring(url)
end
return p