יחידה:Sister project links

מתוך ויקיחדשות, מקור החדשות החופשי

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:Sister project links/תיעוד

local projectsTemplate = {
	['wikipedia'] = {
		['logo']='Wikipedia-logo-v2.svg',
		['projectName'] = 'ויקיחדשות',
		['description']='[[ויקיחדשות]]',
		['display']='שפה זו',
		['pageName'] = ''
	},
	['wiktionary'] = {
		['logo']='Wiktionary-logo-he.png',
		['projectName'] = 'ויקימילון',
		['description']='ערך מילוני',
		['display']='וויקימילון',
		['projectPrefix']='wikt'
	},
	['wikiquote'] = {
		['logo']='Wikiquote-logo.svg',
		['projectName'] = 'ויקיציטוט',
		['description']='ציטוטים',
		['display']='וויקיציטוט',
		['projectPrefix']='q'
	},
	['wikibooks'] = {
		['logo']='Wikibooks-logo.svg',
		['projectName'] = 'ויקיספר',
		['description']='ספר לימוד',
		['display']='וויקיספר',
		['projectPrefix']='b'
	},
	['wikisource'] = {
		['logo']='Wikisource-logo.svg',
		['projectName'] = 'ויקיטקסט',
		['description']='טקסט',
		['display']='וויקיטקסט',
		['projectPrefix']='s'
	},
	['wikinews'] = {
		['logo']='Wikinews-logo.svg',
		['projectName'] = 'ויקיחדשות',
		['description']='דיווחים',
		['display']='וויקיחדשות',
		['projectPrefix']='w'
	},
	['wikivoyage'] = {
		['logo']='Wikivoyage-Logo-v3-icon - mirrored.svg',
		['projectName'] = 'ויקימסע',
		['description']='מדריך למטייל',
		['display']='וויקימסע',
		['projectPrefix']='voy'
	},
	['commons'] = {
		['logo']='Commons-logo.svg',
		['projectName'] = 'ויקישיתוף',
		['description']='תמונות ומדיה',
		['display']='וויקישיתוף',
		['projectPrefix']='commons'
	},
	['wikispecies'] = {
		['logo']='Wikispecies-logo.svg',
		['projectName'] = 'ויקימינים',
		['description']='טקסונומיה',
		['display']='וויקימינים',
		['projectPrefix']='wikispecies'
	},
	['meta'] = {
		['logo']='Wikimedia Community Logo.svg',
		['projectName'] = 'מטא-ויקי',
		['description']='דפי מיזמים',
		['display']='מטא-ויקי',
		['projectPrefix']='m'
	},
	['mediawiki'] = {
		['logo']='MediaWiki-2020-logo.svg',
		['projectName'] = 'מדיה-ויקי',
		['description']='דפי התוכנה',
		['display']='מדיה-ויקי',
		['projectPrefix']='mw'
	}
	-- TODO: add other projects
}

function render(frame)
	
	local args = require('Module:Arguments').getArgs(frame)
	local title = mw.title.getCurrentTitle().text
	local projectLinks = {}
	local entity = mw.wikibase.getEntityIdForCurrentPage()
	
	if args['ויקיחדשות'] then
		local t = projectsTemplate['wikipedia']
		t['projectPrefix'] = args['ויקיחדשות']
		t['pageDisplay'] = args['שם ויקיחדשות'] or title
		table.insert(projectLinks, t)
	end
	if args['ויקיחדשות 2'] then
		local t = projectsTemplate['wikipedia']
		t['projectPrefix'] = args['ויקיחדשות 2']
		t['pageDisplay'] = args['שם ויקיחדשות 2'] or title
		table.insert(projectLinks, t)
	end	
	local projects = {
		{
			arg='ויקימילון',
			template='wiktionary',
			name='hewiktionary'
		},
		{
			arg='ויקיציטוט',
			template='wikiquote',
			name='hewikiquote'
		},
		{
			arg='ויקיספר',
			template='wikibooks',
			name='hewikibooks'
		},
		{
			arg='ויקיטקסט',
			template='wikisource',
			name='hewikisource'
		},
		{
			arg='ויקיחדשות',
			template='wikinews',
			name='hewikinews'
		},
		{
			arg='ויקימסע',
			template='wikivoyage',
			name='hewikivoyage'
		},
		{
			arg='ויקישיתוף',
			template='commons',
			name='commons'
		},
		{
			arg='ויקימינים',
			template='wikispecies',
			name='specieswiki'
		},
		{
			arg='מטא-ויקי',
			template='meta',
		},
		{
			arg='מדיה-ויקי',
			template='mediawiki'
		}
	}

	for i, proj in ipairs(projects) do
		-- fetch link from wikidata if not specific
		if entity~=nil and (not args[proj['arg']] or args[proj['arg']]==nil) and proj['name'] then
			if proj['name'] == 'commons' then
				local commonCat = mw.wikibase.getBestStatements( entity, 'P373' )
				commonCat = commonCat and commonCat[1] and commonCat[1].mainsnak and commonCat[1].mainsnak.datavalue and commonCat[1].mainsnak.datavalue.value
				if commonCat~=nil and commonCat~='' then
					commonCat = mw.ustring.format('Category:%s', commonCat)
				end
				args[proj['arg']] = commonCat
				args['שם ' .. proj['arg']] = title
			else
				args[proj['arg']] = mw.wikibase.sitelink(entity, proj['name'])
			end
		end
		if args[proj['arg']] then
			local t = projectsTemplate[proj['template']]
			local defaultDisplayName = args[proj['arg']]
			if proj['arg'] == 'ויקישיתוף' then
				defaultDisplayName = title
			end
			t['pageName'] = args[proj['arg']]
			t['pageDisplay'] = args['שם ' .. proj['arg']] or defaultDisplayName
			
			table.insert(projectLinks, t)
		else
			
		end	

		local i = 2
		local additionalArg = mw.ustring.format('%s %i', proj['arg'], i)
		while args[additionalArg] do
			local t = mw.clone( projectsTemplate[proj['template']] )
			t['pageName'] = args[additionalArg]
			t['pageDisplay'] = args[mw.ustring.format('שם %s %i', proj['arg'], i)] or t['pageName']
			table.insert(projectLinks, t)
			i=i+1
			additionalArg = mw.ustring.format('%s %i', proj['arg'], i)
		end

	end

	local float = 'float: left;'
	if args['1'] == 'ימין' then
		float  = ''
	end
	local root = mw.html.create('table')
	root:addClass('toccolours')
		:addClass('sistersitebox')
		:addClass('plainlinks')
		:addClass('noprint')
		:cssText('margin: 0 1em 0.5em 0;' .. float)
	root:tag('tr'):tag('th'):css('text-align', 'center'):wikitext('מיזמי [[קרן ויקימדיה]]')

	for k,v in pairs(projectLinks) do
		root:tag('tr'):tag('td'):node(renderProject(v))
	end
	return root
end

function renderProject(projectTemplate)
	return mw.html.create('div')
		:addClass('sisterwikilinkT')
		:wikitext(mw.ustring.format("[[File:%s|20px|link=|%s]] %s ב%s: '''[[:%s:%s|%s]]'''", 
			projectTemplate['logo'], projectTemplate['projectName'], 
			projectTemplate['description'], projectTemplate['display'],
			projectTemplate['projectPrefix'], projectTemplate['pageName'], projectTemplate['pageDisplay']))

end

return 	{
	render=render
}