Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Mainspace editnotice

Permanently protected module
From Wikipedia, the free encyclopedia

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()

		local living = "%[%[%s*[Cc]ategory:%s*[Ll]iving[ _]people%s*%]%]"
		local possiblyLiving = "%[%[%s*[Cc]ategory:%s*[Pp]ossibly[ _]living[ _]people%s*%]%]"

		if content and (content:find(living) or content:find(possiblyLiving)) then
			return "BLP editnotice"
		end
	end,
	
	disambig_notice = function(page, ctx)
		if ctx.isDisambigPage then
			return "Disambig editnotice"
		end
	end,
	
	tfa_notice = function(page)
		if TfaTitle.today_title() == page.text then
			return "TFA editnotice"
		end
	end,
	
	refideas_notice = function(page)
		local talkContent = page.talkPageTitle:getContent()
		if talkContent and talkContent:match('%{%{[rR]ef ?idea') and not talkContent:match("Refideas%-nonotice") 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)
		if template then
			local template_link = '<div class="editnotice-link" style="clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em;"> <small>[[Template:'..template..'|'..template..']]</small> </div>'
			text = text .. template_link .. frame:expandTemplate{ title = template }
		end
	end

	-- Add a link to view and modify the page's editnotice. 
	-- Not needed if there is no editnotice, because then MediaWiki itself adds 
	-- the link through [[MediaWiki:Editnotice-notext]].
	-- Also skip it if a page editnotice exists, as in that case it probably
	-- adds the link, and we want to avoid a duplicate one.
	if text ~= '' and not mw.title.new('Template:Editnotices/Page/' .. page.fullText).exists then
		text = text .. '<div class="editnotice-link sysop-show templateeditor-show pagemover-show" style="clear: both; float: right; margin: 0px 0.8em; padding: 0; line-height: 1em; display: none"><small>[[Template:Editnotices/Page/'.. page.fullText ..'|Page notice]]</small></div>'
	end
	return text
end

return p