Module:Article history/config: Difference between revisions

Content deleted Content added
remove unnecessary mw.language.getContentLanguage call
new format for the DYK object
Line 1,461:
collapsibleNotices = {
-- DYK
{
function (articleHistoryObj)
id = 'DYK',
local args = articleHistoryObj.args
icon = 'DYK questionmark icon.svg',
local prefixArgs = articleHistoryObj.prefixArgs
iconCaption = 'Did You Know',
isActive = function (articleHistoryObj)
local args = articleHistoryObj.args
local prefixArgs = articleHistoryObj.prefixArgs
return not args.dykdate and not args.dykdate2 and not prefixArgs.dyk
end,
makeData = function (articleHistoryObj)
local args = articleHistoryObj.args
local prefixArgs = articleHistoryObj.prefixArgs
 
-- Sanity checks
if not args.dykdate and not prefixArgs.dyk then
for _, t in ipairs(prefixArgs.dyk) do
return nil
if not t.date then
end
articleHistoryObj:raiseError(
if prefixArgs.dyk then
string.format(
for _, t in ipairs(prefixArgs.dyk) do
"an argument starting with 'dyk%d' was detected, " ..
if not t.date then
"but no 'dyk%ddate' parameter was specified",
t[1], t[1]
),
'Template:Article history#Errors'
)
end
end
end
 
local function validateDate(key, date)
local longDate = getLongDate(date)
if longDate then
return longDate
else
articleHistoryObj:raiseError(
string.format(
"aninvalid argument starting withdate 'dyk%ds' was detected, "in ..parameter '%s'",
tostring(date),
"but no 'dyk%ddate' parameter was specified",
t[1], t[1]key
),
'Template:Article history#Errors'
Line 1,482 ⟶ 1,505:
end
end
end
 
local functiondata validateDate(key,= date){}
 
local longDate = getLongDate(date)
if-- longDateOrganise thenthe input
if args.dykdate then
return longDate
data[#data + 1] = {
else
date = validateDate('dykdate', args.dykdate),
articleHistoryObj:raiseError(
stringentry = args.format(dykentry
}
"invalid date '%s' detected in parameter '%s'",
end
tostring(date),
if args.dykdate2 then
key
data[#data + 1] = {
),
date = validateDate('dykdate2', args.dykdate2),
entry = args.dykentry2
}
articleHistoryObj:addWarning(
"the 'dykdate2' and 'dykentry2' parameters are " ..
"deprecated; use 'dyk2date' and 'dyk2entry' instead",
'Template:Article history#Errors'
)
end
if prefixArgs.dyk then
end
for _, t in ipairs(prefixArgs.dyk) do
 
local data[#data ret,+ dyks1] = {}, {}
date = validateDate('dyk' .. t[1] .. 'date', t.date),
 
entry = t.entry
-- Organise the input
}
if args.dykdate then
end
dyks[#dyks + 1] = {
end
date = validateDate('dykdate', args.dykdate),
if #data < 1 then
entry = args.dykentry
error('no DYKs found and parameter checks failed')
}
end
if args.dykdate2 then
dyks[#dyks + 1] = {
date = validateDate('dykdate2', args.dykdate2),
entry = args.dykentry2
}
articleHistoryObj:addWarning(
"the 'dykdate2' and 'dykentry2' parameters are " ..
"deprecated; use 'dyk2date' and 'dyk2entry' instead",
'Template:Article history#Errors'
)
end
if prefixArgs.dyk then
for _, t in ipairs(prefixArgs.dyk) do
dyks[#dyks + 1] = {
date = validateDate('dyk' .. t[1] .. 'date', t.date),
entry = t.entry
}
end
end
if #dyks < 1 then
error('no DYKs found and parameter checks failed')
end
 
-- Icon
ret.icon = 'DYK questionmark icon.svg'
ret.iconCaption = 'Did You Know'
 
-- return Textdata
doend,
text = function (articleHistoryObj, collapsibleNoticeObj)
local text = {} -- Normal text
local data = collapsibleNoticeObj:getData()
local text = {}
 
local raPage
do
raPage = 'Wikipedia:Recent additions/'
.. getDate('Y/F#j F Y', dyksdata[1].date)
local raTitle = makeTitle(raPage)
if not raTitle or not raTitle.exists then
Line 1,550 ⟶ 1,554:
end
 
text[#text + 1] = 'A [['string.format(
"A [[%s|'''fact from this article''']] appeared on Wikipedia's " ..
text[#text + 1] = raPage
"[[Main Page]] in the ''\"[[:Template:Did you know|Did you know?]]\"'' column ",
text[#text + 1] = "|'''fact from this article''']] appeared on "
raPage
text[#text + 1] = "Wikipedia's [[Main Page]] in the "
)
text[#text + 1] = "''\"[[:Template:Did you know|Did you know?]]\"'' column "
 
local dates = {}
for i, t in ipairs(dyksdata) do
dates[i] = 'on ' .. t.date
end
Line 1,563 ⟶ 1,567:
text[#text + 1] = '.'
ret.text =return table.concat(text)
end,
collapsibleText = function (articleHistoryObj, collapsibleNoticeObj)
 
local data = collapsibleNoticeObj:getData()
-- Collapsible text
do
local ctext = {}
if #dyksdata == 1 and dyksdata[1].entry then
ctext[#ctext + 1] = string.format(
"The text of the entry was: ''Did you know %s''",
dyksdata[1].entry
)
else
local entries = {}
local lastEntryDate
for i, t in ipairs(dyksdata) do
entries[#entries + 1] = t.entry
lastEntryDate = t.date
Line 1,589 ⟶ 1,592:
ctext[#ctext + 1] = 'The text of the entries was:\n'
local list = mw.html.create('ul')
for i, t in ipairs(dyksdata) do
if t.entry then
list:tag('li'):wikitext(string.format(
Line 1,601 ⟶ 1,604:
end
if #ctext > 0 then
ret.collapsibleText =return table.concat(ctext)
else
return nil
end
end,
categories = function (articleHistoryObj, collapsibleNoticeObj)
-- Categories
do
local cats = {}
local status = articleHistoryObj:getStatusId()
Line 1,620 ⟶ 1,623:
end
cats[1] = Category.new(cat)
ret.categories =return cats
end
}
 
return ret
end
},