Modul:Sportperson WD

Från Wikipedia
Hoppa till navigering Hoppa till sök

Template-info.png Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


Detta är en modul för att information om sportperson (för närvarande volleybollspelare), som spelposition och under vilken tid de spelat för olika klubbar och landslag. Modulen hämtdata uppgifter från Wikidata och lägger in det i en Mall:Faktamall. Den anropas genom att lägga in {{#Invoke:Sportperson WD | person}} i artikeln.

Modulen är för närvarande under utveckling och finns bara inlagd på ett begränsat antal artikelsidor. Undvik att lägga in den i artiklar i någon större omfattning tills vidare, tills utformningen blivit mer stabil. Den består av följande delar:

  • Personlig data (bild, namn, födelsedatum och ort). Uppgifterna hämtas från motsvarande uppgifter i Wikidata.
  • Uppgifter om klubbar som personen spelat för. Detta omfattar dels:
    • Klubbarna personen har spelat för med start och slutår. Uppgifterna hämtas från motsvarande uppgifter i Wikidata, med årtalen som bestämning.
    • Resultat för klubbarna som personen har spelat för (placering, typ av tävling och tid för tävlingsupplagan). Uppgifter från dess hämtas från uppgiften "deltog i" från Wikidata. Koden läser av klubbens placering i tävlingen samt tiden för tävlingen genom att läsa av uppgifter från tävlingens wikidata-objekt. Om relevanta uppgifter inte finns anpassas visningen så att infoboxen blir så lättläst som möjligt.
  • Uppgifter om landslag som personen spelat för. Denna är uppdelad på samma sätt som för klubblagen (och hämtar sin data på motsvarande sätt), d.v.s.:
    • Landslagen personen har spelat för med start och slutår.
    • Resultat för landslagen som personen har spelat för.
  • Individuella utmärkelser. Uppgifterna hämtas från motsvarande uppgifter i Wikidata.

För alla delar förutom personlig data gäller att de bara visas i infoboxen om det finns några inlagda uppgifter (t.ex. visas inte individuella utmärkelser om det inte finns några inlagda).

p = {}
local wd = require( 'Modul:Referenshantering' )

p.iRefcounter=0

--Labels & Headers
txtBirthDate='Födelsedatum'
txtBirthPlace='Födelseplats'
txtPlayerPosition='Spelarposition'
txtClubTeamHeader='Klubbspel'
txtClubTeamResultHeader='Meriter'
txtNationalTeamHeader='Landslagspel'
txtNationalTeamResultHeader='Meriter'
txtIndividualAwards='Individuella utmärkelser'

txtCompetitionHeader="Tävling"
txtSeasonHeader="År"
txtMatches="Matcher"
txtPoints="Poäng"

txtPositionHeader='Plats'

--For templates
txtInfoboxTemplate='Faktamall'
txtAgeTemplate='Ålder'

txtLabel='etikett'
txtContent='innehåll'

txtTeamHeaderStyle='bgcolor="#eaecf0" align="center"'

txtEditComment='Redigera uppgifter i faktarutan'

--For Layout
txtStyleMain='background:orange;'
txtStyleLevel2='background:gold'
txtWidth_px='240px'

edit_message = mw.message.new('vector-view-edit'):plain()

function txtEditPen(iEntity,iProperty)
	return '<sup class="noprint Inline-Template">&nbsp;[[File:Arbcom_ru_editing.svg|' 
	                   	.. edit_message .. '|8px|baseline|class=noviewer|link=https://www.wikidata.org/wiki/' 
	                   	.. iEntity .. '#' .. iProperty .. ']]</sup>'
end


function getOneValue(entity,txtProperty)
	statements=entity:getBestStatements( txtProperty)
	if next(statements)==nil then
		return nil
		else
		return getLabelByEntity(statements[1]['mainsnak']['datavalue']['value']['id'])
		end
	end

function getOneEntityId(entity,txtProperty)
	statements=entity:getBestStatements( txtProperty)
	if next(statements)==nil then
		return nil
		else
		return statements[1]['mainsnak']['datavalue']['value']['id']
		end
	end

p.person = function(frame)
	entityid=mw.wikibase.getEntityIdForCurrentPage()
	entity=mw.wikibase.getEntity(entityid) 	
	wdTitle=getLabelByEntity( entityid )
    myArgs={titel=wdTitle}
	img=entity:getBestStatements( 'P18' )
	if next(img) then
		wdImage = img[1]['mainsnak']['datavalue']['value']
	    myArgs['bild']='[[File:' .. wdImage .. '|' .. txtWidth_px .. ']]' ..  txtEditPen(entityid,'P18')
	end
    myArgs['rubrikstil'] = txtStyleMain
    iCounter=0
	entityBirthDate=entity:getBestStatements( 'P569' )
	if next(entityBirthDate) then
    	iCounter=iCounter+1
		txtBirthData = entity:getBestStatements( 'P569' )[1].mainsnak.datavalue.value.time
		txtBirthYear = string.sub(txtBirthData,2,5)
		txtBirthMonth = string.sub(txtBirthData,7,8)
		txtBirthDay = string.sub(txtBirthData,10,11)
	    myArgs[txtLabel .. iCounter]=txtBirthDate
    	myArgs[txtContent  .. iCounter]=frame:expandTemplate{ title = txtAgeTemplate, args = { txtBirthYear, txtBirthMonth, txtBirthDay }} .. processAllRefsForItemWD(frame,entityBirthDate[1].references,entityid,'P569') ..  txtEditPen(entityid,'P569')
	end
    idPlace=getOneEntityId(entity,'P19');
    if idPlace then
    	iCounter=iCounter+1
	  	entityPlace=mw.wikibase.getEntity(idPlace) 	
		entityBirthPlace=entity:getBestStatements( 'P19' )
		wdBirthCountry = getOneValue(entityPlace,'P17')
		wdBirthPlace = '[[' .. getOneValue(entity,'P19') .. ']]' .. ', [[' .. wdBirthCountry .. ']]' .. processAllRefsForItemWD(frame,entityBirthPlace[1].references,entityid,'P19') ..  txtEditPen(entityid,'P19')
	    myArgs[txtLabel .. iCounter]=txtBirthPlace
    	myArgs[txtContent  .. iCounter]=wdBirthPlace
    	end
	iCounter=iCounter+1
	wdPosition = getOneValue(entity,'P413')
    myArgs[txtLabel .. iCounter]=txtPlayerPosition;
    myArgs[txtContent .. iCounter]=firstToUpper(wdPosition);

	iCounter=iCounter+1
    tbl=team(frame,entity,entityid)
    if next(tbl) then
	    myArgs['rubrik' .. iCounter]=txtClubTeamHeader;
	    for key, value in pairs( tbl ) do
    		iCounter=iCounter+1
	    	myArgs[txtLabel .. iCounter]=value.club  .. ' ' .. value.ref 
		    myArgs[txtContent .. iCounter]=txtYears(value.yearfrom,value.yearto) .. value.edit
    	end
		iCounter=iCounter+1
		bHasResults,txtTeamresults=teamresults(frame,entity,entityid)
		if (bHasResults) then
		    myArgs['rubrik' .. iCounter]=txtClubTeamResultHeader;
		    myArgs['rubrik' .. iCounter .. 'stil']=txtStyleLevel2;
			iCounter=iCounter+1
		    myArgs[txtContent .. iCounter]=txtTeamresults
			iCounter=iCounter+1
			end
	end
    tbl=nationalteam(frame,entity,entityid)
    if next(tbl) then
	    myArgs['rubrik' .. iCounter]=txtNationalTeamHeader;
    	for key, value in pairs( tbl ) do
    		iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]=value.nationalteam .. ' ' .. value.ref
		    myArgs[txtContent .. iCounter]=txtYears(value.yearfrom,value.yearto) .. value.edit
	    end
		iCounter=iCounter+1
		bHasResults,txtNationalTeamresults=nationalteamresults(frame,entity,entityid)
		if (bHasResults) then
		    myArgs['rubrik' .. iCounter]=txtNationalTeamResultHeader;
		    myArgs['rubrik' .. iCounter .. 'stil']=txtStyleLevel2;
			iCounter=iCounter+1
		    myArgs[txtContent .. iCounter]=txtNationalTeamresults
			iCounter=iCounter+1
			end
	end
    tbl=awards(frame,entity,entityid)
    if next(tbl) then
		iCounter=iCounter+1
	    myArgs['rubrik' .. iCounter]=txtIndividualAwards;
    	for key, value in pairs( tbl ) do
    		iCounter=iCounter+1
		    myArgs[txtLabel .. iCounter]='[[' ..  value.award .. ']] '
		    myArgs[txtContent .. iCounter]=value.awardedby  .. value.ref .. value.edit
	    end
	end
    myArgs['under']='[https://www.wikidata.org/wiki/' .. entityid .. ' '.. txtEditComment .. ']'
	tmp = frame:expandTemplate{ title = txtInfoboxTemplate , args =myArgs}
	return tmp
	end

function team(frame,entity,entityid)
	local out = {}
    local claims = entity:getBestStatements( 'P54' )
    for key, value in pairs( claims ) do
    	local idTeam = value['mainsnak']['datavalue']['value']['id']
		if isClub( idTeam ) then
			tmp={}
			tmp.yearfrom,tmp.yearto = years(value) 
			tmp.club=teamname(idTeam,tmp.yearfrom)
			tmp.ref=processAllRefsForItemWD(frame,value['references'],entity:getId(),'P54')
			tmp.edit=txtEditPen(entityid,value.id)
			table.insert(out, tmp)
		end
    end
    table.sort(out, function(a, b) return a.yearfrom < b.yearfrom end)
	return out
end

function teamname(idTeam,year)
	local entityTeam=mw.wikibase.getEntity(idTeam) 	
	local claims = entityTeam:getBestStatements( 'P1448' ) -- If the club have had many names, loop through to find the one that was used when the player played at the club
	if (next(claims)) then
		if (year) then
			txt=year else
			txt=''
			end
	    for key, value in pairs( claims ) do
			yearfrom,yearto =  years(value) 
	    	txt=txt.. '(' .. yearfrom .. ':' .. yearto .. ')'
	    	if (year >= yearfrom and year <= yearto) then
	    		txtName=value['mainsnak']['datavalue']['value']['text']
    			end
    		end
		return '[[' ..  getLabelByEntity( idTeam ) .. '|' .. txtName .. ']]'
		else
		return '[[' ..  getLabelByEntity( idTeam ) .. ']]'
		end
end


function awards(frame,entity,entityd)
	local out = {}
    local claims = entity:getBestStatements( 'P166' )
    for key, value in pairs( claims ) do
		local tmp={}
    	local idAward = value['mainsnak']['datavalue']['value']['id']
		tmp.award=getLabelByEntity( idAward )
		if value['qualifiers']['P1027'] then
			tmp.awardedby ='[[' .. mw.wikibase.renderSnak(value['qualifiers']['P1027'][1]) .. ']]'
			else
			tmp.awardedby ="-"
			end
		tmp.ref=processAllRefsForItemWD(frame,value['references'],entity:getId(),'P166')
		tmp.edit=txtEditPen(entityd,value.id)
		table.insert(out, tmp)
    	end
    table.sort(out, function(a, b) return a.awardedby < b.awardedby end)
	return out
end

function nationalteam(frame,entity,entityid)
	local d={}
	local t={}
	local out = {}
    local claims = entity:getBestStatements( 'P54' )
    for key, value in pairs( claims ) do
    	local idTeam = value['mainsnak']['datavalue']['value']['id']
		if isNationalTeam( idTeam ) then
			tmp={}
			tmpentity=mw.wikibase.getEntity(idTeam) 	
			wdCountry = getOneValue(tmpentity,'P17')
			tmp.nationalteam=frame:expandTemplate{ title = 'Flaggbild' , args={wdCountry}} .. ' [[' ..  getLabelByEntity( idTeam ) .. '|' .. wdCountry .. ']]'
			tmp.yearfrom,tmp.yearto =  years(value) 
			tmp.ref=processAllRefsForItemWD(frame,value['references'],entity:getId(),'P54')
			tmp.edit=txtEditPen(entityid,value.id)
			table.insert(out, tmp)
			end
    	end
    table.sort(out, function(a, b) return a.yearfrom < b.yearfrom end)
	return out
end

function teamresults (frame,entity,entityid)
	local out = {}
	local all={}
	local d={}
	local t={}

    local claimsCompetition = entity:getBestStatements( 'P1344' )
    for key, value in pairs( claimsCompetition ) do
		local tmp={}
		local id = value['mainsnak']['datavalue']['value']['id']
		iTeam=getPropertyId(value,'P54')
		if (isClub(iTeam)) then
			iStatus,iPosition,txtLeague,txtDate,txtYearFrom,txtSeason=sasongsinfo_local(id,iTeam)
			tmp.iStatus=iStatus
			tmp.iSeason=id
			iPositionDirect=getProperty(value,'P1352')
			if (iPositionDirect=='') then
				tmp.iPosition=iPosition
				else
				tmp.iPosition=iPositionDirect
				end
			tmp.txtLeague=firstToUpper(txtLeague)
			tmp.txtDate=txtDate
			tmp.txtSeason=firstToUpper(txtSeason)
			tmp.iTeam=iTeam
			entityTeam=mw.wikibase.getEntity(iTeam) 
			tmp.txtCountry = getOneValue(entityTeam,'P17')
			tmp.txtTeam=getProperty(value,'P54')
			tmp.iMatches=getProperty(value,'P1350')
			tmp.iPoints=getProperty(value,'P1358')
			tmp.ref=processAllRefsForItemWD(frame,value['references'],entity:getId(),'P1344')
			tmp.edit=txtEditPen(entityid,value.id)
			table.insert(all,tmp)
		end
    end 
    table.sort(all, function(a, b) return a.txtDate < b.txtDate end)
	txt='<table style="class: biography vcard" width="100%"><tr><th width="30px">' .. txtPositionHeader .. '</th><th>' .. txtCompetitionHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
	txtTeamOld=''
	for i = 1,#all do
		if (all[i].txtTeam~=txtTeamOld) then
			local txtTeam='[[' .. all[i].txtTeam .. ']]'
			if (all[i].txtCountry) then
				txtTeam=frame:expandTemplate{ title = 'Flaggbild' , args={all[i].txtCountry,storlek='16px'}} .. ' ' .. txtTeam
				end
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. txtTeam .. '</b></td></tr>'
			txtTeamOld=all[i].txtTeam
			end
		txt=txt .. "<tr>"
		txt=txt .. txtPosition(all[i].iPosition)
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if (txtTmp) then
			txtSeasonTxt= '[[' .. txtTmp  .. '|' .. all[i].txtSeason  .. ']] ' .. all[i].ref .. all[i].edit
			else
			txtSeasonTxt= '[[' .. getLabelByEntity(all[i].iSeason) .. '|' .. all[i].txtSeason .. ']] ' .. all[i].ref .. all[i].edit
		end				
		if (all[i].iStatus==1) then
			txt=txt .. '<td>' .. all[i].txtLeague  .. '</td>'
			txt=txt .. '<td>' .. txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==2) then
			txt=txt .. '<td colspan="2">' .. all[i].txtLeague  ..  txtSeasonTxt .. '</td>' 
			end
		if (all[i].iStatus==3) then
			txt=txt .. '<td colspan="2">' .. txtSeasonTxt .. '</td>' 
			end
		txt=txt .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

