Module:Backwards copy
| This Lua module is used on approximately 1,500 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Implements {{backwards copy}}
local MessageBox = require("Module:Message box")
local yesno = require("Module:Yesno")
local p = {}
local function demoCheck(args)
return yesno(args["demo"]) or yesno(args["nocat"])
end
local function showWarning(text, nocat)
mw.addWarning(text)
return nocat and "" or "[[Category:Pages with backwards copy warnings]]"
end
local function delink(text)
if text == nil then
return nil
end
return string.gsub(string.gsub(require("Module:Delink")._delink{text}, "%[%[", ""), "%]%]", "")
end
local function showError(text, nocat)
return string.format(
"%s%s %s",
nocat and "" or "[[Category:Pages with backwards copy errors]] ",
tostring(
mw.html.create("span")
:css("color", "var(--color-error)")
:css("font-weight", "bold")
:wikitext("Error:")
),
text
)
end
local function row(args, i)
return mw.html.create("li"):wikitext(rowText)
end
local function bannerText(frame, args)
local text = ""
local id = args["id"] or args["revid"]
if id ~= nil then
text = string.format("Revisions succeeding [[Special:Diff/%s|this version]] of this", id)
else
text = "This"
end
local citations = {}
local i = 1
while (
args[tostring(i)] or
(args["articlename" .. i] or (i == 1 and args["articlename"])) or
(args["title" .. i] or (i == 1 and args["title"]))
) do
if args[tostring(i)] then
table.insert(citations, args[tostring(i)])
else
local author = args["author" .. i] or (i == 1 and args["author"])
local date = (args["date" .. i] or (i == 1 and args["date"])) or
-- legacy way of providing dates
string.format(
"%s %s",
args["monthday" .. i] or (i == 1 and args["monthday"]) or "",
args["year" .. i] or (i == 1 and args["year"]) or ""
)
if mw.text.trim(date or "") == "" then
if string.match(author or "", "(%d%d%d[%d]+)") then
text = text .. " " .. showWarning(string.format(
"A <code>year%s</code> or <code>date%s</code> parameter was not found, but a parenthesized year was found in the " ..
"<code>author%s</code> parameter. Move the provided year to the correct parameter.",
i, i, i
), demoCheck(args))
else
text = text .. " " .. showWarning(string.format(
"Provided <code>title%s</code> must also have a respective <code>year%s</code> or <code>date%s</code> parameter.",
i, i, i
))
end
end
local display_authors = args["display-authors" .. i] or (i == 1 and args["display-authors"]); -- get |display-authors= parameter value for this reference
if tonumber (display_authors) and (0 ~= tonumber (display_authors)) then -- for {{backwards copy}} only allowed number is 0 to suppress author name list
display_authors = 'etal'; -- any other number gets 'etal'; any other text will be rejected by cs1|2
end
table.insert(citations, frame:expandTemplate{ title = "Citation", args = {
ref = "none",
author = author,
["display-authors"] = display_authors,
date = date,
url = args["url" .. i] or (i == 1 and args["url"]),
title = (args["articlename" .. i] or (i == 1 and args["articlename"]))
or args["title" .. i] or (i == 1 and args["title"]),
publisher = (args["org" .. i] or (i == 1 and args["org"]))
or args["publisher" .. i] or (i == 1 and args["publisher"])
} })
end
i = i + 1
end
text = string.format(
"%s article is substantially duplicated in one or more external publications. " ..
"Since these publication(s) copied Wikipedia, rather than the reverse, please do not flag this article as a copyright violation of the following source",
text
)
local citationCount = #citations
if citationCount == 0 then
return showError(
"No citations were provided. Provide at least one citation using <code>title</code>.",
demoCheck(args)
)
elseif citationCount > 1 then
text = string.format("%ss:", text)
else
text = string.format("%s:", text)
end
local ul = mw.html.create("ul")
for k, v in pairs(citations) do
ul:node(mw.html.create("li"):wikitext(v))
end
text = string.format(
"%s %s %s",
text,
tostring(ul),
args["comments"] and tostring(
mw.html.create("table")
:attr("class", "mw-collapsible mw-collapsed")
:attr("style", "width:100%; background-color: var(--background-color-warning-subtle);color:var(--color-base);")
:node(mw.html.create("tr")
:node(mw.html.create("th")
:wikitext("Additional comments")
)
)
:node(mw.html.create("tr"):node(mw.html.create("td")
:attr("style", "background-color: var(--background-color-base); color:var(--color-base); border: 1px solid #c0c090; padding: 0.25em 0.5em;")
:wikitext(
args["comments"]
)
))
) or ""
)
return text
end
function p.renderBanner(frame, args)
return MessageBox.main('tmbox', {
name = "backwards-copy",
small = yesno(args["small"]),
image = '[[File:Newspaper Cover.svg|50px]]',
text = bannerText(frame, args)
}) .. ((demoCheck(args) or mw.title.getCurrentTitle().namespace == 10) and
"" or "[[Category:Wikipedia article talk pages incorporating the backwards copy template]]"
)
end
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {
trim = true,
removeBlanks = true
})
return p.renderBanner(frame, args)
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.