Difference between revisions of "Module:PastWikithons"

From BASAbaliWiki
Line 1: Line 1:
 
local p = {}
 
local p = {}
 +
local competitions = {}
 +
 +
function addToSet(set, key)
 +
    set[key] = true
 +
end
 +
 +
function removeFromSet(set, key)
 +
    set[key] = nil
 +
end
 +
 +
function setContains(set, key)
 +
    return set[key] ~= nil
 +
end
  
 
function p.display( frame )
 
function p.display( frame )
Line 13: Line 26:
 
if result and #result then
 
if result and #result then
 
for num, entityData in pairs( result ) do
 
for num, entityData in pairs( result ) do
html = html .. entityData['Competition']
+
local c = entityData['Competition']
 +
if not setContains(competitions, c) then
 +
addToSet(competitions, c)
 +
end
 
end
 
end
 +
end
 +
for i, v in pairs( competitions ) do
 +
html = html .. v
 
end
 
end
 
     return html
 
     return html

Revision as of 13:43, 9 July 2024

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

local p = {}
local competitions = {}

function addToSet(set, key)
    set[key] = true
end

function removeFromSet(set, key)
    set[key] = nil
end

function setContains(set, key)
    return set[key] ~= nil
end

function p.display( frame )
	html = ''
	-- https://github.com/SemanticMediaWiki/SemanticScribunto/blob/master/docs/README.md
	local result = mw.smw.ask {
    	'[[Category:Article]]',
    	'[[Competition::+]]',
    	'?Competition',
    	limit = 10,
    	mainlabel = '-'
	}
	if result and #result then
		for num, entityData in pairs( result ) do
			local c = entityData['Competition']
			if not setContains(competitions, c) then
				addToSet(competitions, c)
			end
		end
	end
	for i, v in pairs( competitions ) do
		html = html .. v
	end
    return html
end

return p