ሞድዩል:Flag

ካብ ዊኪፐድያ፣ ናጻ ኢንሳይክሎፐድያ

Documentation for this module may be created at ሞድዩል:Flag/doc

local p = {}
local wikidata = require('Module:Wikidata')

function getStatements(entity)
    local statements =  wikidata.getStatements(entity)
    mw.log(statements)
    return statements
end

function getFlags(entity)
    local options = {property = 'P41', highestRank = 'yes', entityId = entity}
    return wikidata.getProperty(options)

end

function getName(entity, name)
    local options = {label = name or 'null'}
    local name = wikidata.entityIdFormat(entity, options)
    return name
end 

function p.luaFlag(entityId, size, option, name)
	local flagString
    local flag = getFlags(entityId)
    if size == nil or size == '' then
    	size = '20px'
    end
    local option = option or ''
    local name = getName(entityId, name)

    if flag and flag ~= '' then
        flagString = '[[ፋይል:'..flag..'|' .. size .. '| border]]'
    end
    if option == 'only flag' and  flagString then 
        return flagString -- Will only return the flag
    elseif flagString then   
        return flagString .." " .. name -- Returns the flag next to the name
    else -- There is no value in property P41
        return name -- Just return the name
    end

end

function p.flag(frame)
    return p.luaFlag(frame.args[1], frame.args[2],frame.args[3] , frame.args.name)
end

-- Function to remove flags from text
function p.withoutFlag(text)
	local result
	
 	if text then
 		result = text
 		result = result:gsub('<span class="flagicon">.-</span>&nbsp;', '')  
 		result = result:gsub('<span class="flagicon">.-</span>[%s]*', '')
 		result = result:gsub('%[%[[aA][rR][cC][hH][iI][vV][oO]:.-%]%][%s]*', '')
 		result = result:gsub('%[%[[fF][iI][lL][eE]:.-%]%][%s]*', '')
 		mw.logObject(result)
 		return result
 	end
end

function p.callFromATemplate(frame)
	local args = frame.args
	
	local feature = p[args[1]]

	return feature(args[2], args[3], args[4])
end

return p