Module:DYK checklist
Appearance
![]() | This module depends on the following other modules: |
![]() | This Lua module is used on approximately 20,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements {{DYK checklist}}. Please see the template page for documentation.
-- This module implements {{DYK checklist}}.
local yesno = require('Module:Yesno')
local params = {
newness = true,
length = true,
eligibilityother = true,
sourced = true,
neutral = true,
plagiarismfree = true,
policyother = true,
hookcited = true,
hookother = true,
hookcited = true,
picfree = true,
picused = true,
picclear = true,
}
local statuses = {
YES = mw.getCurrentFrame():expandTemplate{title = 'y'},
NO = mw.getCurrentFrame():expandTemplate{title = 'n'},
UNKNOWN = mw.getCurrentFrame():expandTemplate{title = 'hmmm'},
}
-- The template for making collapsed sections.
local COLLAPSE_TEMPLATE = [[
{| class="collapsible collapsed" border="1" style="border-collapse:collapse;"
|-
! style="font-weight:normal; " | %s
|-
| %s
|}]]
local p = {}
-- If a value is not present for a canonical key in the args table, check if
-- there is a value for an alias key, and write that value to the canonical
-- key. Then delete the alias key, whether or not a canonical value is present.
-- Called like this: consolidateAliases(args, {
-- canonicalKey1 = {'alias1', 'alias2'},
-- canonicalKey2 = {'anotherAlias1', 'anotherAlias2'},
-- })
-- The args table is altered in place; the function returns nil.
local function consolidateAliases(args, aliases)
for argName, aliases in pairs(aliases) do
for i, alias in ipairs(aliases) do
if not args[argName] and args[alias] then
args[argName] = args[alias]
end
args[alias] = nil
end
end
return nil
end
-- Make a collapsed wikitable with the given header and content.
local function makeCollapsedWikitable(header, content)
return string.format(COLLAPSE_TEMPLATE, header, content)
end
-- Make a bulleted list from an array of strings.
local function makeBulletedList(items)
local ret = {}
for i, item in ipairs(items) do
ret[i] = '* ' .. item
end
return table.concat(ret, '\n')
end
-- Make a checklist item from the given issue and status.
local function makeChecklistItem(issue, status, defaultMarker)
if not status then
return string.format('%s: %s', issue, statuses.UNKNOWN)
elseif yesno(status) then
return string.format('%s: %s', issue, statuses.YES)
else
return string.format(
'%s: %s - %s',
issue,
defaultMarker or statuses.NO,
status
)
end
end
-- Return true if all issues have been resolved; return false otherwise.
-- mainIssues is an array of tables as passed to makeSection. otherIssues is a
-- string value or nil (again, as passed to makeSection).
local function allIssuesAreResolved(mainIssues, otherIssues)
if otherIssues then
return false
end
for i, t in ipairs(mainIssues) do
if t.isResolved == false
or (
t.isResolved ~= true
and yesno(t.status) == false
)
then
return false
end
end
return true
end
-- Assemble a section of the DYK checklist.
local function makeSection(options)
local issues = {}
-- Add main issues
options.mainIssues = options.mainIssues or {}
for i, t in ipairs(options.mainIssues) do
local checklistItem
if t.isResolved then
checklistItem = makeChecklistItem(t.issue, t.status, statuses.YES)
else
checklistItem = makeChecklistItem(t.issue, t.status)
end
table.insert(issues, checklistItem)
end
-- Add other issues
if options.otherIssues then
table.insert(issues, makeChecklistItem('Other problems', options.otherIssues))
end
-- Make the section output.
local content = makeBulletedList(issues)
if allIssuesAreResolved(options.mainIssues, options.otherIssues) then
return makeCollapsedWikitable(options.resolvedHeader, content)
else
return options.unresolvedHeader .. '\n' .. content
end
end
local function makeGeneralEligibilitySection(args)
return makeSection{
unresolvedHeader = "'''General eligiblity:'''",
resolvedHeader = "'''General:''' Article is new enough and long enough",
mainIssues = {
{
issue = '[[Wikipedia:Did you know#New|New Enough]]',
status = args.newness,
},
{
issue = '[[Wikipedia:Did you know#Long enough|Long Enough]]',
status = args.length,
},
},
otherIssues = args.eligibilityother,
}
end
local function makePolicyComplianceSection(args)
return makeSection{
unresolvedHeader = "'''Policy compliance:'''",
resolvedHeader = "'''Policy:''' Article is sourced, neutral, and free of copyright problems",
mainIssues = {
{
issue = '[[Wikipedia:Citing sources|Adequate sourcing]]',
status = args.sourced,
},
{
issue = '[[Wikipedia:NPOV|Neutral]]',
status = args.neutral,
},
{
issue = 'Free of [[Wikipedia:Copyright violations|copyright violations]], [[Wikipedia:Plagiarism|plagiarism]], and [[WP:close paraphrasing|close paraphrasing]]',
status = args.plagiarismfree,
},
},
otherIssues = args.policyother,
}
end
local function makeHookEligibilitySection(args)
-- Deal with AGF special case for hook citations
local hookCiteStatus, isHookSourceAGF
if args.hookcited and args.hookcited:lower() == 'agf' then
hookCiteStatus = 'Offline/paywalled citation accepted in good faith'
isHookSourceAGF = true
else
hookCiteStatus = args.hookcited
isHookSourceAGF = nil -- use default behaviour
end
-- Generate output
return makeSection{
unresolvedHeader = "'''Hook eligiblity:'''",
resolvedHeader = "'''Hook:''' Hook has been verified by provided inline citation",
mainIssues = {
{
issue = '[[Wikipedia:Did you know#Cited hook|Cited]]',
status = hookCiteStatus,
isResolved = isHookSourceAGF
},
{
issue = 'Interesting',
status = args.hookinterest,
},
},
otherIssues = args.hookother,
}
end
local function makeImageEligibilitySection(args)
end
local function makeQPQ(args)
end
function p._main(args)
consolidateAliases(args, {plagiarismfree = {'plagarismfree'}})
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:DYK checklist',
})
return p._main(args)
end
return p