Difference between revisions of "Module:Sandbox/Danski454/chance"
Jump to navigation
Jump to search
blackwiki>Danski454 m (add comma) |
blackwiki>Danski454 (add hatnote) |
||
| Line 9: | Line 9: | ||
if (not page) or page.namespace ~= 0 or page.isExternal then | if (not page) or page.namespace ~= 0 or page.isExternal then | ||
error('"' .. title .. '" is not a valid article title') | error('"' .. title .. '" is not a valid article title') | ||
| − | elseif not page.exists then | + | elseif not page.exists then--expensive |
error('"' .. title .. '" does not exist') | error('"' .. title .. '" does not exist') | ||
elseif page.isRedirect then | elseif page.isRedirect then | ||
| Line 40: | Line 40: | ||
content = string.gsub(content, "==%s*External links%s*==.+", "")--references etc section down | content = string.gsub(content, "==%s*External links%s*==.+", "")--references etc section down | ||
--add header | --add header | ||
| − | content = "== [[" .. title .. "]] ==\n" .. content .. "\n{{tref}}" | + | local originRev = frame:callParserFunction("REVISIONID", title)--expensive |
| + | |||
| + | content = "== [[" .. title .. "]] ==\n{{hatnote|Copied from [[" .. title .. | ||
| + | "]] <span class=\"plainlinks\">([{{fullurl:Special:ComparePages|page1=".. title .."&rev1=".. originRev .. | ||
| + | "&page2={{FULLPAGENAME}}}}diff from copied revision]; [{{fullurl:Special:ComparePages|page1=".. title .. | ||
| + | "&page2={{FULLPAGENAME}}}}diff from current revision])<\\span>}}" .. content .. "\n{{tref}}" | ||
return content | return content | ||
end | end | ||
return p | return p | ||
Revision as of 21:42, 14 January 2019
| This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
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--expensive
error('"' .. title .. '" does not exist')
elseif page.isRedirect then
error('"' .. 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%[%[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
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
--add header
local originRev = frame:callParserFunction("REVISIONID", title)--expensive
content = "== [[" .. title .. "]] ==\n{{hatnote|Copied from [[" .. title ..
"]] <span class=\"plainlinks\">([{{fullurl:Special:ComparePages|page1=".. title .."&rev1=".. originRev ..
"&page2={{FULLPAGENAME}}}}diff from copied revision]; [{{fullurl:Special:ComparePages|page1=".. title ..
"&page2={{FULLPAGENAME}}}}diff from current revision])<\\span>}}" .. content .. "\n{{tref}}"
return content
end
return p