跳转到内容

草稿:Module:Wikisource further reading

维基百科,自由的百科全书

local p = {};

out="" function p.getCommonsInfo(commonsType)

   commonsType = commonsType or "withParentheses"

local id=mw.wikibase.getEntityIdForCurrentPage() ---If there is a interwiki link for Wikimedia Commons, show it. local commonsPage=mw.wikibase.getEntity( id )["sitelinks"]["commonswiki"] P373=mw.wikibase.getBestStatements( id , "P373")[1] if( commonsPage ~= nil ) then if( commonsType == "withoutParentheses") then commonsTitle=commonsPage["title"] out=out.."维基共享资源阅览影像" ---Wikimedia Commons category. local P373=mw.wikibase.getBestStatements( id , "P373")[1] if( P373 and P373.mainsnak.datavalue and ("Category:"..P373.mainsnak.datavalue.value~=commonsTitle)) then out=out.."、分类" end

else commonsTitle=commonsPage["title"] out=out.."(维基共享资源阅览影像" ---Wikimedia Commons category. if( P373 and P373.mainsnak.datavalue and ("Category:"..P373.mainsnak.datavalue.value~=commonsTitle)) then out=out.."、分类" end out=out..")" end elseif ( P373 and P373.mainsnak.datavalue) then if( commonsType == "withoutParentheses") then out=out.."维基共享资源阅览影像" else out=out.."(维基共享资源阅览影像)" end end return out; end


function p.getWikisourceInfo() local id=mw.wikibase.getEntityIdForCurrentPage() local commonsNotShown=true local pageName=mw.wikibase.getLabel(id,"zh-hant")

local out='[在维基数据]' local wikisourcePage=mw.wikibase.getEntity( id )["sitelinks"]["zhwikisource"]

--If there is a interwiki link for Wikisource, show it. if( wikisourcePage ~= nil ) then title=wikisourcePage["title"] if( string.match(title, "Author:") ) then out=out.."\n: 维基文库阅读此作者作品" else out=out.."\n: 维基文库阅读本作品原文" end out=out..p.getCommonsInfo() commonsNotShown=false end local claims=mw.wikibase.getEntity( id )["claims"]

--If there are versions (P747) with a Wikisource link, show them. if( claims ~= nil and claims["P747"] ~= nil ) then P747=claims["P747"] for i, data in ipairs(P747) do if( data["qualifiers"]~= nil and data["qualifiers"]["P805"]~= nil) then local wikisourceBook=data["qualifiers"]["P805"] local wikisourceId=wikisourceBook[1]["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( data["qualifiers"]["P958"]~= nil and data["qualifiers"]["P958"][1]~= nil ) then wikisourceSection="#"..data["qualifiers"]["P958"][1]["datavalue"]["value"] else wikisourceSection="#"..pageName end out=out.."\n: 维基文库中的相关文本:"..wikisourcePageTitle.."》" if commonsNotShown then out=out..p.getCommonsInfo() commonsNotShown=false 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.."》" if commonsNotShown then out=out..p.getCommonsInfo() commonsNotShown=false end local zhWikiLink=mw.wikibase.getEntity( wikisourceId )["sitelinks"]["zhwiki"] if( zhWikiLink~=nil ) then out=out.."([["..zhWikiLink["title"].."|介绍]])" end end end end end


--If there are described by source (P1343) with a Wikisource link, show them. 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"] local bookId=data["mainsnak"]["datavalue"]["value"]["id"] local bookName=mw.wikibase.getLabel( bookId ) local bookAuthor=mw.wikibase.getBestStatements(bookId, "P50")

local wikisourceId=wikisourceBook[1]["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( data["qualifiers"]["P958"]~= nil and data["qualifiers"]["P958"][1]~= nil ) then wikisourceSection="#"..data["qualifiers"]["P958"][1]["datavalue"]["value"] else wikisourceSection="#"..pageName end out=out.."\n: 维基文库中的相关文本:"..wikisourcePageName.."》" out=out..",出自" 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"]["zhwiki"] if( bookAuthorLink~=nil ) then out=out.."[["..bookAuthorLink["title"].."|"..bookAuthorName.."]]" else out=out..bookAuthorName end end end local zhWikiLink=mw.wikibase.getEntity( bookId )["sitelinks"]["zhwiki"] if( zhWikiLink~=nil ) then out=out.."《[["..zhWikiLink["title"].."|"..bookName.."]]》" else out=out.."《"..bookName.."》" 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: 维基文库中的相关文本:"..wikisourcePageName.."》" end end end end

--If there is no Wikisource link yet and P31 is human (Q5), show commons link.

if commonsNotShown then P31=mw.wikibase.getBestStatements(id , "P31")[1] if(P31 ~= nil )then if(P31.mainsnak.datavalue.value.id=="Q5")then out=out.."\n: "..p.getCommonsInfo("withoutParentheses") end end end return out

end

return p;