function nationalteamresults (frame,entity,entityid)
	local out = {}
	local all={}
	local d={}
	local t={}

	local txt='   '
    local claimsCompetition = entity:getBestStatements( 'P1344' )
    for key, value in pairs( claimsCompetition ) do
		local tmp={}
		local id = value['mainsnak']['datavalue']['value']['id']
		iTeam=getPropertyId(value,'P54')
		if (isNationalTeam(iTeam)) then
			iStatus,iPosition,txtLeague,txtDate,txtYearFrom,txtSeason=sasongsinfo_local(id,iTeam)
			tmp.iSeason=id
			tmp.iStatus=iStatus
			iPositionDirect=getProperty(value,'P1352')
			if (iPositionDirect=='') then
				tmp.iPosition=iPosition
				else
				tmp.iPosition=iPositionDirect
				end
			tmp.txtLeague=txtLeague
			tmp.txtDate=txtDate
			tmp.txtSeason=firstToUpper(txtSeason)
			tmp.iTeam=iTeam
			tmp.txtTeam=getProperty(value,'P54')
			tmpentity=mw.wikibase.getEntity(iTeam) 	
			wdCountry = getOneValue(tmpentity,'P17')
			tmp.txtNationalTeam='[[' ..  getLabelByEntity( iTeam ) .. '|' .. wdCountry .. ']]'
			tmp.iMatches=getProperty(value,'P1350')
			tmp.iPoints=getProperty(value,'P1358')
			tmp.ref=processAllRefsForItemWD(frame,value['references'],entity:getId(),'P1344')
			tmp.edit=txtEditPen(entityid,value.id)
			table.insert(all,tmp)
		end
    end 

    table.sort(all, function(a, b) return a.txtLeague < b.txtLeague or (a.txtLeague==b.txtLeague and a.txtDate < b.txtDate) end)
	txt=txt..'<table style="class: biography vcard" width="100%"><tr><th width="30px">' .. txtPositionHeader .. '</th><th>Landslag</th><th>' .. txtSeasonHeader .. '</th></tr>'
	txtCompetitionOld=''
	for i = 1,#all do
		if (all[i].txtLeague~=txtCompetitionOld) then
			txt=txt .. '<tr ' .. txtTeamHeaderStyle .. '><td colspan="3"><b>' .. all[i].txtLeague .. '</b></td></tr>'
			txtCompetitionOld=all[i].txtLeague
			end
		txt=txt .. "<tr>"
		txt=txt .. txtPosition(all[i].iPosition)
		txt=txt .. '<td>' .. all[i].txtNationalTeam  .. '</td>'
		txtTmp=mw.wikibase.getSitelink(all[i].iSeason )
		if (txtTmp) then
			txt=txt .. '<td>[[' .. txtTmp  .. '|' .. all[i].txtSeason  .. ']] ' .. all[i].ref .. all[i].edit .. '</td>' 
			else
			txt=txt .. '<td>[[' .. getLabelByEntity(all[i].iSeason) .. '|' .. all[i].txtSeason .. ']] ' .. all[i].ref .. all[i].edit .. '</td>' 
		end				
		txt=txt .. '</tr>'
    end
	txt=txt .. '</table>'
	return #all>0,txt
