Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Citation: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Attempt at creating italics function for better reading)
m (Attempt to implement quoting feature)
Line 7: Line 7:
local function italics (var)
local function italics (var)
return "''" .. var .. "''"
return "''" .. var .. "''"
end
local function parenthesis (var)
return " (" .. var .. ")"
end
end
Line 33: Line 37:
if is_set (Author) then
if is_set (Author) then
if is_set (Year) then
if is_set (Year) then
x1 = Author .. " (" .. Year .. ")" .. ". "
first_part = Author .. parenthesis (Year) .. ". "
else
else
x1 = Author .. "."
first_part = Author .. "."
end
end
else
else
x1 = ""
first_part = ""
end
end


Line 49: Line 53:
Chapter = "[" .. ChapterURL .. " " .. Chapter .. "]"
Chapter = "[" .. ChapterURL .. " " .. Chapter .. "]"
end
end
x2 = "'" .. Chapter .. "'" .. " in " .. "''" .. Title .. "''"
second_part = "'" .. Chapter .. "'" .. " in " .. "''" .. Title .. "''"
else
else
x2 = italics(Title)
second_part = italics(Title)
if not is_set (Author) then
if not is_set (Author) then
if is_set (Year) then
if is_set (Year) then
x2 = x2 .. " (" .. Year .. ")"
second_part = second_part .. " (" .. Year .. ")"
end
end
end
end
Line 61: Line 65:
if is_set (Trans) then
if is_set (Trans) then
if is_set (TransLang) then
if is_set (TransLang) then
x2 = x2 .. " (" .. TransLang .. ": " .. Trans .. ")"
second_part = second_part .. " (" .. TransLang .. ": " .. Trans .. ")"
else
else
x2 = x2 .. " (" .. Trans .. ")"
second_part = second_part .. " (" .. Trans .. ")"
end
end
end
end
Line 73: Line 77:
Page = "pp. " .. Page
Page = "pp. " .. Page
end
end
x2 = x2 .. " (" .. Page .. ")."
second_part = second_part .. " (" .. Page .. ")."
else
else
x2 = x2 .. "."
second_part = second_part .. "."
end
end
end
end
Line 86: Line 90:
:tag( 'small' )
:tag( 'small' )
:wikitext('[' .. PDF .. " " .. mw.text.nowiki('[PDF]') .. ']')
:wikitext('[' .. PDF .. " " .. mw.text.nowiki('[PDF]') .. ']')
x2 = x2 .. " " .. tostring(span)
second_part = second_part .. " " .. tostring(span)
end
end
if is_set (City) then
if is_set (City) then
if is_set (Publisher) then
if is_set (Publisher) then
x3 = City .. ": " .. Publisher .. "."
third_part = City .. ": " .. Publisher .. "."
else
else
x3 = City .. "."
third_part = City .. "."
end
end
elseif is_set(Publisher) then
elseif is_set(Publisher) then
x3 = Publisher .. "."
third_part = Publisher .. "."
else
else
x3 = ""
third_part = ""
end
end


x4 = ""
fourth_part = ""


if is_set (ISBN) then
if is_set (ISBN) then
Line 110: Line 114:
:tag( 'small' )
:tag( 'small' )
:wikitext('[' .. "https://www.worldcat.org/search?qt=worldcat_org_all&q=" .. ISBN .. " " .. "ISBN " .. ISBN .. ']')
:wikitext('[' .. "https://www.worldcat.org/search?qt=worldcat_org_all&q=" .. ISBN .. " " .. "ISBN " .. ISBN .. ']')
x4 = x4 .. tostring(span)
fourth_part = fourth_part .. tostring(span)
end
end


if is_set (DOI) then
if is_set (DOI) then
x4 = x4 .. " doi:" .. DOI
fourth_part = fourth_part .. " doi:" .. DOI
local span = mw.html.create ( 'span' )
local span = mw.html.create ( 'span' )
span
span
Line 121: Line 125:
:tag( 'small' )
:tag( 'small' )
:wikitext('[' .. "https://sci-hub.se/" .. DOI .. " " .. mw.text.nowiki('[HUB]') .. ']')
:wikitext('[' .. "https://sci-hub.se/" .. DOI .. " " .. mw.text.nowiki('[HUB]') .. ']')
x4 = x4 .." " .. tostring(span)
fourth_part = fourth_part .." " .. tostring(span)
end
end
Line 131: Line 135:
:tag( 'small' )
:tag( 'small' )
:wikitext('[' .. LG .. " " .. mw.text.nowiki('[LG]') .. ']')
:wikitext('[' .. LG .. " " .. mw.text.nowiki('[LG]') .. ']')
x4 = x4 .." " .. tostring(span)
fourth_part = fourth_part .." " .. tostring(span)
end
end
Line 141: Line 145:
:tag( 'small' )
:tag( 'small' )
:wikitext('[' .. MIA .. " " .. mw.text.nowiki('[MIA]') .. ']')
:wikitext('[' .. MIA .. " " .. mw.text.nowiki('[MIA]') .. ']')
x4 = x4 .." " .. tostring(span)
fourth_part = fourth_part .." " .. tostring(span)
end
end
Line 149: Line 153:
:attr('width','80%')
:attr('width','80%')
:attr('margin-left','10%')
:attr('margin-left','10%')
:wikitext("''" .. Quote .. "''")
:wikitext(italics (Quote))
mw.html.create('br')
mw.html.create('br')
end
end
first_part = Quote .. first_part


