وحدة:FifaRanking

من ويكيبيديا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث

الاستخدام[عدل]

هذه الوحدة مستخدمة في عدة قوالب مثل :

local a = {}

local function _score(s)
	if(s>0) then
		return 	"[[file:Green Arrow Up Darker.svg|10px]] "..s
	elseif(s<0) then
		return	"[[file:Decrease2.svg|10px]]&nbsp;"..math.abs(s)
	else	return "[[file:Straight Line Steady.svg|10px]]"
	end
end

function _spairs(t, order)
    -- collect the keys
    local keys = {}
    for k in pairs(t) do keys[#keys+1] = k end

    -- if order function given, sort by it by passing the table and keys a, b,
    -- otherwise just sort the keys 
    if order then
        table.sort(keys, function(a,b) return order(t, a, b) end)
    else
        table.sort(keys)
    end

    -- return the iterator function
    local i = 0
    return function()
        i = i + 1
        if keys[i] then
            return keys[i], t[keys[i]]
        end
    end
end

function a.getRankURL(frame)
	local rk = {}
    if(frame.args[1] ~= nil and type(frame.args[1]) == 'string') then
       if(frame.args[1] == 'men') then
          rk = mw.loadData('Module:FifaRanking/men')
      elseif (frame.args[1] == 'women') then
      	  rk = mw.loadData('Module:FifaRanking/women')
  	  else
  		return ''
  	  end
	else
  		rk = mw.loadData('Module:FifaRanking/men')
	end
	return rk.rankurl
end

function a.getRankDate(frame)
	local rk = {}
    if(frame.args[1] ~= nil and type(frame.args[1]) == 'string') then
       if(frame.args[1] == 'men') then
          rk = mw.loadData('Module:FifaRanking/men')
      elseif (frame.args[1] == 'women') then
      	  rk = mw.loadData('Module:FifaRanking/women')
  	  else
  		return ''
  	  end
	else
  		rk = mw.loadData('Module:FifaRanking/men')
	end
	return rk.rankdate
end

function a.getRank( frame )
	local rk = {}
    if(frame.args[2] ~= nil and type(frame.args[2]) == 'string') then
       if(frame.args[2] == 'men') then
          rk = mw.loadData('Module:FifaRanking/men')
      elseif (frame.args[2] == 'women') then
      	  rk = mw.loadData('Module:FifaRanking/women')
  	  else
  		return ''
  	  end
	else
  		rk = mw.loadData('Module:FifaRanking/men')
    end
	team = frame.args[1]

	if( rk.teams[team] ~= nil and type(rk.teams[team]) == 'table') then
		local datetxt = frame:callParserFunction{ name = '#time', args = { '[[j F]] [[Y]]', rk.rankdate } }
		local datetxt2 = frame:callParserFunction{ name = '#time', args = { 'F Y', rk.rankdate } }
                if( rk.teams[team][1] ~= 0) then
		return  rk.teams[team][1].."&nbsp;".._score(rk.teams[team][4]).."<small><br />("..datetxt2..")</small>"..frame:extensionTag{ name = 'ref', content = "["..rk.rankurl.." موقع الفيفا] - ترتيب :"..datetxt}
                else
                    return "غير مصنف&nbsp;<small><br />("..datetxt2..")</small>"..frame:extensionTag{ name = 'ref', content = "["..rk.rankurl.." موقع الفيفا] - ترتيب :"..datetxt}
               end
	end
	return ''
end

function a.getRankTable(frame)
	local rk = {}
	local root = ''
	local line
	local nfttpl ='ك ق' 

    if(frame.args[1] ~= nil and type(frame.args[1]) == 'string') then
       if(frame.args[1] == 'men') then
          rk = mw.loadData('Module:FifaRanking/men')
          nfttpl ='ك ق'
      elseif (frame.args[1] == 'women') then
      	  rk = mw.loadData('Module:FifaRanking/women')
          nfttpl ='ك ق س'
  	  else
  		return ''
  	  end
	   else
  		rk = mw.loadData('Module:FifaRanking/men')
	end

	local maxteam = 500
    if(frame.args['stop'] ~= nil and tonumber(frame.args['stop']) ~= nil) then
		maxteam = tonumber(frame.args['stop'])
	end

	local cc = 0
	for team, data in _spairs(rk.teams,function(t,a,b) return t[a][1]< t[b][1] end) do
		if(data ~= nil and type(data) == 'table') then
			if(cc > maxteam) then break end
			if(data[1] ~= 0) then 
			cc = cc + 1
			line = mw.html.create( 'tr' )
			line
				:tag('th')
					:wikitext(data[1])
				:tag('td')
					:css('text-align','right')
					:wikitext(frame:expandTemplate{title =nfttpl,args = {team, align='y' }})
				:tag('td')
					:wikitext(_score(data[4]))
				:tag('td')
					:wikitext(data[2])
				:tag('td')
					:wikitext(data[3])
			root = root .. tostring(line)
			end
		end
	end
	return root
end

return a