Difference between revisions of "Module:Sandbox/Danski454/chance"

From blackwiki
Jump to navigation Jump to search
blackwiki>Danski454
(Created page with '--implement some tasks in Template:2nd chance local p = {} local getArgs = require('Module:Arguments').getArgs function p.main( frame ) local args = getArg...')
 
blackwiki>Danski454
(dev)
Line 15: Line 15:
 
end
 
end
 
local content = page.getContent()
 
local content = page.getContent()
+
--remove unwanted content
 +
--content = string.gsub(content, "\n%s%[%[File:..-%]%]\n", "\n")--files
 +
--content = string.gsub(content, "{{[iI]nfobox..-}}%s*\n%s*([^|%s])", "%1")--infoboxes
 +
content = string.gsub(content, "%b[]", function (match)
 +
if string.find(match, "[[File:", 1, true) == 1 then
 +
return ""
 +
end
 +
return match
 +
end)--files
 +
content = string.gsub(content, "{{[^{}\n]+%-stub}}", "")--stub templates
 +
content = string.gsub(content, "%b{}", function (match)
 +
if string.find(match, "{{[iI]nfobox") == 1 then
 +
return ""
 +
end
 +
return match
 +
end)--infoboxes
 +
content = string.gsub(content, "%[%[Category%:..-%]%]", "")--categories
 +
--add header
 +
content = "== [[" .. title .. "]] ==\n" .. content
 +
return content
 
end
 
end
 +
 +
return p

Revision as of 20:35, 14 January 2019

Usage

This module implements many parts of the instructions on Template:2nd chance. This module must be substituted. If it is not, the content cannot be edited and will not be fully parsed.

{{subst:#invoke:Sandbox/Danski454|main|EXACT PAGE NAME}}



--implement some tasks in [[Template:2nd chance]]
local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main( frame )
	local args = getArgs(frame)
	local title = args[1]
	local page = mw.title.new( title, 0 )
	if (not page) or page.namespace ~= 0 or page.isExternal then
		error('"' .. title .. '" is not a valid article title')
	elseif not page.exists then
		error('"' .. title .. '" does not exist')
	elseif page.isRedirect then
		error('"' .. title .. '" is a redirect to "' .. page.redirectTarget .. '" you may be looking for that page instead')
	end
	local content = page.getContent()
	--remove unwanted content
	--content = string.gsub(content, "\n%s%[%[File:..-%]%]\n", "\n")--files
	--content = string.gsub(content, "{{[iI]nfobox..-}}%s*\n%s*([^|%s])", "%1")--infoboxes
	content = string.gsub(content, "%b[]", function (match)
			if string.find(match, "[[File:", 1, true) == 1 then
				return ""
			end
			return match
		end)--files
	content = string.gsub(content, "{{[^{}\n]+%-stub}}", "")--stub templates
	content = string.gsub(content, "%b{}", function (match)
			if string.find(match, "{{[iI]nfobox") == 1 then
				return ""
			end
			return match
		end)--infoboxes
	content = string.gsub(content, "%[%[Category%:..-%]%]", "")--categories
	--add header
	content = "== [[" .. title .. "]] ==\n" .. content
	return content
end

return p