Module:Citation/CS1
From All Skies Encyclopaedia
<section begin=header />
![]() | This Lua module is used on approximately 6,110,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module can only be edited by administrators because it is transcluded onto one or more cascade-protected pages. |
Lua error: bad argument #1 to "get" (not a valid title).<section end=header /> This module and associated sub-modules support the Citation Style 1 and Citation Style 2 citation templates. In general, it is not intended to be called directly, but is called by one of the core CS1 and CS2 templates. <section begin=module_components_table /> These files comprise the module support for CS1|2 citation templates:
<section end=module_components_table />
Other documentation:
- Module talk:Citation/CS1/Feature requests
- Module talk:Citation/CS1/COinS
- Module:Cs1 documentation support – a set of functions (some experimental) that extract information from the module suite for the purpose of documenting CS1|2
- Module:Citation/CS1/doc/Category list – lists of category names taken directly from Module:Citation/CS1/Configuration and Module:Citation/CS1/Configuration/sandbox
testcases
- Module:Citation/CS1/testcases (run)
- Module:Citation/CS1/testcases/errors (run) – error and maintenance messaging
- Module:Citation/CS1/testcases/dates (run) – date validation
- Module:Citation/CS1/testcases/identifiers (run) – identifiers
- Module:Citation/CS1/testcases/anchor (run) – CITEREF anchors
--require "mw.text"
local p = {}
-- This can be removed when mw.text.tag appears.
function tag(frame, t)
local name = t.name or "!--"
local content = t.contents or ""
local params = ""
for n,v in pairs(t.params) do
params = params .. "|" .. n .. "=" .. v
end
return frame:preprocess("{{#tag:" .. name .. "|" .. content .. params .. "}}")
end
function doi(frame, i)
return frame:preprocess("{{doi|" .. i .. "}}")
end
function authorprefix(Surname, Given, Authorlink, ampersand)
if (Surname == nil) then return "" end
local prefix = ampersand .. Surname
if (Given ~= nil) then prefix = prefix .. ", " .. Given end
if (Authorlink ~= nil) then prefix = "[[" .. Authorlink .. "|" .. prefix .. "]]" end
return prefix
end
function anchorid(frame)
local P1 = frame.args[1] or ""
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
local P5 = frame.args[5] or ""
return "CITEREF" .. P1 .. P2 .. P3 .. P4 .. P5
end
function name(frame)
local P1 = frame.args[1] or ""
if ( frame.args[5] ~= nil) then
return P1 .. " et al."
else
local P2 = frame.args[2] or ""
local P3 = frame.args[3] or ""
local P4 = frame.args[4] or ""
if ( frame.args[4] ~= nil ) then
P4 = " " .. P4
P3 = " & " .. P3
P2 = " & " .. P2
elseif ( frame.args[3] ~= nil ) then
P3 = " " .. P3
P2 = " & " .. P2
elseif ( frame.args[2] ~= nil ) then
P2 = " " .. P2
end
return P1 .. P2 .. P3 .. P4
end
end
function crossref(pframe, frame)
local LB = frame.BracketLeft or ""
local RB = frame.BracketRight or ""
local anchor = pframe.ref or pframe.Ref or anchorid(pframe)
local text = name(pframe)
local loc = pframe.loc or ""
local page = pframe.p or pframe.page or nil
local pages = pframe.pp or pframe.pages or nil
if ( page ~= nil ) then
local pagesep = frame.PageSep or ""
text = text .. pagesep .. page
end
if ( pages ~= nil ) then
local pagessep = frame.PagesSep or ""
text = text .. pagessep .. pages
end
local ps = pframe.Postscript or ""
return LB .. "[[#" .. anchor .. "|" .. text .. "]]" .. RB .. ps
end
function citation(pframe, frame)
local AuthorMask = pframe.authormask or pframe.authormask or ""
local Surname1 = pframe.last or pframe.surname or pframe.last1 or pframe.surname1 or pframe.author1 or pframe.authors or pframe.author or ""
local Surname2 = pframe.last2 or pframe.surname2 or pframe.author2
local Surname3 = pframe.last3 or pframe.surname3 or pframe.author3
local Surname4 = pframe.last4 or pframe.surname4 or pframe.author4
local Surname5 = pframe.last5 or pframe.surname5 or pframe.author5
local Surname6 = pframe.last6 or pframe.surname6 or pframe.author6
local Surname7 = pframe.last7 or pframe.surname7 or pframe.author7
local Surname8 = pframe.last8 or pframe.surname8 or pframe.author8
local Surname9 = pframe.last9 or pframe.surname9 or pframe.author9
local Given1 = pframe.first1 or pframe.given1 or pframe.first or pframe.given
local Given2 = pframe.first2 or pframe.given2
local Given3 = pframe.first3 or pframe.given3
local Given4 = pframe.first4 or pframe.given4
local Given5 = pframe.first5 or pframe.given5
local Given6 = pframe.first6 or pframe.given6
local Given7 = pframe.first7 or pframe.given7
local Given8 = pframe.first8 or pframe.given8
local Given9 = pframe.first9 or pframe.given9
local Authorlink1 = pframe.authorlink or pframe.author1link or pframe.authorlink1
local Authorlink2 = pframe.author2link or pframe.authorlink2
local Authorlink3 = pframe.author3link or pframe.authorlink3
local Authorlink4 = pframe.author4link or pframe.authorlink4
local Authorlink5 = pframe.author5link or pframe.authorlink5
local Authorlink6 = pframe.author6link or pframe.authorlink6
local Authorlink7 = pframe.author7link or pframe.authorlink7
local Authorlink8 = pframe.author8link or pframe.authorlink8
local Authorlink9 = pframe.author9link or pframe.authorlink9
local Coauthors = pframe.coauthor or pframe.coauthors
local Date = pframe.date or ((pframe.day or "") .. (pframe.month or "") .. (pframe.year or pframe.publicationdate or ""))
local Title = pframe.title
local URL = pframe.archiveurl or pframe.url
local Series = pframe.series
local Volume = pframe.volume
local Issue = pframe.issue or pframe.number
local Edition = pframe.edition
local Place = pframe.place or pframe.location
local PublicationPlace = pframe.publicationplace or pframe.place or pframe.location
local Publisher = pframe.publisher or ""
local Language = pframe.language
local Format = pframe.format or ""
local ISBN= pframe.isbn or pframe.ISBN
local DOI= pframe.doi or pframe.DOI
if ( Title ~= nil ) then Title = " ''" .. Title .. "''." else Title = "" end
local text = "(" .. Date .. ")." .. Title .. " " .. Publisher
text = authorprefix(Surname1, Given1, Authorlink1, "") .. text
text = authorprefix(Surname2, Given2, Authorlink2, "; ") .. text
text = authorprefix(Surname3, Given3, Authorlink3, "; ") .. text
text = authorprefix(Surname4, Given4, Authorlink4, "; ") .. text
text = authorprefix(Surname5, Given5, Authorlink5, "; ") .. text
text = authorprefix(Surname6, Given6, Authorlink6, "; ") .. text
text = authorprefix(Surname7, Given7, Authorlink7, "; ") .. text
text = authorprefix(Surname8, Given8, Authorlink8, "; ") .. text
text = authorprefix(Surname9, Given9, Authorlink9, "; ") .. text
if ( ISBN ~= nil ) then text = text .. " ISBN " .. ISBN end
if ( DOI ~= nil ) then text = text .. " " .. doi(DOI) end
return text
end
-- This is used by templates such as {{SfnRef}} to create the (encoded) anchor name for a Harvard cross-reference hyperlink.
function p.SFNID(frame)
local pframe = frame:getParent()
return anchorid(pframe)
end
-- This is used by templates such as {{Harvard citation}} to create the Harvard cross-reference text.
function p.Harvard(frame)
local pframe = frame:getParent()
return crossref(pframe, frame)
end
-- This is used by templates such as {{cite book}} to create the actual citation text.
function p.citation(frame)
local pframe = frame:getParent()
return citation(pframe, frame)
end
-- This is used by templates such as {{sfn}} to create the entire cross-reference.
function p.sfn(frame)
local pframe = frame:getParent()
local content = crossref(pframe, frame)
local args = { name = anchorid(pframe) }
-- return mw.text.tag{name = "ref", contents = content, params = args}
return tag(frame, {name = "ref", contents = content, params = args})
end
return p