Module:If preview/sandbox
Appearance
From Wikipedia, the free encyclopedia
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Warning This Lua module is used on approximately 1,040,000 pages, or roughly 2% of all pages .
To avoid major disruption and server load, 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. Consider discussing changes on the talk page before implementing them.
To avoid major disruption and server load, 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. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
This module implements {{If preview }} and {{Preview warning }}. It helps templates/modules determine if they are being previewed.
Prefer implementing the template versions in other templates.
In a module to use the main(), you need to pass a frame table with an args table.
For the preview warning, use _warning().
The above documentation is transcluded from Module:If preview/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
localp={} localgetArgs=require("Module:Arguments").getArgs localyn=require("Module:Yesno") localcfg=mw.loadData('Module:If preview/configuration') p.pvwc=p.pvwcorpackage.loaded["Module:If preview/preview warning counter"] orrequire("Module:If preview/preview warning counter") --[[ main This function returns either the first argument or second argument passed to this module, depending on whether the page is being previewed. ]] functionp.main(frame) localargs=getArgs(frame) ifcfg.previewthen returnargs[1]or'' else returnargs[2]or'' end end --[[ pmain This function returns either the first argument or second argument passed to this module's parent (i.e. template using this module), depending on whether it is being previewed. ]] functionp.pmain(frame) returnp.main(frame:getParent()) end localfunctionwarning_text(warning) returnmw.ustring.format( cfg.warning_infrastructure, cfg.templatestyles, warning ) end functionp._warning(args) localwarning=args[1]andargs[1]:match('^%s*(.-)%s*$')or'' ifwarning==''then returnwarning_text(cfg.missing_warning) end ifnotcfg.previewthenreturn''end ifyn(args['consolewarning'])thenmw.addWarning('['..p.pvwc.incr()..'] '..(args[1]orcfg.missing_warning))end returnwarning_text(warning) end --[[ warning This function returns a "preview warning", which is the first argument marked up with HTML and some supporting text, depending on whether the page is being previewed. ]] -- function p.warning(frame) -- mw.addWarning(frame.args[1] or cfg.missing_warning) -- return p._warning(frame.args) -- end --[[ warning, but for pass-through templates like {{preview warning}} ]] functionp.pwarning(frame) localargs=getArgs(frame) returnp._warning(args) end --[[ Does both mw.addWarning and preview warning ]] functionp.warn(text) iftext==nilortext==""thenreturn""end mw.addWarning('['..p.pvwc.incr()..'] '..text) returnp._warning({text}) end --[[ Console warning ]] functionp.consoleWarning(frame) localargs=getArgs(frame) mw.addWarning('['..p.pvwc.incr()..'] '..(args[1]orcfg.missing_warning)) return'' end returnp