Hopp til innhold

Modul:Autocategories

Fra Wikipedia, den frie encyklopedi
Moduldokumentasjon
-- module for replicating categories listed at Wikidata
-- © John Erling Blad, Creative Commons by Attribution 3.0

-- don't pollute with globals
require('Module:No globals')

-- find the P-ids from the argument lists
-- @param table frames forwarded from the method call
-- @return table hash of matching arguments
local function findPids( ... )
	local pids = {}
	for _,frame in ipairs( arg ) do
		for _,value in pairs( frame.args ) do
			local action,pid,count = string.match(value, '^%s(!?)(P%d+)%s*$')
			if pid then
				pids[pid] =  action == '' and true or nil
			end
		end
	end
	return pids
end

-- @var our exposed table
local Autocategories = {}

-- do all allowable categorizations
-- @param table frame arguments from invoke
-- @return string status report during development, should be an empty string
function Autocategories.run( frame )
	--first call is when the call is encapsulated in a template
	local pids = frame:getParent() and findPids( frame.args, frame:getParent().args ) or findPids( frame.args )
	return table.concat( pids, ', ' )
end

-- export the accesspoint
return Autocategories