ናብ ትሕዝቶ ኪድ

ሞድዩል:Badges categorization

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

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

local p = { }

local badgesCategory = {
	Q17437796 = 'ዊኪፐድያ:ፍሉያት ጽሑፋት',
	Q17437798 = 'ዊኪፐድያ:ጽቡቕ ጽሑፋት',
}

local linkCategoryPrefix = { 
	default = '',
}

local linkCategorySuffix = { 
	default = ' ኣብ ካልኦት ሕታማት ዊኪፐድያ',
	afwiki = ' ኣብ ዊኪፐድያ ብኣፍሪካንስ',
	amwiki = ' ኣብ ዊኪፐድያ ብኣምሓርኛ',
	arwiki = ' ኣብ ዊኪፐድያ ብዓረብኛ',
	dewiki = ' ኣብ ዊኪፐድያ ብጀርመንኛ',
	elwiki = ' ኣብ ዊኪፐድያ ብግሪኽኛ',
	eswiki = ' ኣብ ዊኪፐድያ ብስጳንኛ',
	simplewiki = ' ኣብ ዊኪፐድያ ብቀሊል እንግሊዝኛ',
	enwiki = ' ኣብ ዊኪፐድያ ብእንግሊዝኛ',
	eowiki = ' ኣብ ዊኪፐድያ ብኤስፐራንቶ',
	frwiki = ' ኣብ ዊኪፐድያ ብፈረንሳይኛ',
	hewiki = ' ኣብ ዊኪፐድያ ብእብራይስጢ',
	hiwiki = ' ኣብ ዊኪፐድያ ብሂንዲ',
	itwiki = ' ኣብ ዊኪፐድያ ብጥልያን',
	jawiki = ' ኣብ ዊኪፐድያ ብጃፓንኛ',
	kowiki = ' ኣብ ዊኪፐድያ ብኮርይኛ',
	nlwiki = ' ኣብ ዊኪፐድያ ብዳች',
	omwiki = ' ኣብ ዊኪፐድያ ብኦሮሞ',
	ptwiki = ' ኣብ ዊኪፐድያ ብፖርቱጊዝኛ',
	quwiki = ' ኣብ ዊኪፐድያ ብቀችዋ',
	ruwiki = ' ኣብ ዊኪፐድያ ብሩስኛ',
	swwiki = ' ኣብ ዊኪፐድያ ብስዋሂሊ',
	thwiki = ' ኣብ ዊኪፐድያ ብታይላንድኛ',
	tiwiki = '',
	trwiki = ' ኣብ ዊኪፐድያ ብቱርክኛ',
	ukwiki = ' ኣብ ዊኪፐድያ ብዩክሬንኛ',
	viwiki = ' ኣብ ዊኪፐድያ ብቬትናምኛ',
	zhwiki = ' ኣብ ዊኪፐድያ ብቻይንኛ',
}

function p.badgesCategories( frame )
	local entity = mw.wikibase.getEntityObject()
	local wikitext = {}
	local categoryNs = mw.site.namespaces[14].name
        if not entity then
                return ''
        end
	
	for siteid, linkTable in pairs( entity.sitelinks ) do
		for i, badgeId in ipairs( entity.sitelinks[ siteid ].badges ) do
			if badgesCategory[ badgeId ] and string.sub(siteid, -4) == 'wiki' then
				local prefix = linkCategoryPrefix[ siteid ] or linkCategoryPrefix.default or ''
				local main = badgesCategory[ badgeId ] or ''
				local suffix = linkCategorySuffix[ siteid ] or linkCategorySuffix.default or ''
				local category = string.format('[[%s:%s]]', categoryNs, prefix .. main .. suffix )
				table.insert( wikitext, category )
			end
		end
	end
	return table.concat( wikitext )
end

function p.hasAnyBadge( frame )
        local entity = mw.wikibase.getEntityObject()
        if not entity then
                return ''
        end
        
        local sitelinks = entity.sitelinks
        
        if not sitelinks then
        	return ''
        end
        for siteid, linkTable in pairs( sitelinks ) do
                if next(sitelinks[ siteid ].badges) ~= nil then
                        return '1'
                end
        end
        return ''
end

return p