Jump to content

Module:Video game wikidata

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ferret (talk | contribs) at 13:27, 13 April 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local Date = require('Module:Date')._Date

local p = {}

-- Translation table for converting numeric-IDs to shorthand aliases.
local systems = {
	[13361286] = 'XONE',
	[5014725] = 'PS4',
	[16338] = 'PC'
}

function p.getSystemAlias(numericId)
	return systems[numericId];
end

function p.printReviewRow(frame, reviewscore, df)
	local ret = ""

	local system = systems[reviewscore['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']];
	local score = reviewscore['mainsnak']['datavalue']['value'];

	if(not (system == nil or system == "")) then
		ret = ret.."("..system..") ";
	end;
	
	if(not (score == nil or score == "")) then
		ret = ret..score;
	end;

	local reference = reviewscore['references'][1]['snaks']['P854'][1]['datavalue']['value'];	
	
	if(not (reference == nil or reference == "")) then
		local cite = "{{cite web|url="..reference;

		local timestamp = reviewscore['references'][1]['snaks']['P813'][1]['datavalue']['value']['time'];
		local publisher = mw.wikibase.label('Q'..reviewscore['references'][1]['snaks']['P123'][1]['datavalue']['value']['numeric-id']);
		local title = reviewscore['references'][1]['snaks']['P1476'][1]['datavalue']['value']['text'];

		if(not(title == nil or title == "")) then
			cite = cite .. "|title="..title;
		end;
		
		if(not(publisher == nil or publisher == "")) then
			cite = cite .. "|publisher="..publisher;
		end;
		
		--+2016-04-08T00:00:00Z
		if(not(timestamp == nil or timestamp == "")) then
			local year = string.sub(timestamp,2,5);
			local month = string.sub(timestamp,7,8);
			local day = string.sub(timestamp,10,11);
			local accessdate = Date(year, month, day):text(df);

			cite = cite .. "|accessdate="..accessdate;
		end;
		
		cite = cite..'}}';
		cite = frame:extensionTag{ name = "ref", args = {name=name}, content=cite };
		ret = ret..cite;
	end;

	return ret .. "<br />";
end

return p