Module:Submit an edit request explained

-- This module implements .

local CONFIG_MODULE = 'Module:Submit an edit request/config'

-- Load necessary moduleslocal mRedirect = require('Module:Redirect')local cfg = mw.loadData(CONFIG_MODULE)local effectiveProtectionLevel = require('Module:Effective protection level')._mainlocal escape = require("Module:String")._escapePatternlocal lang = mw.language.getContentLanguage

local p =

local validLevels =

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 endend

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,)) 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,) url = tostring(url)

-- Add the preload parameters. @TODO: merge this into the mw.uri.fullUrl -- query table once 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 urlend

function p._link(args) return string.format('

[%s %s]', p.makeRequestUrl(args.type), args.display or message('default-display-value') )end

function p._button(args) return require('Module:Clickable button 2').mainend

local function makeInvokeFunc(func, wrapper) return function (frame) local args = require('Module:Arguments').getArgs(frame,) return func(args) endend

p.link = makeInvokeFunc(p._link, message('link-wrapper-template'))p.button = makeInvokeFunc(p._button, message('button-wrapper-template'))

return p