Módulo:Testes/Gkiyoshinishimoto/Submit an edit request
Este módulo implementa as predefinições {{Teste/Gkiyoshinishimoto/Submit an edit request}} e {{Teste/Gkiyoshinishimoto/Submit an edit request/link}}.
Uso a partir de texto wiki[editar código-fonte]
Para usar este módulo a partir de texto wiki, você normalmente deve usar as predefinições {{Teste/Gkiyoshinishimoto/Submit an edit request}} e {{Teste/Gkiyoshinishimoto/Submit an edit request/link}}. No entanto, o módulo também pode ser usado diretamente a partir de "#invoke". Para o botão de solicitação de edição, use {{#invoke:Testes/Gkiyoshinishimoto/Submit an edit request|button|args}}
, e para apenas a ligação de solicitação de edição, use {{#invoke:Testes/Gkiyoshinishimoto/Submit an edit request|link|args}}
. Consulte as páginas das respectivas predefinições para obter uma lista de parâmetros disponíveis
Uso a partir de módulos Lua[editar código-fonte]
Para usar este módulo a partir de outros módulos Lua, primeiro carregue o módulo.
local mEditRequest = require('Módulo:Testes/Gkiyoshinishimoto/Submit an edit request')
Você pode então usar a função "_button" para gerar um botão de solicitação de edição e a função "_link" para gerar uma ligação de solicitação de edição.
mEditRequest._button(args)
mEditRequest._link(args)
A variável args deve ser uma tabela contendo os argumentos a serem passados ao módulo. Para ver os diferentes argumentos que podem ser especificados e como eles afetam a saída do módulo, por favor consulte a documentação de {{Teste/Gkiyoshinishimoto/Submit an edit request}} e {{Teste/Gkiyoshinishimoto/Submit an edit request/link}}.
Configuração[editar código-fonte]
Este módulo pode ser traduzido e configurado para outras wikis editando Módulo:Testes/Gkiyoshinishimoto/Submit an edit request/config.
A documentação acima é transcluída de Módulo:Testes/Gkiyoshinishimoto/Submit an edit request/doc. (editar | histórico) Editores podem experimentar nas páginas de teste (criar | espelhar) e de exemplos para testes (criar) deste módulo. Subpáginas deste módulo. |
-- Este módulo implementa {{Teste/Gkiyoshinishimoto/Submit an edit request}}.
local CONFIG_MODULE = 'Módulo:Testes/Gkiyoshinishimoto/Submit an edit request/config'
-- Carrega os módulos necessários
local mRedirect = require('Module:Testes/Gkiyoshinishimoto/Redirect')
local cfg = mw.loadData(CONFIG_MODULE)
local effectiveProtectionLevel = require('Módulo:Testes/Gkiyoshinishimoto/Effective protection level')._main
local escape = require("Módulo:Testes/Gkiyoshinishimoto/String")._escapePattern
local lang = mw.language.getContentLanguage()
local p = {}
local validLevels = {
semi = 'semi',
extended = 'extended',
template = 'template',
full = 'full',
interface = 'interface',
manual = 'manual'
}
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 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()
local basePage = titleObj.basePageTitle.fullText
if cfg['main-page-content'][basePage] then
return tostring(mw.uri.fullUrl(message('main-page-request-page')))
end
local talkPageName = titleObj.talkPageTitle
if talkPageName == nil then
return tostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
end
talkPageName = resolveRedirect(talkPageName.prefixedText)
if isProtected(talkPageName) then
return tostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
end
level = validateLevel(level)
if level == 'manual' then
return tostring(mw.uri.fullUrl(talkPageName, {
action = 'edit',
section = 'new'
}))
end
local sectionname = message(
'preload-title-text',
getLevelInfo(level, 'levelText'),
lang:formatDate(message('preload-title-date-format'))
)
local content = mw.title.new(talkPageName):getContent()
if content and content:find("== *" .. escape(sectionname) .. " *==") then
local dedup = 2
while true do
local newname = message("preload-title-dedup-suffix", sectionname, dedup)
if not content:find("== *" .. escape(newname) .. " *==") then
sectionname = newname
break
end
dedup = dedup + 1
end
end
local url = mw.uri.fullUrl(talkPageName, {
action = 'edit',
editintro = getLevelInfo(level, 'editintro'),
preload = message('preload-template'),
preloadtitle = sectionname,
section = 'new'
})
url = tostring(url)
-- Adiciona os parâmetros de pré-carregamento. @TODO: mesclar isso na tabela de consulta "mw.uri.fullUrl"
-- assim que [[phab:T93059]] for corrigido.
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ódulo:Testes/Gkiyoshinishimoto/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ódulo:Teste/Gkiyoshinishimoto/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