Jump to content
Wikipedia The Free Encyclopedia

Module:If preview

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
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.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 421,000 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.
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.
Subpages of this module.

 localp={}
 localgetArgs=require("Module:Arguments").getArgs
 localyn=require("Module:Yesno")
 localcfg=mw.loadData('Module:If preview/configuration')

 --[[
 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(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(text)
 returnp._warning({text})
 end

 --[[
 Console warning
 ]]
 functionp.consoleWarning(frame)
 localargs=getArgs(frame)
 mw.addWarning(args[1]orcfg.missing_warning)
 return''
 end

 returnp

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