Module:Categories by district

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules


The module is proposed for navigation templates of regions. The module generates categories for the page with the navigation template. The page name looks like TOPIC in DISTRICT. Based on this name, the parent category for the topic in the region and the parent category for the super-topic of the district are substituted.

Usage

[edit]

{{#invoke:Categories by district|cat|prefix=cat_prefix|parent=parent_cat|region=region_title}}


Code

local p = {}

function p.cat(frame)
	local pagename = frame:preprocess('{{PAGENAME}}')
	local prefix = frame.args['prefix'] or '';
	local parent = frame.args['parent'] or '';
	if (#prefix==0 and #parent==0) then
		return ''
	end
	local topic_cat = parent .. ' ' .. string.sub(pagename, #prefix + 2)
	local parent_cat = prefix .. ' ' .. frame.args['region']
	return frame:preprocess(string.format('[[Category:%s|*]]\n[[Category:%s|*]]', topic_cat, parent_cat))
end

return p