Module:Article history/config: Difference between revisions

Content deleted Content added
put class config in the order of the classes in the main module
add featured topic code
Line 377:
 
notices = {
-- Featured topics
{
function (articleHistoryObj)
param = 'ftname'
local args = articleHistoryObj.args
}
local prefixArgs = articleHistoryObj.prefixArgs
local article = articleHistoryObj.currentTitle.subjectPageTitle.prefixedText
 
-- Exit if no featured topic parameters were given.
if not args.ftname and not prefixArgs.ft then
return nil
end
 
-- Assemble data about all of the featured topics.
local topics = {}
do
local getTopicStatus = require('Module:FeaturedTopicSum').status
local yesno = require('Module:Yesno')
local function makeTopicData(name, isMain, paramNum)
if name then
return {
name = name,
isMain = yesno(isMain) or false,
status = getTopicStatus(name),
paramNum = paramNum
}
elseif isMain then
local num = paramNum and tostring(paramNum) or ''
articleHistoryObj:raiseError(
string.format(
"parameter 'ft%smain' is set, but no featured " ..
"topic name is set in parameter 'ft%sname'",
num, num
),
'Template:Article history#Errors'
)
else
return nil
end
end
topics[#topics + 1] = makeTopicData(args.ftname, args.ftmain)
if prefixArgs.ft then
for i = 2, #prefixArgs.ft do -- we use args.ftname instead of args.ft1name
local t = prefixArgs.ft[i]
topics[#topics + 1] = makeTopicData(t.name, t.main, t[1])
end
end
end
 
-- Check for rogue ft.. parameters
if #topics < 1 then
articleHistoryObj:raiseError(
"a parameter starting with 'ft' was detected, but no " ..
"featured topic names were specified; " ..
"please check the parameter names",
'Template:Article history#Errors'
)
end
 
local ret = {}
 
-- Get the icon
do
local isFeatured = false
for _, topic in ipairs(topics) do
if status == 'FT' then
isFeatured = true
break
end
end
if isFeatured then
ret.icon = 'Cscr-featuredtopic.svg'
ret.iconCaption = 'Featured topic star'
else
ret.icon = 'Support cluster.svg'
ret.iconCaption = 'Good topic star'
end
ret.iconSize = '48px'
ret.iconSmallSize = '30px'
end
 
-- Make the text
do
local firstBlurb = "'''%s''' is %s the '''[[Wikipedia:Featured topics/%s|%s]] series''', %s."
local otherBlurb = "It is also %s the '''[[Wikipedia:Featured topics/%s|%s]] series''', %s."
local finalBlurb = "%s identified as among the best series of " ..
"articles produced by the [[Wikipedia:Wikipedians|Wikipedia community]]. " ..
"If you can update or improve %s, [[Wikipedia:Be bold|please do so]]."
local main = 'the main article in'
local notMain = 'part of'
local featuredLink = 'a [[Wikipedia:Featured topics|featured topic]]'
local featuredNoLink = 'a featured topic'
local goodLink = 'a [[Wikipedia:Good topics|good topic]]'
local goodNoLink = 'a good topic'
local thisSingular = 'This is'
local thisPlural = 'These are'
local itSingular = 'it'
local itPlural = 'them'
 
local hasFeaturedLink = false
local hasGoodLink = false
local text = {}
-- First topic
do
local topic = topics[1]
local link
if topic.status == 'FT' then
link = featuredLink
hasFeaturedLink = true
else
link = goodLink
hasGoodLink = true
end
text[#text + 1] = string.format(
firstBlurb,
article,
topic.isMain and main or notMain,
topic.name,
topic.name,
link
)
end
 
-- Other topics
for i = 2, #topics do
local topic = topics[i]
local link
if topic.status == 'FT' then
if hasFeaturedLink then
link = featuredNoLink
else
link = featuredLink
hasFeaturedLink = true
end
else
if hasGoodLink then
link = goodNoLink
else
link = goodLink
hasGoodLink = true
end
end
text[#text + 1] = string.format(
otherBlurb,
topic.isMain and main or notMain,
topic.name,
topic.name,
link
)
end
 
-- Final blurb
do
isPlural = #topics > 1
text[#text + 1] = string.format(
finalBlurb,
isPlural and thisPlural or thisSingular,
isPlural and itPlural or itSingular
)
end
 
ret.text = table.concat(text, ' ')
end
 
-- Categories
do
local cats = {}
local status = articleHistoryObj:getStatusId()
 
local function addCat(cat, sort)
cats[#cats + 1] = Category.new(cat, sort)
end
 
-- Page-wide status categories
if status == 'FA' then
addcat('FA-Class Featured topics articles')
elseif status == 'FL' then
addCat('FL-Class Featured topics articles')
elseif status == 'FFA/GA' or status == 'GA' then
addCat('GA-Class Featured topics articles')
else
addCat('Unassessed Featured topics articles')
end
 
-- Topic-specific status categories
local function addTopicCats(catFormat)
for i, topic in ipairs(topics) do
addCat(string.format(catFormat, topic.name))
end
end
if status == 'FA' or status == 'FL' then
addTopicCats('Wikipedia featured topics %s featured content')
elseif status == 'FFA/GA' or 'GA' then
addTopicCats('Wikipedia featured topics %s good content')
else
addTopicCats('Wikipedia featured topics %s')
end
 
-- Importance categories
local hasTop, hasHigh, hasMid, hasLow -- These check for dupes
for i, topic in ipairs(topics) do
local cat, sort
if topic.status == 'FT' then
if topic.isMain and not hasTop then
cat = 'Top-importance Featured topics articles'
sort = topic.name .. ' ' .. article
hasTop = true
elseif not topic.isMain and not hasHigh then
cat = 'High-importance Featured topics articles'
hasHigh = true
end
else
if topic.isMain and not hasMid then
cat = 'Mid-importance Featured topics articles'
sort = topic.name .. ' ' .. article
hasMid = true
elseif not topic.isMain and not hasLow then
cat = 'Low-importance Featured topics articles'
hasLow = true
end
end
if cat then
addCat(cat, sort)
end
end
 
ret.categories = cats
end
 
return ret
end,
},