Module:Works about author

維基文庫,自由的圖書館
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

用于在{{author}}根据wikidata数据显示本站有关这个作者的文献。

local p = {};
local id=mw.wikibase.getEntityIdForCurrentPage()
local pageName=mw.wikibase.getLabel(id,"zh-hant")
local claims=mw.wikibase.getEntity(id)
if claims ~= nil then
	claims = claims["claims"]
end
local out=""
function p.getInfo()
	if( claims ~= nil and claims["P1343"] ~= nil )
	then
		P1343=claims["P1343"]
		for i, data in ipairs(P1343) do
			if( data["qualifiers"]~= nil and data["qualifiers"]["P805"]~= nil)
			then
				local wikisourceBook=data["qualifiers"]["P805"]
				for i2, data2 in ipairs(wikisourceBook) do
					local wikisourceId=data2["datavalue"]["value"]["id"]
					local ws=mw.wikibase.getEntity( wikisourceId )["sitelinks"]
					if( ws~=nil and ws["zhwikisource"]~=nil ) then
						local zhws=ws["zhwikisource"]
						local wikisourcePageTitle=zhws["title"]
						local wikisourcePageName=mw.wikibase.getLabel( wikisourceId ) or wikisourcePageTitle
						if( type(data["qualifiers"]["P958"]) == "table") 
						then
							wikisourceSection="#"..data["qualifiers"]["P958"][1]["datavalue"]["value"]
						else 
							wikisourceSection="#"..pageName
						end
						out=out.."\n: 《[["..wikisourcePageTitle..wikisourceSection.."|"..wikisourcePageName.."]]》"
						out=out..",出自"
						local bookId=data["mainsnak"]["datavalue"]["value"]["id"]
						local bookName=mw.wikibase.getLabel( bookId )
						local bookAuthor=mw.wikibase.getBestStatements(bookId, "P50")
						if( bookAuthor[1]~=nil )
						then
							if bookAuthor[1]['mainsnak']['snaktype'] == 'value' then
								local bookAuthorId=bookAuthor[1]['mainsnak']['datavalue']['value']["id"]
								local bookAuthorName=mw.wikibase.getLabel( bookAuthorId )
								local bookAuthorLink=mw.wikibase.getEntity( bookAuthorId )["sitelinks"]["zhwikisource"]
								if( bookAuthorLink~=nil ) 
								then
									out=out.."[["..bookAuthorLink["title"].."|"..bookAuthorName.."]]"
								else 
									out=out..bookAuthorName
								end
							end
						end
						local zhWikiLink=mw.wikibase.getEntity( bookId )["sitelinks"]["zhwikisource"]
						if( zhWikiLink~=nil ) 
						then
							out=out.."《[["..zhWikiLink["title"].."|"..bookName.."]]》"
						else 
							out=out.."《"..bookName.."》"
						end
					end
				end
			else

				local wikisourceId =data["mainsnak"]["datavalue"]["value"]["id"]
				local ws=mw.wikibase.getEntity( wikisourceId )["sitelinks"]
				if( ws~=nil and ws["zhwikisource"]~=nil ) then
					local wikisourcePageTitle=ws["zhwikisource"]["title"]
					local wikisourcePageName=mw.wikibase.getLabel( wikisourceId ) or wikisourcePageTitle
					out=out.."\n: 《[["..wikisourcePageTitle.."|"..wikisourcePageName.."]]》"
			end
			end 
		end 
	end
	if( out~="") then
		out=":<div style='font-size: 80%; color:#525252;'>"..out.."</div>"
	end
	return out
end
return p;