Mòideal:Submit an edit request
Uses Lua: |
Related pages |
---|
(deasbaireachd⧼tpt-languages-separator⧽ ⧼tpt-languages-separator⧽eachdraidh⧼tpt-languages-separator⧽ceanglaichean⧼tpt-languages-separator⧽doc⧼tpt-languages-separator⧽bogsa-gainmhich⧼tpt-languages-separator⧽cùisean deuchainn)
This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This mòideal is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid large-scale disruption, any changes should first be tested in this mòideal's /sandbox or /testcases subpage, or in your own user space. The tested changes can then be added in one single edit to this mòideal. Please discuss any changes on the talk page before implementing them. |
This module implements the {{Submit an edit request}} and {{Submit an edit request/link}} templates.
Ùsaid bho uiciteacsa - 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.
Ùsaid bho Lua - Usage from Lua
To use this module from other Lua modules, first load the module.
local mEditRequest = require('Mòideal: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}}.
Réiteachadh - Configuration
This module can be translated and configured for other wikis by editing Mòideal:Submit an edit request/config.
-- This module implements {{Submit an edit request}}.
local CONFIG_MODULE = 'Mòideal:Submit an edit request/config'
-- Load necessary modules
local mRedirect = require('Mòideal:Redirect')
local cfg = mw.loadData(CONFIG_MODULE)
local effectiveProtectionLevel = require('Mòideal:Effective protection level')._main
local lang = mw.language.getContentLanguage()
local p = {}
local validLevels = {
semi = 'semi',
extended = 'extended',
template = 'template',
full = 'full',
interface = 'interface'
}
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
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
function p.makeRequestUrl(level, titleObj)
titleObj = titleObj or mw.title.getCurrentTitle()
if isTranscludedOnMainPage(titleObj) then
return tostring(mw.uri.fullUrl(message('main-page-request-page')))
end
local talkPageName = resolveRedirect(titleObj.talkPageTitle.prefixedText)
if isProtected(talkPageName) then
return tostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
end
level = validateLevel(level)
local url = mw.uri.fullUrl(talkPageName, {
action = 'edit',
editintro = getLevelInfo(level, 'editintro'),
preload = message('preload-template'),
preloadtitle = message(
'preload-title-text',
getLevelInfo(level, 'levelText'),
lang:formatDate(message('preload-title-date-format'))
),
section = 'new'
})
url = tostring(url)
-- Add the preload parameters. @TODO: merge this into the mw.uri.fullUrl
-- query table once [[phab:T93059]] is fixed.
local function encodeParam(key, val)
return string.format('&%s=%s', mw.uri.encode(key), mw.uri.encode(val))
end
url = url .. encodeParam('preloadparams[]', getLevelInfo(level, 'requestTemplate'))
url = url .. encodeParam('preloadparams[]', titleObj.prefixedText)
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('Mòideal: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('Mòideal: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