Jump to content

Module:User:SuggestBot/WikiProjects

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nettrom (talk | contribs) at 22:47, 11 August 2015 (add function to sort the suggested articles). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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}}}}"

-- 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.
	
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