end

function txtPosition(iPosition)
	local bMedal=0
	if (iPosition=="1") then
		txtPosColour='gold'
		bMedal=1
		end
	if (iPosition=="2") then
		txtPosColour='silver'
		bMedal=1
		end
	if (iPosition=="3") then
		txtPosColour='bronze'
		bMedal=1
		end
	if (bMedal==1) then
		return '<td align="center" bgcolor="' .. txtPosColour .. '">' .. iPosition  .. '</td>'
		else
		return '<td>' .. iPosition  .. '</td>'
		end
end

function txtYears(startyear,endyear)
if (startyear=='' or startyear==nil) then
	if (endyear=='' or endyear==nil) then
		return '–'
		else
		return '–' .. endyear
		end
	else
	if (endyear==startyear) then
		return startyear
		else
		return startyear .. '–' .. endyear
		end
	end
end

function years(value)
	if value['qualifiers'] then
		if value['qualifiers']['P580'] then
			startyear=string.sub(value['qualifiers']['P580'][1].datavalue.value.time,2,5)
--			startyear=string.sub(p582[1].mainsnak.datavalue.value.time,2,5)
--			startyear=emptyifNil(mw.wikibase.renderSnak(value['qualifiers']['P580'][1]))
			else
			startyear=''
			end
		if value['qualifiers']['P582'] then
			endyear=string.sub(value['qualifiers']['P582'][1].datavalue.value.time,2,5)
