Modul:Sportsklub WD
Udseende
p = {}
local wd = require( 'Modul:Referencer' )
local sd = require( 'Modul:Sportdata' )
p.iRefcounter=0
function isempty(foo)
return foo==nil or foo=='' or foo==0
end
p.club = function(myframe)
if (myframe.args['qid']) then
entityid=myframe.args['qid'] else
entityid=mw.wikibase.getEntityIdForCurrentPage()
end
if not (entityid==nil) then
--Start with all possible arguments
if (myframe.args[txtHideable]==txtYes) then
bHideable=true
else
bHideable=false
end
if (myframe.args['condensed']=='yes') then
bCondensed=true
else
bCondensed=false
end
if myframe.args['txtFoundedDate']~=nil then
txtFoundedDate=myframe.args.txtFoundedDate
end
if myframe.args['txtDissolvedDate']~=nil then
txtDissolvedDate=myframe.args.txtDissolvedDate
end
if myframe.args['txtSeat']~=nil then
txtSeat=myframe.args.txtSeat
end
if myframe.args['txtHomeVenue']~=nil then
txtHomeVenue=myframe.args.txtHomeVenue
end
if myframe.args['txtWebsite']~=nil then
txtHomeVenue=myframe.args.txtHomeVenue
end
if myframe.args['txtClubTeamResultHeader']~=nil then
txtClubTeamResultHeader=myframe.args.txtClubTeamResultHeader
end
if myframe.args['txtClubCoachesHeader']~=nil then
txtClubCoachesHeader=myframe.args.txtClubCoachesHeader
end
if myframe.args['txtNamesHeader']~=nil then
txtNamesHeader=myframe.args.txtNamesHeader
end
if myframe.args['txtNamesDescription']~=nil then
txtNamesDescription=myframe.args.txtNamesDescription
end
if myframe.args['txtCompetitionHeader']~=nil then
txtCompetitionHeader=myframe.args.txtCompetitionHeader
end
if myframe.args['txtNameHeader']~=nil then
txtNameHeader=myframe.args.txtNameHeader
end
if myframe.args['txtSeasonHeader']~=nil then
txtSeasonHeader=myframe.args.txtSeasonHeader
end
if myframe.args['txtPositionHeader']~=nil then
txtPositionHeader=myframe.args.txtPositionHeader
end
if myframe.args['txtInfoboxTemplate']~=nil then
txtInfoboxTemplate=myframe.args.txtInfoboxTemplate
end
if myframe.args['txtFlagIconTemplate']~=nil then
txtFlagIconTemplate=myframe.args.txtFlagIconTemplate
end
if myframe.args['txtHeader']~=nil then
txtHeader=myframe.args.txtHeader
end
if myframe.args['txtLabel']~=nil then
txtLabel=myframe.args.txtLabel
end
if myframe.args['txtContent']~=nil then
txtContent=myframe.args.txtContent
end
if myframe.args['txtTeamHeaderStyle']~=nil then
txtTeamHeaderStyle=myframe.args.txtTeamHeaderStyle
end
if myframe.args['txtLanguageCode']~=nil then
txtLanguageCode=myframe.args.txtLanguageCode
end
if myframe.args['txtEditComment']~=nil then
txtEditComment=myframe.args.txtEditComment
end
if myframe.args['txtStyleMain']~=nil then
txtStyleMain=myframe.args.txtStyleMain
end
if myframe.args['txtStyleLevel2']~=nil then
txtStyleLevel2=myframe.args.txtStyleLevel2
end
if (myframe.args['txtWidth_px']~=nil) and not (myframe.args['txtWidth_px']=='') then
txtWidth_px=myframe.args.txtWidth_px
end
myframe['id']=entityid
-- entity=mw.wikibase.getEntity(entityid)
wdTitle=getLabelByEntity( entityid )
myArgs={titel=wdTitle,grundstil="width:" .. txtWidth_px}
img=mw.wikibase.getBestStatements(entityid, 'P18' )
if (next(img)) then
myArgs=addImage(entityid,'P18',img,myArgs)
else
img=mw.wikibase.getBestStatements(entityid, 'P154' )
if (next(img)) then
myArgs=addImage(entityid,'P154',img,myArgs)
end
end
myArgs[txtHeaderStyle] = txtStyleMain
iCounter=0
claimFoundedDate=mw.wikibase.getBestStatements(entityid, 'P571' )
if next(claimFoundedDate) then
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtFoundedDate
myArgs[txtContent .. iCounter]=mw.wikibase.formatValue(claimFoundedDate[1].mainsnak) .. txtUnpackReference(myframe,tblProcessAllRefsForItemWD(myframe,claimFoundedDate[1].references,entityid,'P571'))
end
claimDissolvedDate=mw.wikibase.getBestStatements(entityid, 'P576' )
if next(claimDissolvedDate) then
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtDissolvedDate
myArgs[txtContent .. iCounter]=mw.wikibase.formatValue(claimDissolvedDate[1].mainsnak) .. txtUnpackReference(myframe,tblProcessAllRefsForItemWD(myframe,claimDissolvedDate[1].references,entityid,'P576'))
end
claimPlace=mw.wikibase.getBestStatements(entityid, 'P159' )
wdPlace=''
iPlaces=0
for key, value in pairs( claimPlace ) do
iPlaces=iPlaces+1
idPlace=value.mainsnak.datavalue.value.id
wdCountry = readFirstStatement(idPlace,'P17')
if (iPlaces>1) then
wdPlace = wdPlace .. ' och '
end
wdPlace = wdPlace .. txtWikilink(idPlace) .. ', ' .. myframe:expandTemplate{ title = txtTemplate .. ':' .. txtFlagIconTemplate , args={wdCountry}} .. ' [[' .. wdCountry .. ']]' .. txtUnpackReference(myframe,tblProcessAllRefsForItemWD(myframe,value.references,entityid,'P159'))
txtYearfrom,txtYearTo = years(value)
if ((not isempty(txtYearfrom)) or not (isempty(txtYearTo))) then
wdPlace=wdPlace .. ' (' .. txtYears(txtYearfrom,txtYearTo) .. ')'
end
wdPlace=wdPlace.. txtEditPen(entityid,value.id)
end
if not (wdPlace=='') then
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtSeat
myArgs[txtContent .. iCounter]=wdPlace
end
claimHomeVenue=mw.wikibase.getAllStatements(entityid, 'P115' )
wdHomeVenue=''
for key, value in pairs( claimHomeVenue ) do
idHomeVenue=value.mainsnak.datavalue.value.id
wdHomeVenue = wdHomeVenue .. txtWikilink(idHomeVenue)
claimCapacity=mw.wikibase.getBestStatements(idHomeVenue,'P1083')
wdCapacity=read(claimCapacity, 'value' ) --['value']
if not (isempty(wdCapacity)) then
wdHomeVenue=wdHomeVenue .. ' (' .. wdCapacity .. ' ' .. txtSeats .. ')'
end
wdHomeVenue=wdHomeVenue .. txtUnpackReference(myframe,tblProcessAllRefsForItemWD(myframe,value.references,entityid,'P115')) .. txtEditPen(entityid,value.id)
end
if not (wdHomeVenue=='') then
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtHomeVenue
myArgs[txtContent .. iCounter]=wdHomeVenue
end
claimWebsite=mw.wikibase.getBestStatements(entityid, 'P856' )
if next(claimWebsite) then
wdWebsite = claimWebsite[1].mainsnak.datavalue.value
if (#wdWebsite>30) then
wdWebsite='[' .. wdWebsite .. ' ' .. txtOfficialWebsite .. ']'
end
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtWebsite
myArgs[txtContent .. iCounter]=wdWebsite .. txtEditPen(entityid,'P856')
end
if myframe.args['width_px']~=nil then
txtWidth_px=myframe.args.width_px
end
claimNickName=mw.wikibase.getBestStatements(entityid, 'P1449' )
if next(claimNickName) then
iCounter=iCounter+1
myArgs[txtLabel .. iCounter]=txtNickName
myArgs[txtContent .. iCounter]=mw.wikibase.formatValue(claimNickName[1].mainsnak) .. txtUnpackReference(myframe,tblProcessAllRefsForItemWD(myframe,claimNickName[1].references,entityid,'P1449'))
end
if ((myframe.args['body1']~=nil and myframe.args['body1']~='') or (myframe.args['pattern_b1']~=nil and myframe.args['pattern_b1']~='')) then
arrayKit1={pattern_la =myframe.args['pattern_la1'], pattern_b=myframe.args['pattern_b1'], pattern_ra =myframe.args['pattern_ra1'], leftarm =myframe.args['leftarm1'],body= myframe.args['body1'], rightarm =myframe.args['rightarm1'],shorts=myframe.args['shorts1'],socks =myframe.args['socks1'], titel = 'Hemmaställ'}
kit1 = myframe:expandTemplate{ title = txtTemplate .. ':' .. txtKitTemplate , args =arrayKit1}
else
kit1=''
end
if ((myframe.args['body2']~=nil and myframe.args['body2']~='') or (myframe.args['pattern_b2']~=nil and myframe.args['pattern_b2']~='')) then
arrayKit2={pattern_la =myframe.args['pattern_la2'], pattern_b=myframe.args['pattern_b2'], pattern_ra =myframe.args['pattern_ra2'], leftarm =myframe.args['leftarm2'],body= myframe.args['body2'], rightarm =myframe.args['rightarm2'],shorts=myframe.args['shorts2'],socks =myframe.args['socks2'], titel = 'Bortaställ'}
kit2 = myframe:expandTemplate{ title = txtTemplate .. ':' .. txtKitTemplate , args =arrayKit2}
else
kit2=''
end
if ((myframe.args['body3']~=nil and myframe.args['body3']~='') or (myframe.args['pattern_b3']~=nil and myframe.args['pattern_b3']~='')) then
arrayKit2={pattern_la =myframe.args['pattern_la3'], pattern_b=myframe.args['pattern_b3'], pattern_ra =myframe.args['pattern_ra3'], leftarm =myframe.args['leftarm3'],body= myframe.args['body3'], rightarm =myframe.args['rightarm3'],shorts=myframe.args['shorts3'],socks =myframe.args['socks3'], titel = 'Libero'}
kit3 = myframe:expandTemplate{ title = txtTemplate .. ':' .. txtKitTemplate , args =arrayKit2}
else
kit3=''
end
iCounter=iCounter+1
myArgs[txtContent .. iCounter]='<table bgcolor=#ffffff><tr><td>' ..kit1 .. '</td><td>' .. kit2 .. '</td><td>' .. kit3 .. '</td></tr></table>'
myArgs[txtContent .. iCounter .. 'stil']='background:#ffffff'
bHasResults,txtTeamresults=teamresults(myframe,entityid)
if (bHasResults) then
iCounter=iCounter+1
myArgs[txtHeader .. iCounter]=txtClubTeamResultHeader
iCounter=iCounter+1
myArgs[txtContent .. iCounter]=txtTeamresults
end
bHasCoaches,txtCoaches=teamcoaches(myframe,entityid)
if (bHasCoaches) then
iCounter=iCounter+1
myArgs[txtHeader .. iCounter]=txtClubCoachesHeader
iCounter=iCounter+1
myArgs[txtContent .. iCounter]=txtCoaches
end
local claimsPlayersCategory = mw.wikibase.getBestStatements(entityid, 'P6112' )
if next(claimsPlayersCategory) then
txtPlayerCategorySitelink=mw.wikibase.getSitelink(read(claimsPlayersCategory[1],'id'))
if txtPlayerCategorySitelink~=nil then
iCounter=iCounter+1
myArgs[txtHeader .. iCounter]=txtPlayersHeaders
iCounter=iCounter+1
myArgs[txtContent .. iCounter]='[[:' .. txtPlayerCategorySitelink .. '|' .. txtPlayersDescription .. ']]'
end
end
bHasNames,txtNames=teamnames(myframe,entityid)
if (bHasNames) then
iCounter=iCounter+1
myArgs[txtHeader .. iCounter]=txtNamesHeader
iCounter=iCounter+1
myArgs[txtContent .. iCounter]='\'\''..txtNamesDescription..'\'\''
iCounter=iCounter+1
myArgs[txtContent .. iCounter]=txtNames
end
--[=====[
--]=====]
myArgs['under']='[https://www.wikidata.org/wiki/' .. entityid .. ' '.. txtEditComment .. ']'
tmp = myframe:expandTemplate{ title = txtTemplate .. ':' .. txtInfoboxTemplate , args =myArgs}
return tmp
end
end
function teamresults (myframe,iTeam)
local out = {}
local all={}
local d={}
local t={}
local claimsCompetition = mw.wikibase.getBestStatements(iTeam, 'P1344' )
for key, value in pairs( claimsCompetition ) do
local tmp={}
local id = read(value,'id')
tmp.iSeason=id
tmp.iTeam=iTeam
tmp=tblSeasonData(myframe,tmp,value,iTeam)
if (tmp.iPosition=='') then
tmp.iPosition=999999
end
tmp.iPosition=tonumber(tmp.iPosition)
tmp.txtCompetition=txtWikilinkWOsitelink(read(value,'id'))
table.insert(all,tmp)
end
all,txt=showresults(myframe,all,"club")
return #all>0,txt
end
function teamcoaches (myframe,iTeam)
local out = {}
local all={}
local txt=''
local claimsCompetition = mw.wikibase.getBestStatements(iTeam, 'P286' )
for key, value in pairs( claimsCompetition ) do
local tmp={}
local id = read(value,'id')
local tmp=tblTeamInfo(myframe,value,iTeam,'P286')
tmp.txtCompetition=txtWikilinkWOsitelink(read(value,'id'))
table.insert(all,tmp)
end
if (myframe.args['oldestfirst']) then
table.sort(all, function(a, b) return a.datefrom < b.datefrom end)
else
table.sort(all, function(a, b) return a.datefrom > b.datefrom end)
end
txt=txt .. '<table style="class: biography vcard" width="100%"><tr><th>' .. txtNameHeader .. '</th><th>' .. txtSeasonHeader .. '</th></tr>'
txtCompetitionOld=''
for i = 1,#all do
txt=txt .. '<tr>'
txt=txt .. '<td style="text-align:left;">' .. all[i].txtCompetition .. '</td>'
txt=txt .. '<td style="text-align:left;">' .. txtYears(all[i].yearfrom,all[i].yearto) .. txtUnpackReference(myframe,all[i].hasref,all[i].ref) .. all[i].edit .. '</td></tr>'
end
txt=txt .. '</table>'
return #all>0,txt
end
function teamnames (myframe,iTeam)
local out = {}
local all={}
local txt=''
local claimsNames = mw.wikibase.getBestStatements(iTeam,'P2561' )
for key, value in pairs( claimsNames ) do
local tmp=tblTeamInfo(myframe,value,iTeam,'P286')
tmp.txtName = read(value,'text')
table.insert(all,tmp)
end
table.sort(all, function(a, b) return a.datefrom > b.datefrom end)
txt=txt .. '<table style="class: biography vcard" width="100%"><tr><th>' .. txtNameHeader .. '</th><th width="80px">' .. txtSeasonHeader .. '</th></tr>'
txtCompetitionOld=''
for i = 1,#all do
txt=txt .. '<tr>'
txt=txt .. '<td>' .. all[i].txtName .. '</td>'
txt=txt .. '<td>' .. txtYears(all[i].yearfrom,all[i].yearto) .. txtUnpackReference(myframe,all[i].hasref,all[i].ref) .. all[i].edit .. '</td></tr>'
end
txt=txt .. '</table>'
return #all>0,txt
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
-- 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