Module:smallest discussions

Hello, you have come here looking for the meaning of the word Module:smallest discussions. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:smallest discussions, but we will also tell you about its etymology, its characteristics and you will know how to say Module:smallest discussions in singular and plural. Everything you need to know about the word Module:smallest discussions you have here. The definition of the word Module:smallest discussions will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:smallest discussions, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module generates contents for Template:smallest discussions.


local export = {}

local shortLinkLength = 24
local columns = 4

local function parseLink(frame, page, section, format)

	if mw.ustring.find(section, "{") then
		section = frame:preprocess(section)
	end
	section = section:gsub("%[%[:", "[[")
	section = section:gsub("%]-|", "")
	section = section:gsub("%[%[", "")
	section = section:gsub("%]%]", "")

	local display = section
	if format == "box" and mw.ustring.len(display) > shortLinkLength then
		display = mw.ustring.sub(display, 1, shortLinkLength):gsub(" +$", "") .. "..."
	end

	result = "]"
	result = result:gsub("%<.-%>", "")

	return result
end

local function parsePage(frame, page, maxItems, format)
	local pageObject = mw.title.new(page)
	if pageObject.isRedirect then
		pageObject = pageObject.redirectTarget
		if format == "full" then
			page = pageObject.nsText .. ":" .. pageObject.text
		end
	end
	local pageText = pageObject:getContent()
	local pageLength = string.len(pageText)

	local pageResults = ""

	local discussionCount = 0
	local discussions = {}

	for line, newlines in pageText:gmatch('(*)(\n*)') do
		local m = line:match('^== *%f(.*)%f *==$')
		if m then
			discussionCount = discussionCount + 1
			discussions = {title = m, length = newlines:len()}
		elseif discussionCount > 0 then
			discussions.length = discussions.length + line:len() + newlines:len()
		end
	end
	pageText = nil -- use less memory

	table.sort(discussions, function (a, b) return a.length < b.length end)

	if format == "full" then
		pageResults = pageResults .. "<h2>]</h2>"
		pageResults = pageResults .. "<small>Discussions: ".. discussionCount .. "</small><br/><small>Bytes: ".. pageLength .. "</small>"
		pageResults = pageResults .. '<div style="column-count:' .. columns .. '; -moz-column-count:' .. columns .. '; -webkit-column-count:' .. columns .. '">'
	elseif format == "box" then
		pageResults = pageResults .. "]"
	end

	pageResults = pageResults .. "<ol>"
	for i, discussion in ipairs(discussions) do
		if i > maxItems then
			break
		end
		pageResults = pageResults .. '<li>' .. parseLink(frame, page, discussion.title, format) .. ' <small dir="ltr">(' .. discussion.length .. ')</small></li>'
	end
	pageResults = pageResults .. "</ol>"

	if format == "full" then
		pageResults = pageResults .. '</div>'
	end

	return pageResults
end

local box_pre = [=[
<div class="toc" style="clear:right; float:right; width:auto; min-width:15em; border-top: none;">
<div class="mw-collapsible mw-collapsed"><strong>]</strong>
<div class="mw-collapsible-content" style="margin-top: 10px; display:none;">
]=]

local function allPages(frame, pages, maxItems, format)
	local resultText = ""

	if format == "box" then
		resultText = resultText .. box_pre
	end

	for k, v in pairs(pages) do
		resultText = resultText .. parsePage(frame, v, maxItems, format)
	end

	if format == "box" then
		resultText = resultText .. '</div></div></div>'
	end

	return resultText
end

function export.show(frame, maxItems)
	local args = frame:getParent().args
	local format = args
	local maxItems = tonumber(args)
	local pages = {}
	local i = 3
	while args do
		table.insert(pages, args)
		i = i + 1
	end
	return allPages(frame, pages, maxItems, format)
end

return export