Module:DYK queue formatting check
Appearance
-- Verifies [[WP:DYKMOS]]
-- https://en.wikipedia.org/wiki/Wikipedia:Main_Page/Errors#c-Ravenpuff-20250321152600-Current_DYK
local p = {}
local plainText = require("Module:Plain text")._main
local isDisambiguation = require('Module:Disambiguation').isDisambiguation
local getTargetFromText = require('Module:Redirect').getTargetFromText
local function check_link(page)
local title = mw.title.new(page)
local content = title.content
if not content then
return "WP:DYKMOS: The hook must not contain redlinks: " .. page
end
if getTargetFromText(content) then
return "WP:DYKMOS: The hook must not contain redirects: " .. page
end
if isDisambiguation(content) then
return "WP:DYKMOS: The hook must not contain links to " ..
"disambiguation pages: " .. page
end
end
local function check_hook(wikitextLine, expandedLine, hookNumber)
local byteCount = -1 -- Counting ends at the question mark
if wikitextLine:find("''%([^)]+%)''") then
-- The eleven characters in a ''(pictured)'' tag do not count
byteCount = byteCount - 11
end
local boldLinkFound = false
for wikilink in wikitextLine:gmatch("'''%[%[([^]]+)%]%]") do
-- Text in boldlinks after the first do not count toward the limit
if boldLinkFound then
wikilink = wikilink:gsub("[^|]+|", "", 1)
byteCount = byteCount - #wikilink
end
boldLinkFound = true
end
byteCount = byteCount + #expandedLine
if byteCount > 200 then
return "WP:DYK200: The hook cannot exceed 200 prose characters. " ..
"It is currently " .. count .. " characters"
end
if hookNumber ~= 1 then
if wikitextLine:find("''%([^)]+%)''") then
return "WP:DYKIMG/WP:DYKMOS: Extra ''(pictured)'' or alternative"
end
else
if not expandedLine:find("%([^)]+%)") then
return "WP:DYKIMG/WP:DYKMOS: Missing ''(pictured)'' or alternative"
end
-- Parentheses that are not the media marker are
-- allowed if "absolutely unavoidable"
end
-- Disabled for now.
-- [[Special:Diff/1282220073]] could be edited but
-- [[Special:Diff/1281992817]] might be intentional
--if (string.find(wikitextLine, "%]%] *%[%[")
-- or string.find(wikitextLine, "%]%] *'''+ *'''+ *%[%[")) then
-- return "WP:DYKMOS/MOS:SEAOFBLUE: Two non-boldlinks or two " ..
-- "boldlinks must be kept separate: " .. expandedLine
--end
if expandedLine:byte(-1) ~= 46 then -- Not an empty hook in prep area
if not boldLinkFound then
return "WP:DYKMOS: Every eligible article in the hook should be " ..
"linked and wrapped in bold markup"
end
if not wikitextLine:find("%?") then
return "WP:DYKMOS: A hook should end in a question mark"
end
end
if wikitextLine:find("%.%.%.that") then
return "WP:DYKMOS The three dots should be followed by a space"
end
end
function p._check(content)
if content:find("[^[]%[//") or content:find("https?://") then
-- Assuming nobody inserts a [[mw:Help:Links|mailto]] link
return "WP:DYKMOS: The hook must not contain external links"
end
if content:find("|''[^]]+''%]") then
return "WP:DYKMOS: Markup should go on the outside of the link if " ..
"possible"
end
if content:find("%(''[^)]+''%)") then
return "WP:DYKMOS: Note that the italics sit outside the parentheses"
end
if (content:find("[^']''%?")
or content:find("''''%?")
or content:find("[ ;?]%?")) then
return "WP:DYKMOS: There should not be a space before the question " ..
"mark, but if the text directly preceding it is italicized, " ..
"the {{-?}} tag can offset it."
end
if content:find("''s ") then
return "WP:DYKMOS: Keep the bold / italic (or bold italic) text and " ..
"the apostrophe distinct using {{`s}}/{{'s}} respectively"
end
if (content:find("''''{{`") -- Use {{'}} with bold italic
or content:find("[^']''{{`") -- Use {{'}} with italic
or content:find("[^']'''{{'")) then -- Use {{`}} with bold
-- Adapted from [[Template:Quotation mark templates]]
return "WP:DYKMOS: {{`}} (or {{`s}}) is for adjacent bold markup; " ..
"{{'}} (or {{'s}}) is for adjacent italic (or bold italic)"
end
local frame = mw.getCurrentFrame()
local hookCount = 0
-- Counting starts from after the space following the three dots
for wikitextLine in content:gmatch("\n%* %.%.%. ([^\n]*)") do
hookCount = hookCount + 1
local expandedLine = plainText(frame:preprocess(wikitextLine), false)
local hookProblem = check_hook(wikitextLine, expandedLine, hookCount)
if hookProblem then
return hookProblem .. ": " .. expandedLine
end
for page in wikitextLine:gmatch("%[%[([^]|]+)|?[^]]*%]%]") do
local linkProblem = check_link(page)
if linkProblem then
return linkProblem
end
end
end
-- Only humans can check if {{lang}} and {{transl}} are needed i.e. if
-- the "non-English and transliterated text" is in "common English usage"
end
function p.main(frame)
local message = p._check(mw.title.getCurrentTitle().content)
if message then
return require("Module:Error").error{message}
end
end
return p