உள்ளடக்கத்துக்குச் செல்

Module:Main page

விக்கிமேற்கோள் இலிருந்து

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 = {
    quote  = "விக்கிமேற்கோள்:தினம் ஒரு மேற்கோள்/",
}
--- 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) )
    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 = 1
    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
"https://ta.wikiquote.org/w/index.php?title=Module:Main_page&oldid=8275" இலிருந்து மீள்விக்கப்பட்டது