Module:Mainspace editnotice: Difference between revisions
Appearance
Content deleted Content added
fix refideas_notice when talk page is not present |
further improve structure |
||
Line 10: | Line 10: | ||
end |
end |
||
local |
local notices = { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local function blp_notice(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
blp_notice = function(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local function tfa_notice(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end, |
||
⚫ | |||
disambig_notice = function(page, ctx) |
|||
⚫ | |||
local function refideas_notice(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
tfa_notice = function(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
refideas_notice = function(page) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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 |
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
![]() | This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
This module is for use in Template:Editnotices/Namespace/Main. It conditionally includes other editnotice templates.
It has testcases at Module:Mainspace editnotice/testcases.
Usage
{{#invoke:Mainspace editnotice|main}}
No parameters are required. For testing what editnotice would be generated for a specific page, you can pass |page=
.
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