Jump to content

Module:Mainspace editnotice: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix refideas_notice when talk page is not present
further improve structure
Line 10: Line 10:
end
end


local function draft_notice(page, ctx)
local notices = {
if page.exists
and (page.isRedirect or ctx.isDisambigPage)
and mw.title.new('Draft:'..page.fullText).exists then
return "Draft at"
end
end

local function blp_notice(page)
local content = page:getContent()
draft_notice = function (page, ctx)
-- Check for [[Category:Living people]] or [[Category:Possibly living people]]
if page.exists
if content:find("%[%[%s*[Cc]ategory:%s*([Pp]ossibly[ _])?[Ll]iving[ _]people%s*%]%]") then
and (page.isRedirect or ctx.isDisambigPage)
return "BLP editintro"
and mw.title.new('Draft:'..page.fullText).exists then
end
return "Draft at"
end
end

end,
local function disambig_notice(page, ctx)
if ctx.isDisambigPage then
blp_notice = function(page)
return "Disambig editintro"
local content = page:getContent()
end
end
-- Check for [[Category:Living people]] or [[Category:Possibly living people]]

if content:find("%[%[%s*[Cc]ategory:%s*([Pp]ossibly[ _])?[Ll]iving[ _]people%s*%]%]") then
local function tfa_notice(page)
return "BLP editintro"
if TfaTitle.is_tfa_on(page.fullText, os.date("%Y-%m-%d")) then
end
return "TFA editnotice"
end
end,
end
disambig_notice = function(page, ctx)

if ctx.isDisambigPage then
local function refideas_notice(page)
return "Disambig editintro"
local talkContent = page.talkPageTitle:getContent()
end
if talkContent and talkContent:match('%{%{[rR]ef ?idea') then
end,
return "Refideas editnotice"
end
tfa_notice = function(page)
end
if TfaTitle.is_tfa_on(page.fullText, os.date("%Y-%m-%d")) then
return "TFA editnotice"
end
end,
refideas_notice = function(page)
local talkContent = page.talkPageTitle:getContent()
if talkContent and talkContent:match('%{%{[rR]ef ?idea') then
return "Refideas editnotice"
end
end,
}


p.core = function(page, frame)
p.core = function(page, frame)
Line 53: Line 56:
}
}


local functions = {draft_notice, blp_notice, disambig_notice, tfa_notice, refideas_notice}
local text = ''
local text = ''
for _, getNotice in ipairs(functions) do
for _, getNotice in pairs(notices) do
local template = getNotice(page, context)
local template = getNotice(page, context)
text = text .. (template and frame:expandTemplate{ title = template } or '')
text = text .. (template and frame:expandTemplate{ title = template } or '')

Revision as of 13:36, 29 January 2024

local Arguments = require('Module:Arguments')
local Disambiguation = require('Module:Disambiguation')
local TfaTitle = require('Module:TFA title')

local p = {}

p.main = function(frame)
	local args = Arguments.getArgs(frame)
	return p.core(args.page and mw.title.new(args.page) or mw.title.getCurrentTitle(), frame)
end

local notices = {
	
	draft_notice = function (page, ctx)
		if page.exists 
			and (page.isRedirect or ctx.isDisambigPage) 
			and mw.title.new('Draft:'..page.fullText).exists then
			return "Draft at"
		end
	end,
	
	blp_notice = function(page)
		local content = page:getContent()
	
		-- Check for [[Category:Living people]] or [[Category:Possibly living people]]
		if content:find("%[%[%s*[Cc]ategory:%s*([Pp]ossibly[ _])?[Ll]iving[ _]people%s*%]%]") then
			return "BLP editintro"
		end
	end,
	
	disambig_notice = function(page, ctx)
		if ctx.isDisambigPage then
			return "Disambig editintro"
		end
	end,
	
	tfa_notice = function(page)
		if TfaTitle.is_tfa_on(page.fullText, os.date("%Y-%m-%d")) then
			return "TFA editnotice"
		end
	end,
	
	refideas_notice = function(page)
		local talkContent = page.talkPageTitle:getContent()
		if talkContent and talkContent:match('%{%{[rR]ef ?idea') then
			return "Refideas editnotice"
		end
	end,
}

p.core = function(page, frame)
	-- Context object to store values that are expensive to compute and required
	-- in multiple places
	local context = {
		isDisambigPage = Disambiguation._isDisambiguationPage(page.fullText)
	}

	local text = ''
	for _, getNotice in pairs(notices) do
		local template = getNotice(page, context)
		text = text .. (template and frame:expandTemplate{ title = template } or '')
	end
	return text
end

return p