Module:User:SuggestBot/WikiProjects
Appearance
Purpose
This module supports SuggestBot when posting or updating suggestions to WikiProjects, using the design layout of WikiProject X.
Usage
{{#invoke:User:SuggestBot|function_name}}
local wp = {}
-- BTW: Lua allows literal strings declarations [[ ]], but the syntax
-- highlighter doesn't support them properly, fails if the string contains
-- another set of square brackets...
-- List start example, showing what we're aiming to do...
-- Note that the intro-parameter always ends with a '<br />'
local list_start = "{{WPX list start|color={{{2|#086}}}<includeonly>|constrained=yes</includeonly>" ..
"|title=Add sources|intro=See [[Wikipedia:Citing sources]] for more information.<br />" ..
"{{WPX last updated|Wikipedia:WikiProject_Ghana/Tasks/SuggestBot}}}}"
local list_item = "{{WPX article recommendation|color={{{1|#37f}}}|title = Jay Q | rating = 1" ..
"| rating_description = Quality: Low, Assessed class: Start, Predicted class: Stub" ..
"| pageviews = 4 | needs = More content, more images, more wikilinks, more sources}}"
local list_end= "{{WPX list end|more=Wikipedia:WikiProject_Ghana/Tasks/SuggestBot#Add_sources}}"
-- Mapping of SuggestBot's task categories (see [[User:SuggestBot/Documentation/Task categories]])
-- to section titles and descriptions, and the order in which they will be presented
local taskcat_order = {'source', 'cleanup', 'expand', 'unenc',
'merge', 'wikify', 'orphan', 'stub'}
local taskcat_map = {
source={
title='Add sources',
descr='See [[Wikipedia:Citing sources]] for more information.<br />'
},
cleanup={
title='Cleanup',
descr='Improve the presentation of content.'
},
expand={
title='Expand',
descr='Add more information to these articles.'
},
unenc={
title='Unencyclopaedic',
descr='Remove content that is not relevant for an encyclopaedia.'
},
merge={
title='Merge',
descr='Should this article be merged with another article?'
},
wikify={
title='Wikify',
descr='Improve the wiki-formatting on this article.'
},
orphan={
title='Orphan',
descr='Few or no articles link to this article.'
},
stub={
title='Stub',
descr='Expand on this brief article.'
}
}
-- Local support functions follow below
local function has_key(tbl, key)
-- Check if the given table has the given key
return tbl[key] ~= nil
end
local function sort_articles(arglist, task_cats)
-- Sort the given argument list into a table mapping task categories
-- to a list of articles in that task category.
local sorted_arts = {}
for i, task_cat in pairs(task_cats) do
sorted_arts[task_cat] = {}
end
-- What language are we talking?
local lang = mw.language.getContentLanguage()
-- 0-based index of the current article being processed
local cur_art = 0
while arglist[(cur_art * 6) + 1] do
local cur_idx = cur_art * 6
local task_cat = cur_idx + 1
-- Do we have this task category in our table?
if sorted_arts[task_cat] then
table.insert(sorted_arts[task_cat], {
tag=task_cat, title=arglist[cur_idx + 2],
views=lang:formatNum(tonumber(arglist[cur_idx + 3])),
cur_qual=arglist[cur_idx + 4],
pred_qual=arglist[cur_idx + 5],
tasks=arglist[cur_idx + 6]
})
end
end
return sorted_arts
end
-- Globally exposed functions follow below
function wp.suggestions(frame)
-- Process the suggested articles given in the frame's arguments
-- and build lists of articles for each task category defined in the global
-- list of categories above.
-- Keyword arguments:
-- * is_included=yes: passed in to limit lists to two items each when
-- the page of the call is transcluded
-- * list_col=[colour value]: defines the CSS colour value of list headers
-- * item_col=[colour value]: defines the CSS colour value of list items
--
-- The rest of the arguments are sets of six parameters describing each
-- suggested article, as follows:
-- 1: task category
-- 2: article title
-- 3: number of average views/day (14 days prior to the update)
-- 4: assessed quality
-- 5: predicted quality
-- 6: comma-separated list of specific tasks for improving this article
local sorted_articles = sort_articles(frame.args, taskcat_order)
return "Hello world!"
end
function wp.hello(frame)
return "Hello World!"
end
function wp.test_args(frame)
result = "The method got the following arguments:"
if has_key(frame, 'is_included') then
result = result .. "\n* is_included" .. frame.args['is_included']
end
for k, v in pairs(frame.args) do
result = result .. "\n* " .. k .. "=" .. v
end
return result
end
return wp