মডিউল:সংগ্রহশালার সূচিপত্র: সংশোধিত সংস্করণের মধ্যে পার্থক্য

উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে
বিষয়বস্তু বিয়োগ হয়েছে বিষয়বস্তু যোগ হয়েছে
সম্পাদনা সারাংশ নেই
সম্পাদনা সারাংশ নেই
১ নং লাইন: ১ নং লাইন:
local p = {}
local p = {}
local plaintext = require("মডিউল:সরল পাঠ্য")
local plaintext = require("মডিউল:সরল পাঠ্য")
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")
local function split_into_threads(text, level3)
local function split_into_threads(text, level3)
৪৯ নং লাইন: ৫০ নং লাইন:
seen[topic] = (seen[topic] or 0) +1
seen[topic] = (seen[topic] or 0) +1
local link = string.format("[[%s#%s]]", title.prefixedText, frame:callParserFunction("anchorencode", {linktopic}))
local link = string.format("[[%s#%s]]", title.prefixedText, frame:callParserFunction("anchorencode", {linktopic}))
out = out .. string.format("\n|-\n| %s || %s || %s", thread.topic, tostring(reply_count), link)
out = out .. string.format("\n|-\n| %s || %s || %s", thread.topic, convert('bn',tostring(reply_count)), link)
end
end
return out
return out

২২:২২, ১১ জানুয়ারি ২০২১ তারিখে সংশোধিত সংস্করণ

".../সংগ্রহশালার সূচিপত্র" নামে পাতা তৈরি করুন ও নিচের কোড যুক্ত করুন:

{{#invoke:সংগ্রহশালার সূচিপত্র|main|mask=/সংগ্রহশালা <#>|indexhere=yes}}

একাধিক তালিকাভুক্ত করতে:

{{#invoke:সংগ্রহশালার সূচিপত্র|main|
|mask1=পূর্ণ নাম/সংগ্রহশালা <#>
|mask2=পূর্ণ নাম/সংগ্রহশালা <#>
|mask3=পূর্ণ নাম/সংগ্রহশালা <#>
|indexhere=yes
}}

local p = {}
local plaintext = require("মডিউল:সরল পাঠ্য")
local convert = require('মডিউল:সংখ্যা রূপান্তরকারী').convert
local yesno = require("Module:Yesno")
local function split_into_threads(text, level3)
	local threads = {}
	local current_thread
	local header_pat 
	text = "\n" .. text
	if level3 then
		header_pat = '\n===[	]*([^=].-)[ 	]* === *\n' 
	else
		header_pat = '\n==[ 	]*([^=].-) *==[ 	]*\n' 
	end
	local last = 1
	while true do 
		local start, endindex, topic = text:find(header_pat, last)
		if current_thread then 
			current_thread.content = text:sub(last, start)
			threads[#threads + 1] = current_thread
		end
		current_thread = {topic = topic}
		if start == nil then
			-- hit end of page
			break
		end
		last = endindex + 1
	end
	if not threads and not level3 then
		return split_into_threads(text, true)
	end
	return threads
end
local function parse_archive(title, out)
	local frame = mw.getCurrentFrame()
	if title.isRedirect then
		title = title.redirectTarget
	end
	local threads = split_into_threads(title:getContent())
	local seen = {}
	for _, thread in ipairs(threads) do
		local __, reply_count = thread.content:gsub("%(ইউটিসি%)","")
		local linktopic
		local topic = thread.topic
		if seen[topic] then
			linktopic = topic .. " " .. tostring(seen[topic] + 1)
		else
			linktopic = topic
		end
		seen[topic] = (seen[topic] or 0) +1
		local link = string.format("[[%s#%s]]", title.prefixedText, frame:callParserFunction("anchorencode", {linktopic}))
		out = out .. string.format("\n|-\n| %s || %s || %s", thread.topic, convert('bn',tostring(reply_count)), link)
	end
	return out
end	
-- End of copied code. The below code was written by me, without paying much attention to the relevant Legobot code
local function resolve_relative(mask, frame) 
	local title = frame:getParent():getTitle()
	local titleObj = mw.title.new(title)
	if titleObj.subpageText == "সংগ্রহশালার সূচিপত্র" then
		title = titleObj.nsText .. ":" .. titleObj.baseText
	end
	return title .. mask
end
function p._onemask(mask, frame)
	if frame == nil then
		frame = mw.getCurrentFrame()
	end
	if mask:sub(1,1) == "/" then
		mask = resolve_relative(mask, frame)
	end
	local out = ""
	if mask:find("<#>") then
		local archivecount = 0
		while true do
			archivecount = archivecount + 1
			local title = mw.title.new(mask:gsub("<#>",tostring(archivecount)))
			if not title.exists then
				return out
			end
			out = parse_archive(title, out)
		end
	else
		local title = mw.title.new(mask)
		out = parse_archive(title, out)
	end
	return out
end
function p.main(frame)
	local out = ""
	out = out .. frame:extensionTag("templatestyles","",{src="মডিউল:সংগ্রহশালার সূচিপত্র/শৈলী.css"})
	out = out .. '\n{| class="sortable"\n! আলোচনার প্রসঙ্গ !! উত্তর (আনুমানিক) !! সংগ্রহশালার সংযোগ'
	if frame.args.mask then
		out = out .. p._onemask(frame.args.mask, frame)
	end
	local masknum = 1
	while true do
		local maskArg = frame.args["mask" .. tostring(masknum)]
		if maskArg then
			out = out .. p._onemask(maskArg, frame)
			masknum = masknum + 1
		else
			break
		end
	end
	if yesno(frame.args.indexhere) then
		out = parse_archive(mw.title.new(resolve_relative("", frame)), out)
	end
	return out
end
return p