Jump to content

Module:Lorem ipsum: Difference between revisions

From WikipediNyah
Created page with "local yn = require("Module:Yesno") return { main = function(frame) local args = require("Module:Arguments").getArgs(frame) local data = args["data"] and mw.loadData(args["data"]) or mw.loadData("Module:Lorem_ipsum/data") local paragraphs = {} for k,v in ipairs(data) do table.insert(paragraphs, v) end local out = '' local link = yn(args["link"]) or yn(args[4]) or false local join = yn(args["join"]) or false local joinprefixsuffix = yn(args["joinprefi..."
Tags: Mobile edit Mobile web edit Advanced mobile edit
 
No edit summary
 
Line 1: Line 1:
local yn = require("Module:Yesno")
local yn = require("Module:Yesno")
return {
local p = {}
main = function(frame)
 
local args = require("Module:Arguments").getArgs(frame)
function p._main(args)
local data = args["data"] and mw.loadData(args["data"]) or mw.loadData("Module:Lorem_ipsum/data")
local paragraphs = {}
local paragraphs = {}
local outTbl = setmetatable({}, {__call = function (t, v) t[#t+1] = v end})
for k,v in ipairs(data) do
local link = yn(args["link"]) or yn(args[4]) or false
table.insert(paragraphs, v)
local join = yn(args["join"]) or false
local joinprefixsuffix = yn(args["joinprefixsuffix"]) or false
local cat = yn(args["cat"]) or true
local count = tonumber(args[1]) or 1
local i = tonumber(args["start"]) or 1
local data = mw.loadData(args["data"] or "Module:Lorem_ipsum/data")
local maxLen = tonumber(args["max len"])
for k,v in ipairs(data) do
table.insert(paragraphs, v)
end
if join and (not joinprefixsuffix) then
outTbl(args["prefix"] or args[2] or "")
end
 
while i > 0 and i <= count do
if (not join) or joinprefixsuffix then
outTbl(args["prefix"] or args[2] or "\n")
end
end
local out = ''
mw.log(count, i, data)
local link = yn(args["link"]) or yn(args[4]) or false
outTbl(mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or "")))
local join = yn(args["join"]) or false
if not join then
local joinprefixsuffix = yn(args["joinprefixsuffix"]) or false
outTbl((args["suffix"] or args[3] or "") .. "\n")
local cat = yn(args["cat"]) or true
else
local count = tonumber(args[1] or 1)
if joinprefixsuffix then
local i = 1
outTbl(args["suffix"] or args[3] or "")
if join and (not joinprefixsuffix) then
out = out .. (args["prefix"] or args[2] or "")
end
while i <= count do
if (not join) or joinprefixsuffix then
out = out .. (args["prefix"] or args[2] or "\n")
end
end
out = out .. mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or ""))
outTbl(i == count and "" or " ")
if not join then
out = out .. (args["suffix"] or args[3] or "") .. "\n"
else
if joinprefixsuffix then
out = out .. (args["suffix"] or args[3] or "")
end
out = out .. (i == count and "" or " ")
end
link = false
i = i + 1
end
end
if join and (not joinprefixsuffix) then
link = false
out = out .. (args["suffix"] or args[3] or "")
i = i + 1
end
end
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
if join and (not joinprefixsuffix) then
out = out .. "[[Category:Wikipedia articles containing placeholders]]"
outTbl(args["suffix"] or args[3] or "")
end
end
return frame:preprocess(out)
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
end,
outTbl("[[Category:Wikipedia articles containing placeholders]]")
oneParagraph = function(frame)
local args = require("Module:Arguments").getArgs(frame)
local data = args["data"] and mw.loadData(args["data"]) or mw.loadData("Module:Lorem_ipsum/data")
local paragraphs = {}
for k,v in ipairs(data) do
table.insert(paragraphs, v)
end
local i = tonumber(args[1] or 1)
local link = yn(args["link"])
local paragraph = paragraphs[math.mod(i - 1, #paragraphs) + 1]
local out = ""
if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
out = out .. "[[Category:Wikipedia articles containing placeholders]]"
end
out = out .. mw.ustring.format(paragraph, (link and "link" or ""))
out = frame:preprocess(out)
local maxLen = tonumber(args["max len"] or mw.ustring.len(out))
return mw.ustring.sub(out, 1, maxLen)
end
end
}
local outStr = mw.getCurrentFrame():preprocess(table.concat(outTbl))
return maxLen and mw.ustring.sub(outStr, 1, maxLen) or outStr
end
 
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame)
return p._main(args, false)
end
 
function p.oneParagraph(frame)
local args = require("Module:Arguments").getArgs(frame)
args["join"] = true
args["start"] = tonumber(args[1]) or 1
return p._main(args)
end
 
return p

Latest revision as of 02:50, 2 July 2026

For actual documentation, view the corresponding Wikipedia pages.


local yn = require("Module:Yesno")
local p = {}

function p._main(args)
	local paragraphs = {}
	local outTbl = setmetatable({}, {__call = function (t, v) t[#t+1] = v end})
	local link = yn(args["link"]) or yn(args[4]) or false
	local join = yn(args["join"]) or false
	local joinprefixsuffix = yn(args["joinprefixsuffix"]) or false
	local cat = yn(args["cat"]) or true
	local count = tonumber(args[1]) or 1
	local i = tonumber(args["start"]) or 1
	local data = mw.loadData(args["data"] or "Module:Lorem_ipsum/data")
	local maxLen = tonumber(args["max len"])
	for k,v in ipairs(data) do
		table.insert(paragraphs, v)
	end
	
	if join and (not joinprefixsuffix) then
		outTbl(args["prefix"] or args[2] or "")
	end

	while i > 0 and i <= count do
		if (not join) or joinprefixsuffix then
			outTbl(args["prefix"] or args[2] or "\n")
		end
		mw.log(count, i, data)
		outTbl(mw.ustring.format(paragraphs[math.mod(i - 1, #paragraphs) + 1], (link and "link" or "")))
		if not join then
			outTbl((args["suffix"] or args[3] or "") .. "\n")
		else
			if joinprefixsuffix then
				outTbl(args["suffix"] or args[3] or "")
			end
			outTbl(i == count and "" or " ")
		end
		link = false
		i = i + 1
	end
	if join and (not joinprefixsuffix) then
		outTbl(args["suffix"] or args[3] or "")
	end
	if cat and mw.title.getCurrentTitle().namespace == 0 and not mw.isSubsting() then
		outTbl("[[Category:Wikipedia articles containing placeholders]]")
	end
	local outStr = mw.getCurrentFrame():preprocess(table.concat(outTbl))
	return maxLen and mw.ustring.sub(outStr, 1, maxLen) or outStr
end

function p.main(frame)
	local args = require("Module:Arguments").getArgs(frame)
	return p._main(args, false)
end

function p.oneParagraph(frame)
	local args = require("Module:Arguments").getArgs(frame)
	args["join"] = true
	args["start"] = tonumber(args[1]) or 1
	return p._main(args)
end

return p