local p =
-- List of all columns and their respective header titleslocal table_columns =
-- Mapping of shortnames for task categories and their respective text-- For more information, see User:SuggestBot/Documentation/Task categorieslocal task_map =
-- Mapping of assessment class names to indexes for sortinglocal rating_sort =
-- Mapping of quality levels into imageslocal rating_level = local rating_images =
-- List of task columns in order so we can flag if in need of improvementlocal task_list = -- Mapping of tasks to explanations (used in the image alt-text)local task_explanations = -- Title of the image file we use to flag taskslocal task_image = 'Flag icon red 3.svg'--
-- Hello world to test that the module works...function p.hello_world return "Hello, world!"end
function translate_quality(tbl_row, title, rating, prediction) -- Add a table cell with quality information local qual_lvl = rating_level[prediction] local qual_text = '60px|alt=Quality: ' .. qual_lvl .. ', Assessed class: ' .. rating .. ', Predicted class: ' .. prediction .. '|link=' .. title .. '|Quality: ' .. qual_lvl .. ', Assessed class: ' .. rating .. ', Predicted class: ' .. prediction .. ''
-- Create a table cell with information about article quality local qualcell = tbl_row:tag('td') -- Add the sortkey from mapping predicted class to a number add_sortkey(qualcell, rating_sort[prediction]) qualcell:wikitext(qual_text)end
function add_sortkey(tblcell, value) return tblcell:tag('span') :addClass('sortkey') :wikitext(value)end
function add_tasks(tbl_row, tasks, title) -- For each task we now about, see if it's in task and act accordingly for i, task in ipairs(task_list) do local taskcell = tbl_row:tag('td') if string.find(tasks, task) then add_sortkey(taskcell, '0') taskcell:wikitext('') else add_sortkey(taskcell, '2') end endend
function build_header(tbl) local t_row = tbl:tag('tr') for i, title in ipairs(table_columns) do t_row:tag('th') :attr('scope', 'col') :wikitext(title) :newline endend
function add_row(tbl) -- Adds a suggestion row to the table return tbl:tag('tr') :css('text-align', 'center') :css('height', '30px') :newlineend
function add_cells(tbl_row, tag, title, views, rating, prediction, tasks) -- Add the table cells for the suggestion based on the given parameters local tag_text = task_map[tag] -- First column is number of views tbl_row:tag('td') :css('text-align', 'right') :wikitext(views) -- Second column is article quality translate_quality(tbl_row, title, rating, prediction) -- Third column is a link to the article and its talk page tbl_row:tag('td') :css('text-align', 'left') :wikitext('' .. title .. ' (talk)') -- Fourth through eighth columns are the tasks add_tasks(tbl_row, tasks, title) -- Last column is the article's task category tbl_row:tag('td'):wikitext(task_map[tag])end
function p.build_table(frame) -- Build the entire suggestion table. -- Expects a set of 'n' suggestions, where each suggestion has -- a total of six parameters, in order as follows: -- 1: Task category -- 2: Article title -- 3: Avg. no. of article views/day for past 14 days -- 4: Assessed quality class -- 5: Predicted quality class -- 6: Comma-separated list of tasks to flag -- What language are we talking? local lang = mw.language.getContentLanguage local table = mw.html.create('table') :addClass('wikitable') :addClass('sortable') :css('text-align', 'center') :attr('border', '1') build_header(table)
-- 0-based index of the current article being processed local cur_art = 0
while frame.args[(cur_art * 6) + 1] do local cur_idx = cur_art * 6 local newrow = add_row(table) -- Use the formatnum parser function to format number of views local n_views = lang:formatNum(tonumber(frame.args[cur_idx + 3])) add_cells(newrow, frame.args[cur_idx + 1], frame.args[cur_idx + 2], n_views, frame.args[cur_idx + 4], frame.args[cur_idx + 5], frame.args[cur_idx + 6]) cur_art = cur_art + 1 end
return tostring(table)end
function p.nargs(frame) local i = 0 local output = while frame.args[(i * 6) + 1] do output = output .. 'Processing article ' .. i .. '... ' i = i + 1 end return outputend
return p