Jump to content

Module:Submit an edit request/sandbox

From Wikipedia, the free encyclopedia
-- This module implements {{Submit an edit request}}.localCONFIG_MODULE='Module:Submit an edit request/config'-- Load necessary moduleslocalmRedirect=require('Module:Redirect')localcfg=mw.loadData(CONFIG_MODULE)localeffectiveProtectionLevel=require('Module:Effective protection level')._mainlocalescape=require("Module:String")._escapePatternlocallang=mw.language.getContentLanguage()localp={}localvalidLevels={semi='semi',extended='extended',template='template',full='full',interface='interface',manual='manual'}localfunctionmessage(key,...)localparams={...}localmsg=cfg[key]if#params<1thenreturnmsgelsereturnmw.message.newRawMessage(msg):params(params):plain()endendlocalfunctionvalidateLevel(level)returnlevelandvalidLevels[level]or'full'endlocalfunctiongetLevelInfo(level,field)returncfg.protectionLevels[level][field]endlocalfunctionresolveRedirect(page)returnmRedirect.luaMain(page)endlocalfunctionisProtected(page)localaction=mw.title.new(page).existsand'edit'or'create'returneffectiveProtectionLevel(action,page)~='*'endfunctionp.makeRequestUrl(level,titleObj)titleObj=titleObjormw.title.getCurrentTitle()localbasePage=titleObj.basePageTitle.fullTextifcfg['main-page-content'][basePage]thenreturntostring(mw.uri.fullUrl(message('main-page-request-page')))endlocaltalkPageName=titleObj.talkPageTitleiftalkPageName==nilthenreturntostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))endtalkPageName=resolveRedirect(talkPageName.prefixedText)ifisProtected(talkPageName)thenreturntostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))endlevel=validateLevel(level)iflevel=='manual'thenreturntostring(mw.uri.fullUrl(talkPageName,{action='edit',section='new'}))endlocalsectionname=message('preload-title-text',getLevelInfo(level,'levelText'),lang:formatDate(message('preload-title-date-format')))localcontent=mw.title.new(talkPageName):getContent()ifcontentandcontent:find("== *"..escape(sectionname).." *==")thenlocaldedup=2whiletruedolocalnewname=message("preload-title-dedup-suffix",sectionname,dedup)ifnotcontent:find("== *"..escape(newname).." *==")thensectionname=newnamebreakenddedup=dedup+1endendlocalurl=mw.uri.fullUrl(talkPageName,{action='edit',editintro=getLevelInfo(level,'editintro'),preload=message('preload-template'),preloadtitle=sectionname,section='new'})url=tostring(url)-- Add the preload parameters. @TODO: merge this into the mw.uri.fullUrl-- query table once [[phab:T93059]] is fixed.localfunctionencodeParam(key,val)returnstring.format('&%s=%s',mw.uri.encode(key),mw.uri.encode(val))endurl=url..encodeParam('preloadparams[]',getLevelInfo(level,'requestTemplate'))url=url..encodeParam('preloadparams[]',titleObj.prefixedText)returnurlendfunctionp._link(args)returnstring.format('<span class="plainlinks">[%s %s]</span>',p.makeRequestUrl(args.type),args.displayormessage('default-display-value'))endfunctionp._button(args)returnrequire('Module:Clickable button').main{[1]=args.displayormessage('default-display-value'),url=p.makeRequestUrl(args.type),class='mw-ui-progressive'}endlocalfunctionmakeInvokeFunc(func,wrapper)returnfunction(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers={wrapper}})returnfunc(args)endendp.link=makeInvokeFunc(p._link,message('link-wrapper-template'))p.button=makeInvokeFunc(p._button,message('button-wrapper-template'))returnp
close