Jump to content

Module:If preview/configuration: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
what happens if I callParserFunction
Tag: Reverted
Undid revision 1021485332 by Izno (talk) nope nope nope
Line 6: Line 6:


local function is_preview()
local function is_preview()
local revision_id = frame:callParserFunction('REVISIONID')
local revision_id = frame:preprocess('{{REVISIONID}}')
-- {{REVISIONID}} is usually the empty string when previewed.
-- {{REVISIONID}} is usually the empty string when previewed.
-- I don't know why we're checking for nil but hey, maybe someday things
-- I don't know why we're checking for nil but hey, maybe someday things

Revision as of 00:03, 5 May 2021

--[[
We perform the actual check for whether this is a preview here since
preprocessing is relatively expensive.
]]
local frame = mw.getCurrentFrame()

local function is_preview()
	local revision_id = frame:preprocess('{{REVISIONID}}')
	-- {{REVISIONID}} is usually the empty string when previewed.
	-- I don't know why we're checking for nil but hey, maybe someday things
	-- would have broken
	return revision_id == nil or revision_id == ''
end

local function templatestyles()
	return frame:extensionTag{
		name = 'templatestyles', args = { src = 'Module:If preview/styles.css' }
	}
end

return {
	preview = is_preview(),
	templatestyles = templatestyles(),
	warning_infrastructure = '%s<div class="preview-warning"><strong>Preview warning:</strong> %s</div>',
	missing_warning = 'The template has no warning text. Please add a warning.'
}