Module:Category handler/shared

From KitwarePublic
< Module:Category handler
Revision as of 23:19, 12 July 2016 by WikiSysop (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Documentation for this module may be created at Module:Category handler/shared/doc

 1 -- This module contains shared functions used by [[Module:Category handler]]
 2 -- and its submodules.
 3 
 4 local p = {}
 5 
 6 function p.matchesBlacklist(page, blacklist)
 7 	for i, pattern in ipairs(blacklist) do
 8 		local match = mw.ustring.match(page, pattern)
 9 		if match then
10 			return true
11 		end
12 	end
13 	return false
14 end
15 
16 function p.getParamMappings(useLoadData)
17 	local dataPage = 'Module:Namespace detect/data'
18 	if useLoadData then
19 		return mw.loadData(dataPage).mappings
20 	else
21 		return require(dataPage).mappings
22 	end
23 end
24 
25 function p.getNamespaceParameters(titleObj, mappings)
26 	-- We don't use title.nsText for the namespace name because it adds
27 	-- underscores.
28 	local mappingsKey
29 	if titleObj.isTalkPage then
30 		mappingsKey = 'talk'
31 	else
32 		mappingsKey = mw.site.namespaces[titleObj.namespace].name
33 	end
34 	mappingsKey = mw.ustring.lower(mappingsKey)
35 	return mappings[mappingsKey] or {}
36 end
37 
38 return p