Module:Sandbox/Danski454/chance

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

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 return displayError({'"' .. title .. '" is not a valid article title'}) elseif not page.exists then--expensive return displayError({'"' .. title .. '" does not exist'}) elseif page.isRedirect then return displayError({'"' .. title .. '" is a redirect to "' .. page.redirectTarget.prefixedText .. '", you may be looking for that page instead'}) end local content = page:getContent --remove unwanted content --content = string.gsub(content, "\n%s%\n", "\n")--files --content = string.gsub(content, "%s*\n%s*([^|%s])", "%1")--infoboxes content = string.gsub(content, "%b[]", function (match)			if string.find(match, "[[File:", 1, true) == 1 or string.find(match, "[[Image:", 1, true) == 1 then				return ""			end			return match		end)--files	content = string.gsub(content, "", "")--stub templates	content = string.gsub(content, "%b{}", function (match)			if string.find(match, "{{[iI]nfobox") == 1 or string.find(match, "{{[mM]ultiple image") == 1 then				return ""			end			return match		end)--infoboxes and multiple images	content = string.gsub(content, "%[%[Category%:..-%]%]", "")--categories	content = string.gsub(content, "", "")--galleries	content = string.gsub(content, "==%s*References%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*Notes%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*Endnotes%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*Footnotes%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*Works cited%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*Further reading%s*==.+", "")--references etc section down	content = string.gsub(content, "==%s*External links%s*==.+", "")--references etc section down	content = string.gsub(content, "\n=([^\n]+)=\n", "\n==%1==\n")--reduce heading levels	--add header	content = "== [[" .. title .. "]] ==\n" .. content .. "\n{{tref}}"	return content end

return p