--			endyear=emptyifNil(mw.wikibase.renderSnak(value['qualifiers']['P582'][1]))
			else
			endyear=''
			end
		return startyear,endyear
		else
			return '',''
		end
end

function getProperty(value,txtPropertyId)
	if value['qualifiers'][txtPropertyId] then
			txtValue=emptyifNil(mw.wikibase.renderSnak(value['qualifiers'][txtPropertyId][1]))
		else
			txtValue=''
		end
	return txtValue
end

function getPropertyId(value,txtPropertyId)
	if value['qualifiers'] then
		if value['qualifiers'][txtPropertyId] then
			txtSnaktype=value['qualifiers'][txtPropertyId][1].snaktype
			if (txtSnaktype=="value") then
				txtValue=value['qualifiers'][txtPropertyId][1].datavalue.value.id
				else
				txtValue="Not Implemented"
				end
			else
			txtValue=nil
		end
		else
			txtValue=nil
end			
	return txtValue
end

function isClub( id )
	instanceof1=mw.wikibase.getEntity( id ):getBestStatements( 'P31' );
    for key, value in pairs( instanceof1 ) do
		txtId=value['mainsnak']['datavalue']['value']['id'];
		if (txtId=='Q1194951') then
			return false
			end
		if (txtId == 'Q847017' or txtId == 'Q12973014' or txtId=='Q108395614' ) then
			return true
			end
		instanceof2=mw.wikibase.getEntity( txtId ):getBestStatements( 'P279' );
	    for key2, value2 in pairs( instanceof2 ) do
			txtId2=value2['mainsnak']['datavalue']['value']['id'];
			if (txtId2=='Q1194951') then
				return false
				end
			if (txtId2 == 'Q847017' or txtId2 == 'Q12973014' or txtId2=='Q108395614' ) then
				return true
				end
			end
		end
	return false
