Jump to content
Wikipedia The Free Encyclopedia

Module:Submit an edit request

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
[画像:Warning] 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 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.

localmEditRequest=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.

The above documentation is transcluded from Module:Submit an edit request/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 -- This module implements {{Submit an edit request}}.

 localCONFIG_MODULE='Module:Submit an edit request/config'

 -- Load necessary modules
 localmRedirect=require('Module:Redirect')
 localcfg=mw.loadData(CONFIG_MODULE)
 localeffectiveProtectionLevel=require('Module:Effective protection level')._main
 localescape=require("Module:String")._escapePattern
 locallang=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<1then
 returnmsg
 else
 returnmw.message.newRawMessage(msg):params(params):plain()
 end
 end

 localfunctionvalidateLevel(level)
 returnlevelandvalidLevels[level]or'full'
 end

 localfunctiongetLevelInfo(level,field)
 returncfg.protectionLevels[level][field]
 end

 localfunctionresolveRedirect(page)
 returnmRedirect.luaMain(page)
 end

 localfunctionisProtected(page)
 localaction=mw.title.new(page).existsand'edit'or'create'
 returneffectiveProtectionLevel(action,page)~='*'
 end

 functionp.makeRequestUrl(level,titleObj)
 titleObj=titleObjormw.title.getCurrentTitle()
 localbasePage=titleObj.basePageTitle.fullText
 ifcfg['main-page-content'][basePage]then
 returntostring(mw.uri.fullUrl(message('main-page-request-page')))
 end

 localtalkPageName=titleObj.talkPageTitle
 iftalkPageName==nilthen
 returntostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
 end
 talkPageName=resolveRedirect(talkPageName.prefixedText)
 ifisProtected(talkPageName)then
 returntostring(mw.uri.fullUrl(message('protected-talk-page-request-page')))
 end
 level=validateLevel(level)
 iflevel=='manual'then
 returntostring(mw.uri.fullUrl(talkPageName,{
 action='edit',
 section='new'
 }))
 end
 localsectionname=message(
 'preload-title-text',
 getLevelInfo(level,'levelText'),
 lang:formatDate(message('preload-title-date-format'))
 )
 localcontent=mw.title.new(talkPageName):getContent()
 ifcontentandcontent:find("== *"..escape(sectionname).." *==")then
 localdedup=2
 whiletruedo
 localnewname=message("preload-title-dedup-suffix",sectionname,dedup)
 ifnotcontent:find("== *"..escape(newname).." *==")then
 sectionname=newname
 break
 end
 dedup=dedup+1
 end
 end
 localurl=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))
 end
 url=url..encodeParam('preloadparams[]',getLevelInfo(level,'requestTemplate'))
 url=url..encodeParam('preloadparams[]',titleObj.prefixedText)

 returnurl
 end

 functionp._link(args)
 returnstring.format(
 '<span class="plainlinks">[%s %s]</span>',
 p.makeRequestUrl(args.type),
 args.displayormessage('default-display-value')
 )
 end

 functionp._button(args)
 returnrequire('Module:Clickable button').main{
 [1]=args.displayormessage('default-display-value'),
 url=p.makeRequestUrl(args.type),
 class='mw-ui-progressive'
 }
 end

 localfunctionmakeInvokeFunc(func,wrapper)
 returnfunction(frame)
 localargs=require('Module:Arguments').getArgs(frame,{
 wrappers={wrapper}
 })
 returnfunc(args)
 end
 end

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

 returnp

AltStyle によって変換されたページ (->オリジナル) /