Module:If preview/sandbox: Difference between revisions

Content deleted Content added
grammar
import preview_warning from Module:Preview warning
Line 1:
local p = {}
 
--[[
is_preview
 
This function returns a boolean indicating whether the page is a preview.
 
]]
local function is_preview(frame)
local revision_id = frame:preprocess('{{REVISIONID}}')
-- {{REVISIONID}} is usually the empty string when previewed.
ifreturn not revision_id == nil and not revision_id == '' then
end
 
--[[
Line 5 ⟶ 17:
 
This function returns either the first argument or second argument passed to
this module, depending on whether itthe page is being previewed.
 
Usage:
Line 12 ⟶ 24:
]]
function p.main(frame)
if is_preview(frame) then
local revision_id = frame:preprocess('{{REVISIONID}}')
-- {{REVISIONID}} is usually the empty string when previewed.
if not revision_id == nil and not revision_id == '' then
return frame.args[1] or ''
else
return frame.args[2] or ''
end
end
 
--[[
preview_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.
 
Usage:
{{#invoke:If preview|preview_warning|value_if_preview|value_if_not_preview}}
 
]]
function p.warning(frame)
if not is_preview(frame) then return '' end
local warning = frame.args[1]:match('^%s*(.-)%s*$') or ''
if warning == '' then
warning = 'Something is wrong with this template'
end
return mw.ustring.format(
'%s<div class="preview-warning"><strong>Warning:</strong> %s (this message is shown only in preview)</div>',
frame:extensionTag{
name = 'templatestyles', { src = 'Module:Preview warning/styles.css' }
},
warning
)
end