Module:විශේෂ ව්‍යාපෘති

From Wikisource
Jump to navigation Jump to search

අදාළ දත්ත, Module:විශේෂ ව්‍යාපෘති/දත්ත වෙත ඇතුළු කරන්න.


-- විශේෂ ව්‍යාපෘති සඳහා වන මොඩියුලය මෙය වේ

local p = {} --p යනු පැකේජය යන්න සඳහා වේ

function get_month_index(data)
	return 7
end

function get_current_work_index_in_month(month_data)
	
	local work_index = month_data["current"]
	if work_index == nil then
		work_index = 1
	end
	
	return work_index
end

function get_option(month_data)
	if month_data['overflow'] then
		-- if overflowed...
		return "overflow"
	elseif get_current_work_index_in_month(month_data) > 1 then
		-- or we haven't overflowed to "little works", but we have gotten to a second work
		return "extra"
	end
	
	return nil
end

function get_base_params(work, month_data)
	
	local file = work["image"]
	if file == nil then
		file = "Featured article star - check.svg"
	end
	
	local filesize = work["imagesize"]
	if filesize == nil then
		filesize = 75
	end	

	local base_args = {
		POTMindex = work["index"],
		POTMtitle = work["display"],
		POTMauthor = work["author"],
		POTMyear   = work["year"],
		option = get_option(month_data),
		POTMfile = file,
		POTMfilesize = filesize,
	}

	if string.match(work["author"], "%[%[Author:") then
		base_args["override_author"] = work["author"]
	else
		base_args["POTMauthor"] = work["author"]
	end	
	
	return base_args
end

function get_recents(data, limit, first_month)

	local recents = {}
	local skip = 1 -- ignore the first one, that's the current work
	
	-- iterate months
	for k, month in pairs(data) do
		local broken = false
		if k >= first_month then
			
			-- don't read past the "current" work in a month
			local last_idx = get_current_work_index_in_month(month)
	
			for i=last_idx, 1, -1 do
				
				local work = month["works"][i]
	
				if skip == 0 then
					table.insert(recents, work)
				else
					skip = skip - 1
				end
				
				if (#recents == limit) then
					broken = true
					break
				end
			end
		end
		
		if broken then
			break
		end
	end
	
	return recents
end


function index_link(index, display)
	return "[[Index:" .. index .. "|" .. display .. "]]"
end


function format_recents(data, limit, first_month)
	local recents = get_recents(data, limit, first_month)
	
	local formatted = {}
	
    for k, work in pairs(recents) do
        formatted[k] = index_link(work["index"], work["display"])
    end
    return table.concat(formatted, ", ")
end

--[=[
මෙය [[Module:විශේෂ ව්‍යාපෘති/දත්ත]] හි අඩංගු තොරතුරු වලට අනුව {{ශ්‍රමදාන/වත්මන් ව්‍යාපෘතිය}} ආමන්ත්‍රණය කරයි
]=]
function p.shramadhaana_wathman_vYaapruthi(frame)
	local data = mw.loadData('Module:විශේෂ ව්‍යාපෘති/දත්ත')
	
	local month_index = get_month_index(data)
	local curr_month = data[month_index]
	local curr_work_index = get_current_work_index_in_month(curr_month)
	local curr_work = curr_month["works"][curr_work_index]
	
	local num_recents = 10
	local base_args = get_base_params(curr_work, curr_month)

	base_args["POTMrecent"] = format_recents(data, num_recents, month_index)

	if string.match(curr_work["author"], "%[%[") then
		base_args["override_author"] = curr_work["author"]
	else
		base_args["POTMauthor"] = curr_work["author"]
	end
	
	return frame:expandTemplate{ title = 'ශ්‍රමදාන/වත්මන්_ව්‍යාපෘතිය', args = base_args }
end

return p