تضامنًا مع حق الشعب الفلسطيني |
وحدة:ملعب/Mr. Ibrahem/teamroster
< وحدة:ملعب | Mr. Ibrahem
توثيق الوحدة [أنشئ] [محو الاختزان][استخدامات] [قوالب]
local p = {}
local wiki = "ar"
local function getSquadTableColumn(x)
local l10nDef = { -- note (in the table), note (below the table)
["ar"] = {"المتسابق", "تاريخ الولادة", "الفريق السابق", "ملاحظة", "ملاحظة", "البلد", "قائمة الفريق"}
}
local l10n = l10nDef["ar"]
return l10n[x]
end
function p.teamroster(frame)
local available_list = false
if frame.args[1] ~= nil then frame.args[1] = string.gsub(frame.args[1], "%c", "") end
local squadSeason = mw.wikibase.getEntityObject( frame.args[1] )
local flags, pays = {}, {}
local riderIds, riderNames, riderBirthdays, givenname, familyname, riderTeam, time = {}, {}, {}, {}, {}, {}, {}
local riderStart, riderEnd, riderPosition, riderReason, riderRef = {}, {}, {}, {}, {}
local index, riderNames_transl, riderNames_notransl = {}, {}, {}
local labelMissing = false
local lang = mw.language.getContentLanguage()
local WDlink_on
local team, rider, startOfSeason
local v = ''
--========================
local typeoftemplate = false
if frame.args.new and frame.args.new ~= '' then typeoftemplate = true end
--========================
local function trans(date, month, day)
if date ~= '' then
local _, _, y, m, d = string.find(date, "(%d+)-(%d+)-(%d+)")
if m == '00' then m = month end
if d == '00' then d = day end
date = '+'..y..'-'..m..'-'..d..'T00:00:00Z'
return date
else return '' end
end
local function name(i, wiki, transl, names, givenname, familyname)
-- transform name "A B ..." into "B ... A"
local _, count = mw.ustring.gsub(names, " ", " ")
local a,b,c,d = '', '', '', ''
local done = false
if count ~= nil then count = count + 1 else count = 1 end
if count > 1 then
if count == 2 then
if names~='' then _, _, a, b = mw.ustring.find(names, "(%S+)%s+(%S+)") names=b..' '..a..":"..i end
else
local name_parts_lv = {'da', 'de', 'di', 'De', 'la', 'Le', 'ten', 'van', 'Van'}
local name_parts_mk = {'да', 'ди', 'де', 'Де', 'ла', 'Ле', 'тен', 'ван', 'Ван'}
local name_parts_ru = {'да', 'ди', 'де', 'Де', 'ла', 'Ле', 'тен', 'ван', 'Ван'}
local name_parts = {'da', 'de', 'di', 'De', 'la', 'Le', 'ten', 'van', 'Van'}
local v
if count == 3 and names~='' then
_, _, a, b, c = mw.ustring.find(names, "(%S+)%s+(%S+)%s+(%S+)")
if wiki == 'mk' then
for _,v in ipairs(name_parts_mk) do if b == v then names = b..' '..c..' '..a..":"..i done = true break end end
end
if wiki == 'lv' then
for _,v in ipairs(name_parts_lv) do if b == v then names = b..' '..c..' '..a..":"..i done = true break end end
end
if wiki == 'ru' then
for _,v in ipairs(name_parts_ru) do if b == v then names = b..' '..c..' '..a..":"..i done = true break end end
end
if wiki ~= 'lv' and wiki ~= 'mk' and wiki ~= 'ru' then
for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..a..":"..i done = true break end end
end
if transl == 'notransl' then --or (wiki~='lv' and wiki~='mk' and wiki~='ru' and wiki~='ja') then
for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..a..":"..i done = true break end end
end
if not done and familyname==2 then names = b..' '..c..' '..a..":"..i done = true end
if not done and familyname==1 then names = c..' '..a..' '..b..":"..i done = true end
if not done and familyname==0 then names = c..' '..a..' '..b..":"..i done = true end
end
if count > 3 and names~='' then
_, _, a, b, c, d = mw.ustring.find(names, "(%S+)%s+(%S+)%s+(%S+)%s+(%S+)")
if wiki == 'mk' then
for _,v in ipairs(name_parts_mk) do if c == v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end
for _,v in ipairs(name_parts_mk) do if b == v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end
end
if wiki == 'lv' then
for _,v in ipairs(name_parts_lv) do if c == v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end
for _,v in ipairs(name_parts_lv) do if b == v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end
end
if wiki == 'ru' then
for _,v in ipairs(name_parts_ru) do if c == v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end
for _,v in ipairs(name_parts_ru) do if b == v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end
end
if wiki ~= 'lv' and wiki ~= 'mk' and wiki ~= 'ru' then
for _,v in ipairs(name_parts) do if c == v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end
for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end
end
if transl == 'notransl' then --or (wiki~='lv' and wiki~='mk' and wiki~='ru' and wiki~='ja') then
for _,v in ipairs(name_parts) do if c == v then names = c..' '..d..' '..a..' '..b..":"..i done = true break end end
for _,v in ipairs(name_parts) do if b == v then names = b..' '..c..' '..d..' '..a..":"..i done = true break end end
end
if not done then names = b..' '..c..' '..d..' '..a..":"..i end
end
end
end
return names
end
local localFrame
local sort
--[[
The word 'sort' is used to sort the riders after the surname. It could look like this in the Wikipedia article
{{Cycling race/teamroster|Q21769847
| sort
}}
A rider called 'Laurens De Vreese' is sorted after 'De Vreese Laurens'. If you want to sort after 'Vreese Laurens De'
change that in the code. In lvWiki, mkWiki and ruWiki sorting is standard, there is no need to switch sorting on in the article
]]
if string.match(frame:getParent():getTitle(), '%P+') == mw.site.namespaces.Template.name
then localFrame = frame:getParent() else localFrame = frame end
if localFrame.args[2] ~= nil then
if mw.ustring.find(mw.ustring.lower(localFrame.args[2]), "sort") then sort = true else sort = false end
end
if wiki == "lv" or wiki == "mk" or wiki == "ru" then sort = true end
pcall(function() team = squadSeason.claims["P361"][1].mainsnak.datavalue.value['numeric-id'] end)
-- WDlink_on is used to decide if a Wikidata flag will be shown
if wiki == "mk" or wiki == "ja" or wiki == "ru" then WDlink_on = true else WDlink_on = false end
if pcall(function() startOfSeason = squadSeason.claims["P580"][1].mainsnak.datavalue.value.time end) then
else
local Sitelink = squadSeason:getSitelink(wiki .. 'wiki') or squadSeason:getSitelink('enwiki') or squadSeason:getSitelink('frwiki') or squadSeason:getSitelink('dewiki') or ''
if not Sitelink or Sitelink == '' then return '> Wikidata is missing data about the start time (P580) and end time (P582) of the season'
else startOfSeason = '+'..string.match(Sitelink, '%d%d%d%d' ) ..'-01-01T00:00:00Z'
end
end
local i = 1
pcall(function()
while squadSeason.claims["P527"][i] do
riderIds[i] = 'Q' .. squadSeason.claims["P527"][i].mainsnak.datavalue.value['numeric-id']
riderNames[i] = WPlink(riderIds[i])
rider = mw.wikibase.getEntityObject(riderIds[i])
if pcall(function() riderBirthdays[i] = rider.claims["P569"][1].mainsnak.datavalue.value.time end
) then else riderBirthdays[i] = '' end
if pcall(function() local k for k, _ in pairs(rider.claims["P735"]) do givenname[i] = k end end
) then else givenname[i] = 0 end
if pcall(function() local k for k, _ in pairs(rider.claims["P734"]) do familyname[i] = k end end
) then else familyname[i] = 0 end
pcall(function()
local language
language = wiki
local entity=mw.wikibase.getEntity(riderIds[i])
if wiki == 'mk' or wiki == 'ru' then
if entity:getLabel(language) ~= nil and (mw.ustring.byte(entity:getLabel(language), 1, 1) > 127 and mw.ustring.byte(entity:getLabel(language), 3, 3) > 127)
then riderNames_transl[i] = entity.labels[language].value riderNames_notransl[i] = ''
else riderNames_notransl[i] = entity.labels['en'].value or entity.labels['fr'].value or entity.labels['de'].value riderNames_transl[i] = ''
end
end
if wiki ~= 'mk' and wiki ~= 'ru' then
if entity:getLabel(language) ~= nil then riderNames_transl[i] = entity.labels[language].value riderNames_notransl[i] = ''
else riderNames_notransl[i] = entity.labels['en'].value or entity.labels['fr'].value or entity.labels['de'].value riderNames_transl[i] = ''
end
end
end)
if sort == true then
riderNames_transl[i] = name(i, wiki, 'transl', riderNames_transl[i], givenname[i], familyname[i])
riderNames_notransl[i] = name(i, wiki, 'notransl', riderNames_notransl[i], givenname[i], familyname[i])
else index[i] = i
end
if pcall(function()
local date = squadSeason.claims["P527"][i].qualifiers["P580"][1].datavalue.value.time or ''
riderStart[i] = func_date(trans(date,'01', '01'), 'small')
end
) then else riderStart[i] = '' end
if pcall(function()
local date = squadSeason.claims["P527"][i].qualifiers["P582"][1].datavalue.value.time
riderEnd[i] = func_date(trans(date,'12', '31'), 'small')
end
) then else riderEnd[i] = '' end
if pcall(function()
riderPosition[i] = 'Q' .. squadSeason.claims["P527"][i].qualifiers["P39"][1].datavalue.value['numeric-id']
local entity = mw.wikibase.getEntity( riderPosition[i] )
local label = string.gsub(entity:getLabel("ar"), "%b()", "") or entity:getLabel( 'en' )
--if label == null then label = entity:getLabel( 'en' ) end
riderPosition[i] = ', ' .. label end
) then else riderPosition[i] = '' end
riderReason[i] = ''
pcall(function() riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1643"][1].datavalue.value['numeric-id'] end)
if riderReason[i] == '' then pcall(function() riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1642"][1].datavalue.value['numeric-id'] end) end
if riderReason[i] == '' then pcall(function() riderReason[i] = 'Q'.. squadSeason.claims["P527"][i].qualifiers["P1534"][1].datavalue.value['numeric-id'] end) end
if riderReason[i] ~= '' then
local entity = mw.wikibase.getEntity( riderReason[i] )
local label = string.gsub(entity:getLabel("ar"), "%b()", "") or entity:getLabel('en')
--if label == null then label = entity:getLabel( 'en' ) end
riderRef[i] = references(squadSeason, 'P527', i)
riderReason[i] = ', ' .. label
end
local a, b
local timeofrace
local changedTime = '+0000-00-00'
local changedTeam = ''
local entity, label
local stagiaire
time[i]='' riderTeam[i] = ''
if pcall(function() timeofrace = squadSeason.claims["P527"][i].qualifiers["P580"][1].datavalue.value.time end)
then else timeofrace = startOfSeason end
if team ~= nil then a = true b = team -- if team known, don´t search for team
else a, b = timeStartEnd(riderIds[i], 'P54', 'numeric-id', timeofrace) team = b
end
if a == true and b ~= nil then
pcall(function()
local v
for _, v in pairs(rider.claims["P54"]) do -- look into all P54 teams
pcall(function() -- get trainee data from rider item
if v.mainsnak.datavalue.value['numeric-id'] == b then -- print riderStart[i], riderEnd[i], riderPosition[i], riderReason[i]
if riderReason[i] == '' then pcall(function() riderReason[i] = 'Q'.. v.qualifiers["P1643"][1].datavalue.value['numeric-id'] end) end
if riderReason[i] == '' then pcall(function() riderReason[i] = 'Q'.. v.qualifiers["P1642"][1].datavalue.value['numeric-id'] end) end
if riderReason[i] == '' then pcall(function() riderReason[i] = 'Q'.. v.qualifiers["P1534"][1].datavalue.value['numeric-id'] end) end
if string.sub(riderReason[i],1,1)=='Q' then -- only for these pcall-functions, not for those at line 970
local entity = mw.wikibase.getEntity( riderReason[i] )
local label = string.gsub(entity:getLabel("ar"), "%b()", "") or entity:getLabel('en')
if pcall(function() riderRef[i] = references(squadSeason, 'P527', i) end) then else riderRef[i]='' end
-- riderRef[i] = references(squadSeason, 'P527', i)
riderReason[i] = ', ' .. label
end
local date1 = v.qualifiers["P580"][1].datavalue.value.time
date1 = trans(date1,'01','01')
local _, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)")
local date2
if pcall(function() date2 = v.qualifiers["P582"][1].datavalue.value.time end) then else date2='+'..y1..'-12-31T00:00:00Z' end
date2 = trans(date2,'12','31')
local _, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)")
local _, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)")
if (y1 == y3 or y2 == y3) and ((y1 == y3 and (m1 ~= '01' or d1 ~= '01')) or (y2 == y3 and (m2 ~= '12' or d2 ~= '31'))) then
-- riders who start after 1 January or end earlier then 31 December in the season
riderStart[i] = func_date(date1, 'small')
if pcall(function()
local date = v.qualifiers["P582"][1].datavalue.value.time
riderEnd[i] = func_date(date2, 'small')
end
) then else riderEnd[i] = func_date('+'..y1..'-12-31T00:00:00Z', 'small') end
if riderPosition[i] == '' then -- find the 'position' (P39) of a rider
pcall(function() riderPosition[i] ='Q' ..v.qualifiers["P39"][1].datavalue.value['numeric-id']
local entity = mw.wikibase.getEntity( riderPosition[i] )
local label = string.gsub(entity:getLabel("ar"), "%b()", "") or entity:getLabel( 'en' )
riderPosition[i] = ', ' .. label
end)
end
end
end
end)
stagiaire = ''
pcall(function() stagiaire = v.qualifiers["P39"][1].datavalue.value['numeric-id'] end)
if v.mainsnak.datavalue.value['numeric-id'] ~= b and stagiaire == '' then -- find previous team and end time for the rider at that team
local date1 = v.qualifiers["P580"][1].datavalue.value.time
date1 = trans(date1,'01','01')
local _, _, y1, m1, d1 = string.find(date1, "(%d+)-(%d+)-(%d+)")
local date2
if pcall(function() date2 = v.qualifiers["P582"][1].datavalue.value.time end) then else date2='+'..y1..'-12-31T00:00:00Z' end
date2 = trans(date2,'12','31')
local _, _, y2, m2, d2 = string.find(date2, "(%d+)-(%d+)-(%d+)")
local _, _, y3, m3, d3 = string.find(startOfSeason, "(%d+)-(%d+)-(%d+)")
if y1 <= y3 then -- start time < season time
pcall(function()
local timeP582 = v.qualifiers["P582"][1].datavalue.value.time
timeP582 = trans(timeP582,'12', '31')
if timeP582 >= changedTime then -- find maximum end time
-- Case Pierre-Roger Latour: Chambéry CF (2012 - 2014), time season at 2013
-- Task: changedTime should be after start time, but before startOfSeason
local _, _, y4, m4, d4 = string.find(timeP582, "(%d+)-(%d+)-(%d+)")
if y4 > y3 then changedTime = '+'..y3..'-12-31T00:00:00Z' else changedTime = timeP582 end
changedTeam = v.mainsnak.datavalue.value['numeric-id']
end -- end if
end) -- end function
-- print riderTeam[i], time[i]
if changedTime ~= '+0000-00-00' then
pcall(function() riderTeam[i] = WPlink( 'Q'..changedTeam , 'team', changedTime ) end)
local _, _, y1, _, _ = string.find(changedTime, "(%d+)-(%d+)-(%d+)")
time[i] = ' ('..y1..')'
end
end
end -- end if
end -- end for
end) -- end function
end -- end if
local a, b = timeStartEnd( riderIds[i], 'P27', 'numeric-id', startOfSeason )
if a then
flags[i] = flag( 'Q' .. b, startOfSeason )
if available_list == true and type( translations.list ) == 'function' then
pays[i] = translations.list('Q'..b)
if pays[i] == '' then
local country = mw.wikibase.getEntityObject( 'Q'..b )
pays[i] = country:getLabel("ar") or country:getLabel('en') .. ' (en)'
end
end
else
flags[i] = ''
pays[i] = ''
end
i = i + 1
end
end)
-- sorting names after surname
if sort == true then
if language~='ja' then
table.sort(riderNames_transl, function(a,b) return a<b end)
table.sort(riderNames_notransl, function(a,b) return a<b end)
end
local ii, v1, v2, name1, name2, number
i = 1
-- sorting riders with a translation
for ii,name1 in ipairs(riderNames_transl) do
if name1 ~= '' then
v1, v2 = mw.ustring.find(name1, ":")
number = mw.ustring.sub(name1, v2+1)
name2, _ = mw.ustring.gsub(name1, ":%d+", "")
index[i] = tonumber(number)
i = i + 1
end
end
-- sorting riders without a translation
for ii,name1 in ipairs(riderNames_notransl) do
if name1 ~= '' then
v1, v2 = mw.ustring.find(name1, ":")
number = mw.ustring.sub(name1, v2+1)
name2, _ = mw.ustring.gsub(name1, ":%d+", "")
index[i] = tonumber(number)
i = i + 1
end
end
end
--=============================
--===
local borderStyle = 'border:1px solid rgb(200,200,200); padding: 4px'
if wiki == 'lv' then
borderStyle = 'border:0'
end
--[[local tableHeader = '{{سطر فريق دراجات/بداية|style='.. borderStyle
if WDlink_on == false then tableHeader = tableHeader .. '|id='.. frame.args[1].. '' end
tableHeader = tableHeader.. '|1=' .. getSquadTableColumn(1)..'|2=' .. getSquadTableColumn(2)
if available_list==true then tableHeader = tableHeader .. '|3=' .. getSquadTableColumn(6) end
tableHeader = tableHeader ..'|4=' .. getSquadTableColumn(3) .. '}}\n'
]]
local templatename = 'سطر فريق دراجات/بداية'
local tab_id , row3 , row4 = '' , '' , ''
local row1 = getSquadTableColumn(1)
local row2 = getSquadTableColumn(2)
if WDlink_on == false then tab_id = frame.args[1] end
if available_list ==true
then
row3 = getSquadTableColumn(6)
row4 = getSquadTableColumn(3)
else
row3 = getSquadTableColumn(3)
end
--=============================
--=============================
local tableEnd = '{{سطر فريق دراجات/نهاية}}'
local tableHeader = string.format([[{{%s|style=%s|id=%s|%s|%s|%s|%s}}
]], templatename , borderStyle, tab_id, row1, row2 , row3 , row4)
if typeoftemplate then
tableHeader = '{{Cycling squad start}}\n'
tableEnd = '{{Cycling squad end}}'
end
--=============================
--=============================
local tableEndText = ''
local tableBody , table_Body = '', ''
local tableSize = table.getn(riderNames)
local iii = 1
local row_temp_name = 'سطر فريق دراجات'
i = 1
while index[i] do
local row_name,row_flag, row_nat, row_birthdate, row_other = '' , '', '', '', ''
--tableBody = tableBody.. '\n{{| '
row_name = riderNames[index[i]]
if available_list==false
--then tableBody = tableBody.. flags[index[i]]..' '..riderNames[index[i]]
then
row_flag = '|علم=' .. flags[index[i]]
--else tableBody = tableBody.. riderNames[index[i]]
--else row_name = riderNames[index[i]]
end
if WDlink_on == true then row_name = row_name .. ' '.. wdLink(riderIds[index[i]]) end
row_name = row_name .. row_flag
if riderStart[index[i]]~='' or riderEnd[index[i]]~='' then
--tableBody = tableBody..'|other='..riderStart[index[i]]..'–'..riderEnd[index[i]].. riderPosition[index[i]]
row_other = '|other='..riderStart[index[i]]..'–'..riderEnd[index[i]].. riderPosition[index[i]]
if riderReason[index[i]] ~= ''
--then tableBody = tableBody.. ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
then row_other = row_other.. ', [[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
end
--tableBody = tableBody .. ''
elseif riderReason[index[i]]~='' then
--tableBody = tableBody.. '<span style="font-size:80%; color:#686868"> ([[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'.. ')</span>'
row_other = '|other=[[#tr_'..i..frame.args[1]..'|'..getSquadTableColumn(4)..']]'
end
--tableBody = tableBody.. ' |'
if wiki == 'lv' then
local _, _, y1, m1, d1 = string.find(startOfSeason,"(%d+)-(%d+)-0*(%d+)")
local _, _, y2, m2, d2 = string.find(riderBirthdays[index[i]],"(%d+)-(%d+)-0*(%d+)")
--tableBody = tableBody.. frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } }--.. '\n'
row_birthdate = frame:expandTemplate{ title = 'Template:Birth date and age2', args = { y1, m1, d1, y2, m2, d2 } }--.. '\n'
else
--tableBody = tableBody.. func_date (riderBirthdays[index[i]], 'long')
row_birthdate = func_date (riderBirthdays[index[i]], 'long')
if available_list ~= false
then row_nat = flags[index[i]].. ' '..pays[i]--.. '\n'
end
end
--tableBody = tableBody.. '<td style="padding:0 0.5em; text-align:right"><div dir="ltr">'
--tableBody = tableBody.. ' |'
local row_Team = ''
if riderTeam[index[i]] ~= nil
--then tableBody = tableBody.. riderTeam[index[i]].. time[index[i]]
then row_Team = riderTeam[index[i]].. time[index[i]]
end
if typeoftemplate then row_temp_name = 'Cycling squad rider' end
row_body = string.format([[{{%s|اسم=%s|جنسية=%s|ميلاد=%s|فريق سابق=%s %s}}
]], row_temp_name , row_name, row_nat, row_birthdate, row_Team, row_other)
table_Body = table_Body .. row_body
--tableBody = tableBody..'}}'
--tableBody = tableBody..'</div></td></tr>'
if riderReason[index[i]] ~= '' then
if iii == 1 then tableEndText = tableEndText.. getSquadTableColumn(5)..': '.. riderNames[index[i]].. riderReason[index[i]]
--else tableEndText = tableEndText.. '<span style="color:white">'.. getSquadTableColumn(5)..': </span>'.. riderNames[index[i]].. riderReason[index[i]] end
else tableEndText = tableEndText.. getSquadTableColumn(5)..':'.. riderNames[index[i]].. riderReason[index[i]] end
iii = iii + 1
if riderRef[index[i]] ~= '' then tableEndText = tableEndText..
frame:extensionTag{name='ref', content=riderRef[index[i]], args = {name='tr_'..i..frame.args[1]}} end
tableEndText = tableEndText.. '<br>'
end
i = i + 1
end
--if tableEndText ~= '' then tableEndText = getSquadTableColumn(5)..': <span style="font-size:80%; color:#686868">'.. tableEndText .. '</span>' end
--local tableStart = '<table style="'.. borderStyle.. '"><tr><td style="vertical-align:top;">'
--local tableStart = '{{سطر فريق دراجات/بداية|style='.. borderStyle.. '}}\n'
if labelMissing then tableEnd = tableEnd .. getMissingLabelTrackingCategory() end
return tableHeader.. table_Body.. tableEnd.. tableEndText
end
return p