Jump to content

Module:If preview

Permanently protected module
From Wikipedia, the free encyclopedia

localp={}localgetArgs=require("Module:Arguments").getArgslocalyn=require("Module:Yesno")localcfg=mw.loadData('Module:If preview/configuration')--[[mainThis function returns either the first argument or second argument passed tothis module, depending on whether the page is being previewed.]]functionp.main(frame)localargs=getArgs(frame)ifcfg.previewthenreturnargs[1]or''elsereturnargs[2]or''endend--[[pmainThis function returns either the first argument or second argument passed tothis module's parent (i.e. template using this module), depending on whether itis being previewed.]]functionp.pmain(frame)returnp.main(frame:getParent())endlocalfunctionwarning_text(warning)returnmw.ustring.format(cfg.warning_infrastructure,cfg.templatestyles,warning)endfunctionp._warning(args)localwarning=args[1]andargs[1]:match('^%s*(.-)%s*$')or''ifwarning==''thenreturnwarning_text(cfg.missing_warning)endifnotcfg.previewthenreturn''endifyn(args['consolewarning'])thenmw.addWarning(args[1]orcfg.missing_warning)endreturnwarning_text(warning)end--[[warningThis function returns a "preview warning", which is the first argument markedup 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""endmw.addWarning(text)returnp._warning({text})end--[[Console warning]]functionp.consoleWarning(frame)localargs=getArgs(frame)mw.addWarning(args[1]orcfg.missing_warning)return''endreturnp
close