Module:Sandbox/Paweł Ziemian/test

local m = {}

function m.D1(frame) mw.logObject(frame.args[1], "frame.args[1]") return frame.args[1] end

m.NumberOfArticlesBetween = function(frame) local pf = frame:getParent local start = frame.args[1] or pf.args[1] if not start then return end local stop = frame.args[2] or pf.args[2] if not stop then return end local content = mw.title.getCurrentTitle:getContent if not content then return end local startPattern = "" local startPosition = string.find(content, startPattern, 1, true) if not startPosition then return end startPosition = startPosition + #startPattern local stopPattern = "" local stopPosition = string.find(content, stopPattern, startPosition, true) if not stopPosition then return end stopPosition = stopPosition - 1 if startPosition >= stopPosition then return end local text = string.sub(content, startPosition, stopPosition) local _, count = mw.ustring.gsub(text, "(%[%^%[%-%]%])", "%1") local _, files = mw.ustring.gsub(text, "(%)", "%1") count = count - files local threshold = tonumber(frame.args.threshold or pf.args.threshold) or 1 if count < threshold then return end local lang = mw.getContentLanguage local number = lang:formatNum(count) local articles = lang:convertPlural(count, { frame.args[4] or pf.args[4] or "article", frame.args[5] or pf.args[6] or "articles" })

local result, _ = string.gsub(frame.args[3] or pf.args[3] or " ($1) ", "$1", number.." "..articles) return result end

m.countLinks = function(frame) local text = frame.args[1] if text then text = mw.text.trim(text) local _, count = mw.ustring.gsub(text, "(%[%^%[%-%]%])", "%1") if count >= 2 then local lang = mw.getContentLanguage local number = lang:formatNum(count) return text .. " ("..number.." articles) " else return text end end end

m.goodCounter = function(frame) local fullText = frame.args[1] if not fullText then return nil end function testlink(text) local b1 = string.byte(text, 1) if (b1 ~= 39) and (b1 ~= 91) then return false end local prefix = string.sub(text, 1, 7) if prefix == "[[File:" then			return false		end		return (string.sub(prefix, 1, 2) == "[[") or (string.sub(prefix, 1, 4) == "''[[")	end	local lang = mw.getContentLanguage	function showcounter(counter)		local number = lang:formatNum(counter)		return " ("..number.." articles) \n"	end	local lines = mw.text.split(fullText, "\n", true)	local counter = 0	local result = {}	for i, line in ipairs(lines) do		if os.clock > 30 then			break		end		if testlink(line) then			table.insert(result, line)			counter = counter + 1		else			if counter > 1 then				table.insert(result, showcounter(counter))			end			counter = 0			table.insert(result, line)		end		table.insert(result, "\n")	end	if counter > 1 then		table.insert(result, showcounter(counter))	end

return table.concat(result, "") end

local easter = require("Module:Easter")

local function prepareDateFormatter(format) if not format then local convertToRoman = { ["03"] = "III", ["04"] = "IV", ["05"] = "V", } return function(date) local month = convertToRoman[string.sub(date,6,7)] local day = tonumber(string.sub(date,9)) return day .. " " .. month end elseif format == "none" then return function(date) return date end else local lang = mw.language.getContentLanguage return function(date) return lang:formatDate(format, date) end end end

function m.Table2(frame) local firstYear = tonumber(frame.args[1]) local lastYear = tonumber(frame.args[2]) local formatDate = prepareDateFormatter(frame.args.format) local result = {} table.insert(result, " ") return table.concat(result,"") end

-- look into entity object function m.ViewSomething(frame) local f = (frame.args[1] or frame.args.id) and frame or frame:getParent local data = mw.wikibase.getEntityObject(f.args.id) if not data then return nil end

local i = 1 while true do		local index = f.args[i] if not index then if type(data) == "table" then return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY) else return tostring(data) end end data = data[index] or data[tonumber(index)] if not data then return end i = i + 1 end end

local i18n = { ["warnDump"] = "" }

function m.Dump(frame) local f = (frame.args[1] or frame.args.id) and frame or frame:getParent local data = mw.wikibase.getEntityObject(f.args.id) if not data then return i18n.warnDump end

local i = 1 while true do		local index = f.args[i] if not index then return " "..mw.dumpObject(data).." ".. i18n.warnDump end

data = data[index] or data[tonumber(index)] if not data then return i18n.warnDump end

i = i + 1 end end

return m