Modulis:Ping2

Dokumentācijas ikona Moduļa dokumentācija[izveidot]
local p = {}

function p.main(frame)
	local output = ''
	local pingees_hidden = {}
	local pingees_visible = {}
	local pframe = frame:getParent()
	
	-- process all usernames
	for i, arg in pairs( pframe.args ) do
		if(arg ~= '') then -- (ignore empty usernames)
			if p.isPingeable(arg) == 1 then
				table.insert(pingees_visible, p.pingUser(arg))
			else -- user created [[Special:MyPage/noping]], to not appear visibly in @ping
				table.insert(pingees_hidden, p.pingUser(arg))
			end
		end
	end
	if (next(pingees_hidden)==nil and next(pingees_visible)==nil) then
		output = "'''<span style='color:red;'>Kļūda! Netika norādīts neviens lietotājs!</span>'''"
	else
		-- fill in the hidden pingees span
		if(#pingees_hidden > 0) then
			mw.log('Invisible pingees are present')
			output = output .. '<span style="display:none;">'
			output = output .. table.concat(pingees_hidden, " ")
			output = output .. '</span>'
		end
		-- fill in the visible pingees, comma separated
		if(#pingees_visible > 0) then
			output = output .. '@'
			output = output .. table.concat(pingees_visible, ", ")
			output = output .. ":"
		end
	end
	return output
end

-- checks whether user created [[Special:MyPage/noping]], to not appear visibly in @ping
function p.isPingeable(username)
    local noError, pageObject = pcall(mw.title.new, 'Lietotājs:' .. username .. '/noping')
    if not noError then
        return nil
    else
        if pageObject.id == 0 then
            return 1
        else
        	return 0
    	end
    end
end

-- returns a ping
function p.pingUser(username)
	string.gsub(username, "&amp;", "&")
	local foo = '[[Lietotājs:' .. username .. '|' .. username .. ']]'
	return foo
	--if p.isPingeable(username) == 0 then
	    --pingtext = '<span style="display:none;>' .. pingtext .. '</span>'
   -- --else
    --	--pingtext = pingtext .. ', '
--	end
--	return pingtext
end

return p