Module:MultiID: Difference between revisions

From WIDEVERSE Wiki
Jump to navigation Jump to search
(allow no)
(No difference)

Revision as of 16:54, 12 July 2019

Documentation for this module may be created at Module:MultiID/doc

local yn = require('Module:Yesno')
local p = {}

function p.main(frame)
	return p._main(frame:getParent().args)
end

function p._main(args)
	local cat = '[[Category:Needs ID]]'
	if args.cat then
		if args.cat == 'n' then
			cat = ''
		else
			cat = string.format('[[Category:%s]]', args.cat)
		end
	end
	local property = mw.text.trim(args[1])
	local ids = args[2]
	if ids == 'no' and not yn(args.nono) then
		return ''
	end
	
	if not (type(ids) == 'string' and ids:match('^[ 0-9,]+$')) then
		return cat
	end
	
	local _ids = mw.text.split(mw.text.trim(ids), '%s*,%s*')
	local props = {
		[property] = _ids
	}
	if not yn(args.noall) then
		props['All '..property] = mw.clone(_ids)
	end
	
	local smw = mw.smw.set(props)
	
	if not smw == true then
		return cat
	end
	return ''
end

return p