Jump to content
Wikimedia Meta-Wiki

Module:If preview

From Meta, a Wikimedia project coordination wiki
Module documentation
You might want to create a documentation page for this Scribunto module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Please 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')

 --[[
 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 によって変換されたページ (->オリジナル) /