FANDOM


local p = {}
local u = require('Module:Utility')
 
function p.show(frame)
   return p.randSlider(frame, 0)
end
 
function p.showdef(frame)
   return p.randSlider(frame, 1)
end
 
function p.randSlider(frame, iDefault)
   local tArgs1,tArgs2 = u.getArgs(frame)
   if tArgs1 and not(tArgs1[1]) then tArgs1= tArgs2 end
   if not(tArgs1[1]) and not(tArgs2[1]) then return end
   local tMedia ={}
   local sIndexes = ""
   math.randomseed( mw.site.stats.edits + mw.site.stats.pages + os.time() + math.floor(os.clock() * 1000000000))
   math.random()
   local sFiles ='<gallery type="slider" orientation="bottom">\n'
 
   if iDefault == 1 then 
      sFiles = sFiles .. tArgs1[1]..'\n'
      tMedia[1]=tArgs1[1]
   end
     local iIndex = 0
     while iIndex < 4 do
       local entry = math.random(1,#tArgs1)
       if tArgs1 and not(tArgs1[entry] == tMedia[entry]) and not(iDefault == entry) then
         tMedia[entry]= tArgs1[entry]
         sFiles = sFiles..tMedia[entry]..'\n'
         sIndexes = sIndexes .."-".. entry
         iIndex = iIndex +1
       end
       if (#tMedia == #tArgs1) then
          break;
       end
     end
   sFiles = sFiles .."</gallery>"
   local oGallery =frame:preprocess(sFiles)
   return oGallery
end
return p