end

function isNationalTeam( id )
	local isNT = false
	instanceof1=mw.wikibase.getEntity( id ):getBestStatements( 'P31' );
	txtId=instanceof1[1]['mainsnak']['datavalue']['value']['id'];
	if txtId=='Q1194951' then
		isNT = true
	end
	return isNT
end

function emptyifNil(data)
	if (data) then
		return data
		else
		return ''
	end
end

function getLabelByEntity( id )
	return mw.wikibase.getEntity( id ):getLabel( 'sv' )
end


sasongsinfo_local= function(txtId,iTeam)
	local entityCompetition=mw.wikibase.getEntity(txtId) 
	local iStatus=1														-- Everything ok	
    local formatedLeague= entityCompetition:formatPropertyValues( 'P3450' )
    local claimsLiga = entityCompetition:getAllStatements( 'P3450' )
    if (claimsLiga[1]) then											-- Has a link to leauge (from the individual season) 
	    local idSerie=claimsLiga[1]['mainsnak']['datavalue']['value']['id']
		local nla=mw.wikibase.getEntity(idSerie):getSitelink( 'svwiki' )
		txtThisLeague=firstToUpper(formatedLeague['value'])
		if (nla) then
			txtLeague = '[[' .. nla .. '|' .. txtThisLeague .. ']]'
			else
			txtLeague = '[[' .. txtThisLeague .. ']]'
			end
		else
		txtLeague='Tävlingstyp ej satt för '
		iStatus=2
		end
	p580=entityCompetition:getAllStatements( 'P580' )
	if (next(p580)) then
		txtDate=p580[1].mainsnak.datavalue.value.time
		txtYearFrom=string.sub(p580[1].mainsnak.datavalue.value.time,2,5)
		p582=entityCompetition:getAllStatements( 'P582' )
		if (next(p582)) then
			txtYearTo=string.sub(p582[1].mainsnak.datavalue.value.time,2,5)
			else
			txtYearTo=''
			end
		txtSeason=txtYears(txtYearFrom,txtYearTo)
		else
		--If no start year check for era	
		p2348=entityCompetition:getAllStatements( 'P2348' ) -- Om tidsperiod
		if (next(p2348)) then
			iPeriod=p2348[1].mainsnak.datavalue.value.id
			txtSeason=iPeriod
			entityPeriod=mw.wikibase.getEntity(iPeriod) 	
			p580=entityPeriod:getAllStatements( 'P580' )
			if (next(p580)) then
				txtDate=p580[1].mainsnak.datavalue.value.time
				txtYearFrom=string.sub(p580[1].mainsnak.datavalue.value.time,2,5)
				p582=entityPeriod:getAllStatements( 'P582' )
				if (next(p582)) then
					txtYearTo=string.sub(p582[1].mainsnak.datavalue.value.time,2,5)
					else
					txtYearTo=''
					end
				txtSeason=txtYears(txtYearFrom,txtYearTo)
				else
				txtSeason=getLabelByEntity(txtId)
				iStatus=3
				end
			else
			-- If neither startyear nor era, do not try do display more detailed information, just display information about the season of the league	
			txtSeason=getLabelByEntity(txtId)
			iStatus=3
			end
		end
		claimTeams=entityCompetition:getBestStatements( 'P1923' )
		txtRet=''
	    for key, value in pairs(claimTeams ) do
			iTeamLoop=value.mainsnak.datavalue.value.id
			if (iTeamLoop==iTeam) then
				if (value.qualifiers) then
					txtRet=txtRet .. string.sub(value.qualifiers.P1352[1].datavalue.value.amount,2,-1)
					end
				break
			    end
		    end
	return iStatus,txtRet,txtLeague,txtDate,txtYearFrom,txtSeason
