打开/关闭菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

Module:引用

来自普罗百科,无产者的百科全书
更多语言
Forte讨论 | 贡献2022年8月12日 (五) 13:05的版本 (Imported module from English version and adapted to Chinese template arguments)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

可在Module:引用/doc创建此模块的帮助文档

local p = {}

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

local function italics (var)
	return "<i>" .. var .. "</i>"
end

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

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

	local Author = pframe.args['作者'] or pframe.args.author
	local Year = pframe.args['年'] or pframe.args.year
	local Chapter = pframe.args['章节'] or pframe.args.chapter
	local ChapterURL = pframe.args['章节-url'] or pframe.args['chapter-url']
	local Section = pframe.args['小节'] or pframe.args.section
	local Title = pframe.args['标题'] or pframe.args.title
	local TitleURL = pframe.args['标题-url'] or pframe.args['title-url']
	local Volume = pframe.args['卷'] or pframe.args.volume 
	local Series = pframe.args['系列'] or pframe.args.series
	local Trans = pframe.args['trans-title']
	local TransLang = pframe.args['trans-lang']
	local Page = pframe.args['页'] or pframe.args.page
	local PDF = pframe.args.pdf
	local City = pframe.args['城市'] or pframe.args.city
	local Publisher = pframe.args['出版者'] or 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['引用'] or pframe.args.quote
	local Image = pframe.args['图片'] or pframe.args.image
	local ImageCaption = pframe.args['image-caption']
		

	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 (Quote) then
		Quote = string.gsub(Quote,"\n","<br>")
		Quote = "“" .. Quote .. "”"
		local div = mw.html.create ('div')
		div
		:attr("style", "width:80%; margin-left:10%;")
		:wikitext(Quote)
		local br = mw.html.create ('br', selfClosing)
		first_part = italics(tostring(div)) .. tostring(br) .. first_part
	end
	
	if is_set (Image) then
		local span = mw.html.create ( 'span' )
		span
		:wikitext('[[File:' .. Image .. '|center|300px|frameless]]')

		if is_set(ImageCaption) then 
			local caption = mw.html.create ('div')
			caption
			:attr("style", "text-align:center;font-size:85%;")
			:wikitext(ImageCaption)
			first_part = tostring(span) .. tostring(caption) .. first_part
			else
				first_part = tostring(span) .. first_part
		end
				
	end
		

	if is_set (Title) then
		if is_set (TitleURL) then
			Title = "[" .. TitleURL .. " " .. Title .. "]"
		end
		Title = italics(Title)
		if not is_set (Series) then
			if is_set (Volume) then
				Title = Title .. ", vol. " .. Volume
			end
		end
		second_part = Title
		if is_set (Chapter) then
			if is_set (ChapterURL) then
				Chapter = "[" .. ChapterURL .. " " .. Chapter .. "]"
			end
			if is_set (Section) then
				Chapter = Chapter .. "; " .. Section
			end
			second_part = second_part .. ": " .. "'" .. Chapter .. "'"
		end
		
		if not is_set (Author) then
			if is_set (Year) then
				second_part = second_part .. " " .. parenthesis (Year)
			end
		end
		
		if is_set (Trans) then
			if is_set (TransLang) then
				second_part = second_part .. " " .. "(" .. TransLang .. ": " .. Trans .. ")"
				else
					second_part = second_part .. " " .. parenthesis (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 .. " " .. parenthesis (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 (Series) then
		if is_set (Volume) then
			Series = Series .. ", vol." .. Volume
		end
		second_part = second_part .. " " .. Series .. "."
	end
	
	if is_set (City) then
		if is_set (Publisher) then
			third_part = City .. ": " .. Publisher .. "."
			else
				third_part = City .. "."
				end
		end

		if not is_set(City) then
			if is_set(Publisher) then
			third_part = Publisher .. "."
			else
				third_part = ''
			end
		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
		local doispan = mw.html.create ( 'span' )
		doispan
		:tag('small')
		:wikitext("doi: " .. DOI)
		fourth_part = fourth_part .. " " .. tostring(doispan)
		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 (second_part) then
		second_part = " " .. second_part
	end
	
	if is_set (third_part) then
		third_part = " " .. third_part
	end
	
	if is_set (fourth_part) then
		fourth_part = " " .. fourth_part
	end	

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