پودمان:Wikishia

از ویکی تراث

توضیحات این پودمان می‌تواند در پودمان:Wikishia/توضیحات قرار گیرد.

local fgetFAlist = require('Module:Wikishia/Selected').getFAlist
local fgetFPlist = require('Module:Wikishia/بوابات').getFPlist

local a = {}

function a.rnumber( frame )
    d = {}

	if (frame.args[1] =='fa' or frame.args[1] =='Selected' ) then
		d = fgetFAlist()
		return #d
	elseif (frame.args[1] =='fp' or frame.args[1] =='بوابات' ) then
		d = fgetFPlist()
		local nb =0
		for t,s in pairs(d) do
			nb = nb+1
		end
		return nb
	end
end

function a.rlist( frame )
    d = {}
    if(frame.args[1] =='ga' or frame.args[1] =='Good' ) then
    	d = fgetGAlist()
	elseif (frame.args[1] =='fa' or frame.args[1] =='Selected' ) then
		d = fgetFAlist()
	end
    
    math.randomseed( os.time() )
    x = math.random(1,#d) 
    repeat
    	x1 = math.random(1,#d)
	until x1 ~= x
    repeat
    	x2 = math.random(1,#d)
	until (x2 ~= x and x2 ~= x1)

    return "[["..d[x1].."]] – [["..d[x].."]] – [["..d[x2].."]]" 
end

function a.plist(frame)
    local c = ''
    local d = {}
    if(frame.args[1] =='ga' or frame.args[1] =='Good' ) then
    	d = fgetGAlist()
    	for _,s in ipairs(d) do
       		c = c .. "\n# [[" .. s .. "]]"
    	end    	
	elseif (frame.args[1] =='fa' or frame.args[1] =='Selected' ) then
		d = fgetFAlist()
    	for _,s in ipairs(d) do
       		c = c .. "\n# [[" .. s .. "]]"
    	end    	
	elseif (frame.args[1] =='fp' or frame.args[1] =='بوابات' ) then
		d = fgetFPlist()
    	for t,s in pairs(d) do
       		c = c .. "\n# [[" ..t.."|".. s[3] .. "]]"
    	end    	
	end

  return c 
end
----
---- _RandOne : النتيجة هي اسم عشوائي مقالة واحدة مختارة/جيدة
local function _getOnepDay( frame )
    d = {}
	math.randomseed( os.time() )
	
    if (frame.args[1] =='dyk' or frame.args[1] =='learning' ) then
		local nbf = mw.site.stats.pagesInCategory( 'Project list did you know', 'pages' )
		if(type(nbf) ~= "number") then return '' end
    	---- x = math.random(1,nbf)
    	x = (math.floor(os.time()/(24*3600)) % nbf ) +1
		return frame:expandTemplate{ title = 'Main page/Know/Current', args = {  x } }
    elseif (frame.args[1] =='fpic' or frame.args[1] =='Picture' ) then
		d = fgetFPiclist()
		local nbf=0
    	for t,s in pairs(d) do
       		nbf = nbf + 1
    	end
    	---- x = math.random(1,nbf)
    	x = math.floor(os.time()/(24*3600)) % nbf 
		local nb=0
    	for t,s in pairs(d) do
       		nb = nb + 1
       		if(nb == x) then
       			return frame:expandTemplate{ title = 'Main page/Main/Right/Picture/Template', args = {  t, s[1],  s[2] } }
       		end
    	end
    	x = math.floor(os.time()/(24*3600)) % nbf
		local nb=0
    	for t,s in pairs(d) do
       		nb = nb + 1
       		if(nb == x) then
       			return frame:expandTemplate{ title = 'كلمة اليوم', args = {  s[1],  s[2] } }
       		end
    	end
    elseif (frame.args[1] =='fp' or frame.args[1] =='بوابات' ) then
		d = fgetFPlist()
		local nbf=0
    	for title,items in pairs(d) do
       		nbf = nbf + 1
    	end
    	--- x = math.random(1,nbf)
    	x = math.floor(os.time()/(24*3600)) % nbf
		local nb=0
    	for t,s in pairs(d) do
       		nb = nb + 1
       		if(nb == x) then
       			return frame:expandTemplate{ title = 'بوابة اليوم المختارة/قالب', args = {  s[1],  s[2], t , s[3] } }
       		end
    	end
	elseif(frame.args[1] =='ga' or frame.args[1] =='Good' ) then
    	d = fgetGAlist()
	elseif (frame.args[1] =='fa' or frame.args[1] =='Selected' ) then
		d = fgetFAlist()
	end
    
    
    ---x = math.random(1,#d)
    x = math.floor(os.time()/(24*3600)) % #d
    return x --d[x]
end

local function _LCount( items )
	local nb = 0
	for _, item in ipairs(items) do
             nb = nb +1
    end
    return nb     
end
	
local function _OneDay( frame )

    local dayList = {}
    local monthList = {}
    local articles = {}
    local nbarts = 0
	
	math.randomseed( os.time() )
	
    if(frame.args[1] =='Selected' or frame.args[1] =='Good' ) then      
    	
    	---- التأكد أولا بوجود مقالة مخصصة لهذا اليوم بالذات
    	dayList = mw.loadData('Module:Wikishia/'.. frame.args[1]..'/Date')
    	for date1, articles in pairs(dayList) do
    		if( date1 == mw.getContentLanguage():formatDate('Y-n-d') ) then
    		   nbarts = _LCount(articles)
               if(nbarts == 1) then
                 	return articles[1]
            		elseif nbarts > 1 then
            		return articles[math.random(1,nbarts) ]
        		end
    		end
    	end

        --- البحث عن ذكرى سنوية
        monthList = mw.loadData('Module:Wikishia/'.. frame.args[1]..'/Month/'..mw.getContentLanguage():formatDate('n'))

        articles = monthList[mw.getContentLanguage():formatDate('d')]

        if(type(articles) ~= 'table') then
          return ''
        end

        nbarts = _LCount(articles)

        if(nbarts == 0) then
            return ''
            elseif nbarts == 1 then
            return articles[1]
            else
            return articles[math.random(1,nbarts) ]
        end
    end
    return ''
end

function a.selectArt(frame)

   local title = _OneDay( frame )
   if(title ~= '') then
     return title
   else
     return _getOnepDay( frame )
   end
end

----
----
return a