Jump to content

Module:Mainspace editnotice

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SD0001 (talk | contribs) at 09:40, 28 January 2024 (no need to pass frame around any more). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 function draft_notice(page)
	if page.exists 
		and (page.isRedirect or Disambiguation._isDisambiguationPage(page.fullText)) 
		and mw.title.new('Draft:'..page.fullText).exists then
		return "Draft at"
	end
end

local function blp_notice(page)
	local content = page:getContent()
		
	if content:find("%[%[%s*[Cc]ategory:%s*[Ll]iving[ _]people%s*%]%]") or 
		content:find("%[%[%s*[Cc]ategory:%s*[Pp]ossibly[ _]living[ _]people%s*%]%]") then
		return "BLP editintro"
	end
end

local function disambig_notice(page)
	if Disambiguation._isDisambiguationPage(page.fullText) then
		return "Disambig editintro"
	end
end

local function tfa_notice(page)
	if TfaTitle.is_tfa_on(page.fullText, os.date("%Y-%m-%d")) then
		return "TFA editnotice"
	end
end

local function refideas_notice(page)
	return "Refideas editnotice if exists"
end

p.core = function(page, frame)
	local functions = {draft_notice, blp_notice, disambig_notice, tfa_notice, refideas_notice}
	local text = ''
	for _, getNotice in ipairs(functions) do
		local template = getNotice(page)
		text = text .. (template and frame:expandTemplate{ title = template } or '')
	end
	return text
end

return p