Մոդուլ:Banana

Վիքիպեդիայից՝ ազատ հանրագիտարանից
Jump to navigation Jump to search

Documentation for this module may be created at Մոդուլ:Banana/doc

local p = {}
local lang = mw.language.getContentLanguage()
local currentYear = tonumber( lang:formatDate( 'Y' ) )

local function checkPageExists( title )
    if not title then
        error('No title passed to checkArchiveExists', 2)
    end
    local noError, titleObject = pcall(mw.title.new, title)
    if not noError then
        -- If we are over the expensive function limit then assume
        -- that the page doesn't exist.
        return false
    else
        if titleObject then
            return titleObject.exists
        else
            return false -- Return false if given a bad title.
        end
    end
end

local function yearCheck( archive )
	result = ''
	year = 2005
	while year < currentYear do 
		title = string.gsub( archive, "%%%(year%)d", year)
		if checkPageExists( title ) then
			result = result .. '* [[' .. title .. ']]\n'
		end
		year = year + 1
	end
	return result
end

function p.main( frame )
	local args = frame:getParent().args
	if string.match( args['archive'], "%%%(year%)d" ) ~= nil then
		return yearCheck(args['archive'])
	else
		-- TODO
		return ''
	end
end

return p