Module:Video game wikidata: Difference between revisions

Content deleted Content added
Latest rewrite as we continue to learn and grow.
Updates for getting series data and publication dates, other tweaks/refactoring, from Sandbox.
Line 114:
return platformA < platformB
end;
 
local function sortDates(a,b)
if(a.year == b.year) then
if(a.month == b.month) then
return a.day < b.day;
else
return a.month < b.month;
end;
else
return a.year < b.year;
end;
end;
 
Line 127 ⟶ 139:
cite = "{{cite web|url="..referenceUrl;
local timestamppubdate = nil;
local accessdate = nil;
local publisher = nil;
local work = nil;
local title = nil;
 
if(reference['snaks']['P577'] ~= nil and reference['snaks']['P577'][1] ~= nil) then
pubdate = reference['snaks']['P577'][1]['datavalue']['value']['time'];
end;
if(reference['snaks']['P813'] ~= nil and reference['snaks']['P813'][1] ~= nil) then
timestampaccessdate = reference['snaks']['P813'][1]['datavalue']['value']['time'];
end;
if(reference['snaks']['P123'] ~= nil and reference['snaks']['P123'][1] ~= nil) then
Line 153 ⟶ 169:
if(work ~= nil and work ~= "") then
cite = cite .. "|work="..work;
end;
if(timestamppubdate ~= nil and timestamppubdate ~= "") then
local year = string.sub(timestamppubdate,2,5);
local month = string.sub(timestamppubdate,7,8);
local day = string.sub(timestamppubdate,10,11);
local accessdatepubdateText = Date(year, month, day):text(df);
 
cite = cite .. "|date="..pubdateText;
end;
if(accessdate ~= nil and accessdate ~= "") then
local year = string.sub(accessdate,2,5);
local month = string.sub(accessdate,7,8);
local day = string.sub(accessdate,10,11);
local accessdateText = Date(year, month, day):text(df);
 
cite = cite .. "|accessdate="..accessdateaccessdateText;
end;
Line 314 ⟶ 338:
function p.getUpdateLink()
return '<sub>[[d:'..entity['id']..'#P444|&#91;±&#93;]]</sub>';
end;
 
function p.getSitelink()
return mw.wikibase.sitelink(entity['id']);
end;
 
function p.getLabel()
return mw.wikibase.label(entity['id']);
end;
 
function p.getParts()
local ret = {};
-- Loop all of "has Part" for this title
local parts = entity['claims']['P527'];
if(parts) then
for i,part in pairs(parts) do
table.insert(ret,"Q"..part['mainsnak']['datavalue']['value']['numeric-id']);
end;
end;
 
return ret;
end;
 
function p.getEarliestPublicationDate()
local ret = {};
local pubDates = entity['claims']['P577'];
if(pubDates) then
for i,pubDate in pairs(pubDates) do
local timestamp = pubDate['mainsnak']['datavalue']['value']['time'];
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);
table.insert(ret,accessdate);
end;
end;
 
if(#ret < 1) then
return nil;
end;
 
table.sort(ret,sortDates);
return ret[1];
end;
 
Line 364 ⟶ 434:
if(ret ~= "") then
ret = string.sub(ret, 1, -7);
if elseif(not showUpdateLink) then
-- Add edit link at end if showUpdateLink is on.
if(showUpdateLink) then
ret = ret .. p.getUpdateLink();
end;
else
ret = nil;
end;
-- Add edit link at end if showUpdateLink is on.
if(showUpdateLink) then
ret = ret .. p.getUpdateLink();
end;
 
return ret;