if is_set (x1) then
if is_set (first_part) then
x1 = x1 .. " "
first_part = first_part .. " "
end
end
if is_set (x2) then
if is_set (second_part) then
x2 = x2 .. " "
second_part = second_part .. " "
end
end
if is_set (x3) then
if is_set (third_part) then
x3 = x3 .. " "
third_part = third_part .. " "
end
end


return x1 .. x2 .. x3 .. x4
return first_part .. second_part .. third_part .. fourth_part
end
end
return p
return p

Revision as of 06:20, 10 November 2021

local p = {}

local function is_set (var)
	return not (var == nil or var == '');
end

local function italics (var)
	return "''" .. var .. "''"
end

local function parenthesis (var)
	return " (" .. var .. ")"
end
	

function p.cite( frame )
	local pframe = frame:getParent()

	local Author = pframe.args.author
	local Year = pframe.args.year
	local Chapter = pframe.args.chapter
	local ChapterURL = pframe.args['chapter-url']
	local Title = pframe.args.title
	local TitleURL = pframe.args['title-url']
	local Trans = pframe.args['trans-title']
	local TransLang = pframe.args['trans-lang']
	local Page = pframe.args.page
	local PDF = pframe.args.pdf
	local City = pframe.args.city
	local Publisher = pframe.args.publisher
	local ISBN = pframe.args.isbn
	local DOI = pframe.args.doi
	local LG = pframe.args.lg
	local MIA = pframe.args.mia
	local Quote = pframe.args.quote

	if is_set (Author) then
		if is_set (Year) then
			first_part = Author .. parenthesis (Year) .. ". "
			else
				first_part = Author .. "."
		end
		else
			first_part = ""
	end

	if is_set (Title) then
		if is_set (TitleURL) then
			Title = "[" .. TitleURL .. " " .. Title .. "]"
			end
		if is_set (Chapter) then
			if is_set (ChapterURL) then
				Chapter = "[" .. ChapterURL .. " " .. Chapter .. "]"
				end
			second_part = "'" .. Chapter .. "'" .. " in " .. "''" .. Title .. "''"
			else
				second_part = italics(Title)
				if not is_set (Author) then
					if is_set (Year) then
					second_part = second_part .. " (" .. Year .. ")"
					end
				end
		end
		
		if is_set (Trans) then
			if is_set (TransLang) then
				second_part = second_part .. " (" .. TransLang .. ": " .. Trans .. ")"
				else
					second_part = second_part .. " (" .. Trans .. ")"
			end
		end

		if is_set (Page) then
			if tonumber(Page) ~= nil then
				Page = "p. " .. Page
				else
					Page = "pp. " .. Page
			end
				second_part = second_part .. " (" .. Page .. ")."
			else
				second_part = second_part .. "."
		end
	end
	
	if is_set (PDF) then
		local span = mw.html.create ( 'span' )
		span
		:attr( 'title', 'PDF download')
		:addClass('plainlinks')
		:tag( 'small' )
		:wikitext('[' .. PDF .. " " .. mw.text.nowiki('[PDF]') .. ']')
		second_part = second_part .. " " .. tostring(span)
	end
	
	if is_set (City) then
		if is_set (Publisher) then
			third_part = City .. ": " .. Publisher .. "."
			else
				third_part = City .. "."
				end
		elseif is_set(Publisher) then
			third_part = Publisher .. "."
			else
				third_part = ""
		end

	fourth_part = ""

	if is_set (ISBN) then
		local span = mw.html.create ( 'span' )
		span
		:attr( 'title', 'WorldCat')
		:addClass('plainlinks')
		:tag( 'small' )
		:wikitext('[' .. "https://www.worldcat.org/search?qt=worldcat_org_all&q=" .. ISBN .. " " .. "ISBN " .. ISBN .. ']')
		fourth_part = fourth_part .. tostring(span)
	end

	if is_set (DOI) then
		fourth_part = fourth_part .. " doi:" .. DOI
		local span = mw.html.create ( 'span' )
		span
		:attr( 'title', 'Sci-Hub link')
		:addClass('plainlinks')
		:tag( 'small' )
		:wikitext('[' .. "https://sci-hub.se/" .. DOI .. " " .. mw.text.nowiki('[HUB]') .. ']')
		fourth_part = fourth_part .." " .. tostring(span)
	end
	
	if is_set (LG) then
		local span = mw.html.create ( 'span' )
		span
		:attr( 'title', 'Library Genesis link')
		:addClass('plainlinks')
		:tag( 'small' )
		:wikitext('[' .. LG .. " " .. mw.text.nowiki('[LG]') .. ']')
		fourth_part = fourth_part .." " .. tostring(span)
	end
	
	if is_set (MIA) then
		local span = mw.html.create ( 'span' )
		span
		:attr( 'title', 'Marxists Internet Archive link')
		:addClass('plainlinks')
		:tag( 'small' )
		:wikitext('[' .. MIA .. " " .. mw.text.nowiki('[MIA]') .. ']')
		fourth_part = fourth_part .." " .. tostring(span)
	end
	
	if is_set (Quote) then
		local div = mw.html.create ('div')
		div
		:attr('width','80%')
		:attr('margin-left','10%')
		:wikitext(italics (Quote))
		mw.html.create('br')
	end
	first_part = Quote .. first_part
		
		

	if is_set (first_part) then
		first_part = first_part .. " "
	end
	
	if is_set (second_part) then
		second_part = second_part .. " "
	end
	
	if is_set (third_part) then
		third_part = third_part .. " "
	end

	return first_part .. second_part .. third_part .. fourth_part
end
return p