Module:Main page
Appearance
Documentation for this module may be created at Module:Main page/doc
local p = {}
local lang = mw.getContentLanguage()
--- Prefixes for each type of main page content
-- The key is the parameter to the 'current' function
local prefixes = {
picture = "விக்கிப்பீடியா:இன்றைய சிறப்புப் படம்/",
dyk = "User:Shrikarsan/test/1/",
fa = "User:Shrikarsan/test/",
tdta = {prefix ="விக்கிப்பீடியா:ஆண்டு நிறைவுகள்/", format = "F j" },
portal = {prefix = "விக்கிப்பீடியா:வலைவாசல்கள்/", format="F"},
list = {prefix = "விக்கிப்பீடியா:பட்டியல்கள்/", format="F"}
}
--- Returns a page for this type and that date if it exists, nil otherwise
-- @param type_name String that is a key in the 'prefixes' table
-- @param date Timestamp (in a format that mw.language:formatDate accepts) to give page for
-- @return a string page title if it exists, nil otherwise
function existing_page_for( type_name, date )
local type_data = prefixes[ type_name ]
local page_name
if type( type_data ) == 'table' then
page_name = type_data['prefix'] .. lang:formatDate( type_data['format'], tostring(date) )
else
page_name = type_data .. lang:formatDate( 'F j, Y', tostring(date) )
end
local title = mw.title.new( page_name )
if title.exists then
return page_name
else
return nil
end
end
--- Returns the expanded text for the current main page content specified by the first argument 'type'
-- Checks the page for the current date for the type (using existing_page_for). If it exists, it is
-- expanded and returned. If not, we keep trying prior dates until we find one that exists, and then
-- expand and return it.
function p.current( frame )
local type = frame.args[1]
local cur_date = os.date()
local i = 0
while true do
cur_date = os.date( nil, os.time() - (i * 24 * 60 * 60) )
i = i + 1
page = existing_page_for( type, cur_date )
if page then
return frame:expandTemplate{title=page}
end
end
end
return p