يمكن إنشاء صفحة توثيق الوحدة في وحدة:Sisterlinks/شرح

local p = {}
local getArgs = require('Module:Arguments').getArgs
local entity = nil

local slType = {
	wikt = "[[ملف:Wiktionary-logo-ar-without-text.svg|وصلة=|15بك]] [[:Wikt:%s|تعريفات قاموسية]] في ويكاموس",
	b = "[[ملف:Wikibooks-logo.svg|وصلة=|15بك]] [[:b:%s|كتب]] من ويكي الكتب",
	voy = "[[ملف:Wikivoyage-Logo-v3-icon.svg|وصلة=|15بك]] [[:Voy:%s|رحلات]] من ويكي رحلات",
	w = "[[ملف:Wikipedia-logo-v2.svg|وصلة=|15بك]] [[:w:%s|مقالة]] من ويكيبديا",
	s = "[[ملف:Wikisource-logo.svg|وصلة=|15بك]] [[:s:%s|نصوص مصدرية]] من ويكي مصدر",
	commons = "[[ملف:Commons-logo.svg|وصلة=|15بك]] [[:commons:%s|صور وملفات صوتية]] من كومنز",
	
	gcommons = "[[ملف:Crystal Clear app lphoto commons logo.png|وصلة=|15بك]] [[:commons:%s|معرض صور]] من كومنز",
	
	n = "[[ملف:Wikinews-logo.png|وصلة=|15بك]] [[:n:%s|أخبار]] من ويكي الأخبار.",
	v = "[[ملف:Wikiversity Logo.png|وصلة=|15بك]] [[:v:%s|دروس]] من ويكي الجامعة.",
	spieces = "[[ملف:Wikispecies-logo.svg|وصلة=|15بك]] [[:species:%s|أنواع]] من ويكي أنواع.",
}

local function makeLink(slt, link)
	--mw.log(">>slt:"..slt.." >>>"..mw.dumpObject(slType[slt]))
	if slType[slt] then
		return "\n* "..mw.ustring.format( slType[slt], link ) 
		else return ''
	end
end

local function getEntity( val ) 
	if type(val) == 'table' then
		return val
	end
	if val == '-' then
		return nil
	end
	if val == '' then
		val = nil
	end
	return mw.wikibase.getEntity(val)
end

local function is_defined(s)
	if s and s ~= '' and s ~= 'no' and s ~= '-' then
		return s
	else
		return nil
	end
end

function p._main(args)
	local result = ''
	local currentpage = mw.title.getCurrentTitle()
	local disambigname = mw.ustring.gsub(args.name or currentpage.text, " %b()", "")
	local title = args[1] or disambigname
	
	local commons = args.c or args.commons  or args["كومنز"]
	local source = args.source or args.s or args.wikisource or args.ws or args["مصدر"]
	local books = args.books or args.b or args.wikibooks or args.wbk or args.wb  or args["كتب"]
	local news = args.news or args.n or args.wikinews  or args.wnw  or args["أخبار"]
	local wikipedia = args.wiki or args.w or args.wikipedia or args.w  or args["مقالة"]
	local spieces =  args.wikispecies  or args.species  or args["أنواع"]
	local versity =  args.wikiversity  or args.wvy or args.v  or args["جامعة"]
	local voyage =  args.wikivoyage or args.voyage  or args.voy or args["ويكي الرحلات"]
	local tionary =  args.wiktionary or args.dictionary  or args.wikt or args["قاموس"]
	--				or "Special:Search/"..title
	
	entity = getEntity(entity or args.wikidata or args.wd or args["ويكي بيانات"])
	
	if entity and entity.sitelinks then
	--	mw.log(">>entity: >>>"..mw.dumpObject(entity)..' commons:'..type(entity.sitelinks["commonswiki"]))
	end
	--mw.log(">>args: >>>"..mw.dumpObject(args))
		
	if #args == 0 and (entity == nil or entity.sitelinks == nil) then
		return ''
	end
	
	if entity and entity.claims and entity.claims["P373"] and
		       entity.claims["P373"][1].mainsnak.snaktype == 'value' then
			result = result..makeLink("commons","Category:"..entity.claims["P373"][1].mainsnak.datavalue.value)
		elseif entity and entity.claims and entity.claims["P935"] and
			 entity.claims["P935"][1].mainsnak.snaktype == 'value' then
			result = result..makeLink("gcommons",entity.claims["P935"][1].mainsnak.datavalue.value)
		elseif entity and entity.sitelinks.commonswiki then
			result = result..makeLink("commons",entity.sitelinks.commonswiki.title)
		elseif is_defined(commons) then
		result = result..makeLink("commons","Category:"..commons)
	end
	
	if	entity.sitelinks and entity.sitelinks.arwikisource then
			result = result..makeLink("s",entity.sitelinks.arwikisource.title)
		elseif is_defined(source) then
			result = result..makeLink("s",source)
	end 
	--   
	if	entity and entity.sitelinks and entity.sitelinks.arwikibooks then
			result = result..makeLink("b",entity.sitelinks.arwikibooks.title)
		elseif is_defined(books) then
			result = result..makeLink("b",books)
	end 
	
	if	entity and entity.sitelinks and entity.sitelinks.arwikinews then
			result = result..makeLink("n",entity.sitelinks.arwikinews.title)
		elseif is_defined(news) then
			result = result..makeLink("n",news)
	end 

	if	entity and entity.sitelinks and entity.sitelinks.arwikipedia then
			result = result..makeLink("q",entity.sitelinks.arwikipedia.title)
		elseif is_defined(quote) then
			result = result..makeLink("q",quote)
	end 

	if	entity and entity.sitelinks and entity.sitelinks.arwikiversity then
			result = result..makeLink("v",entity.sitelinks.arwikiversity.title)
		elseif is_defined(versity) then
			result = result..makeLink("v",versity)
	end 
	
	if	entity and entity.sitelinks and entity.sitelinks.specieswiki then
			result = result..makeLink("spieces",entity.sitelinks.specieswiki.title)
		elseif is_defined(spieces) then
			result = result..makeLink("spieces",spieces)
	end 
	
	if entity and entity.sitelinks and entity.sitelinks.arwiktionary then
			result = result..makeLink("wikt",entity.sitelinks.arwiktionary.title)
		elseif is_defined(tionary) then
			result = result..makeLink("wikt",tionary)
	end 
	
	return result
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

return p