end

-- the "qualifiers" and "snaks" field have a respective "qualifiers-order" and "snaks-order" field
-- use these as the second parameter and this function instead of the built-in "pairs" function
-- to iterate over all qualifiers and snaks in the intended order.
local function orderedpairs(array, order)
	if not order then return pairs(array) end

	-- return iterator function
	local i = 0
	return function()
		i = i + 1
		if order[i] then
			return order[i], array[order[i]]
		end
	end
end

local function getSnakValue(snak, parameter)
	if snak.snaktype == "value" then
		-- call the respective snak parser
		if snak.datavalue.type == "string" then return snak.datavalue.value
		elseif snak.datavalue.type == "globecoordinate" then return printDatavalueCoordinate(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "quantity" then return printDatavalueQuantity(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "time" then return printDatavalueTime(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "wikibase-entityid" then return printDatavalueEntity(snak.datavalue.value, parameter)
		elseif snak.datavalue.type == "monolingualtext" then return printDatavalueMonolingualText(snak.datavalue.value, parameter)
		end
	end
	return mw.wikibase.renderSnak(snak)
end

function __genOrderedIndex( t )
    local orderedIndex = {}
    for key in pairs(t) do
        table.insert( orderedIndex, key )
    end
    table.sort( orderedIndex )
    return orderedIndex
end

function orderedNext(t, state)
    -- Equivalent of the next function, but returns the keys in the alphabetic
    -- order. We use a temporary ordered key table that is stored in the
    -- table being iterated.

    local key = nil
    --print("orderedNext: state = "..tostring(state) )
    if state == nil then
        -- the first time, generate the index
        t.__orderedIndex = __genOrderedIndex( t )
        key = t.__orderedIndex[1]
    else
        -- fetch the next value
        for i = 1,table.getn(t.__orderedIndex) do
            if t.__orderedIndex[i] == state then
                key = t.__orderedIndex[i+1]
            end
        end
    end

    if key then
        return key, t[key]
    end

    -- no more value to return, cleanup
    t.__orderedIndex = nil
    return
end

function orderedPairs(t)
    -- Equivalent of the pairs() function on tables. Allows to iterate
    -- in order
    return orderedNext, t, nil
end

-- from: https://stackoverflow.com/questions/2421695/first-character-uppercase-lua
function firstToUpper(str)
	if (str) then
	    return (str:gsub("^%l", string.upper))
	    else
	    return ''
	    end
end


return p