Content deleted Content added
Updates for getting series data and publication dates, other tweaks/refactoring, from Sandbox. |
Implementing MOS RFC. |
||
(21 intermediate revisions by 4 users not shown) | |||
Line 13:
local system = nil;
local systemId = nil;
local systemFormat = "colon";
local updateLinkStyle = nil;
local entities = {};
-- Translation table for converting numeric-IDs to shorthand aliases.
Line 42 ⟶ 45:
[184839] = 'N64',
[182172] = 'GC', -- Sometimes has been NGC
[19610114] = 'NS', -- Nintendo Switch
[98973368] = 'XSX/S', -- Xbox Series X and Series S (Output label differs from the input parameter, XSXS, per RFC)
[63184502] = 'PS5'
}
Line 73 ⟶ 79:
['GC'] = 182172,
['NGC'] = 182172,
['NS'] = 19610114,
['XSXS'] = 98973368, -- This is the template parameter, which cannot contain a / or | character.
['PS5'] = 63184502
}
Line 78 ⟶ 87:
local aggregatorAliases = {
[150248] = 'MC',
[40160] = 'GR',
[21039459] = 'OC'
}
Line 84 ⟶ 94:
local aggregatorIDs = {
['MC'] = 150248,
['GR'] = 40160,
['OC'] = 21039459
}
Line 90 ⟶ 101:
local reviewerAliases = {
[591573] = 'FAM',
[207708] = 'IGN'
}
-- List of accepted reviewer arguments and their related QID.
local reviewerIDs = {
['FAM'] = 591573,
['IGN'] = 207708
}
local function sortByPlatform(a,b)
local platformA =
local platformB =
if(a['qualifiers']['P400'] ~= nil and
platformA = p.getSystemAlias(a['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);
if(platformA == nil) then
Line 114 ⟶ 127:
return platformA < platformB
end;
Line 144 ⟶ 145:
local work = nil;
local title = nil;
local archiveUrl = nil;
local archiveDate = nil;
local authors = {};
if(reference['snaks']['P577'] ~= nil and reference['snaks']['P577'][1] ~= nil) then
Line 160 ⟶ 164:
title = reference['snaks']['P1476'][1]['datavalue']['value']['text'];
end;
if(reference['snaks']['P1065'] ~= nil and reference['snaks']['P1065'][1] ~= nil) then
archiveUrl = reference['snaks']['P1065'][1]['datavalue']['value'];
end;
if(reference['snaks']['P2960'] ~= nil and reference['snaks']['P2960'][1] ~= nil) then
archiveDate = reference['snaks']['P2960'][1]['datavalue']['value']['time'];
end;
if(reference['snaks']['P50'] ~= nil and #reference['snaks']['P50'] > 0) then
for i,authorDat in pairs(reference['snaks']['P50']) do
local authorQid = 'Q'..authorDat['datavalue']['value']['numeric-id'];
if(entities[authorQid] == nil) then
entities[authorQid] = mw.wikibase.getEntity(authorQid);
end;
local author = {};
author['fullname'] = mw.wikibase.label(authorQid); -- Default to label
author['first'] = nil;
author['last'] = nil;
if(entities[authorQid]['claims']['P735'] ~= nil and entities[authorQid]['claims']['P735'][1] ~= nil) then
author['first'] = mw.wikibase.label('Q'..entities[authorQid]['claims']['P735'][1]['mainsnak']['datavalue']['value']['numeric-id']);
end;
if(entities[authorQid]['claims']['P734'] ~= nil and entities[authorQid]['claims']['P734'][1] ~= nil) then
author['last'] = mw.wikibase.label('Q'..entities[authorQid]['claims']['P734'][1]['mainsnak']['datavalue']['value']['numeric-id']);
end;
table.insert(authors, author);
end;
end;
if(title ~= nil and title ~= "") then
cite = cite .. "|title="..title;
Line 171 ⟶ 203:
end;
if(pubdate ~= nil and pubdate ~= "") then
local
cite = cite .. "|date="..pubdateText;
end;
if(accessdate ~= nil and accessdate ~= "") then
local
cite = cite .. "|accessdate="..accessdateText;
end;
if(archiveUrl ~= nil and archiveUrl ~= "" and archiveDate ~= nil and archiveDate ~= "") then
local archivedateText = Date(archiveDate):text(df);
cite = cite .. "|archiveurl="..archiveUrl;
cite = cite .. "|archivedate="..archivedateText;
end;
if(#authors > 0) then
for i,author in pairs(authors) do
if(author['first'] ~= nil and author['last'] ~= nil and author['first'] ~= "" and author['last'] ~= "") then
if(#authors == 1) then
cite = cite .."|last="..author['last'].."|first="..author['first'];
else
cite = cite .."|last"..i.."="..author['last'].."|first"..i.."="..author['first'];
end;
else
if(#authors == 1) then
cite = cite .."|author="..author['fullname'];
else
cite = cite .."|author"..i.."="..author['fullname'];
end;
end;
end;
end;
cite = cite..'}}';
Line 194 ⟶ 243:
local function printReviewRow(frame, reviewscore)
local
if(reviewscore['mainsnak']['datavalue'] ~= nil and reviewscore['mainsnak']['datavalue']['value'] ~= nil) then
score = reviewscore['mainsnak']['datavalue']['value'];
else
return "";
end;
local ret = ""
local system = nil;
local
if(reviewscore['qualifiers']['P400'] ~= nil and reviewscore['qualifiers']['P400'][1] ~= nil) then
Line 204 ⟶ 259:
end
if(system ~= nil and system ~= "" and showSystem) then
if(systemFormat == "para") then
ret = ret.."("..system..") ";
else
ret = ret..system..": ";
end;
end;
ret = ret..score;
if(reviewscore['references'] ~= nil and reviewscore['references'][1] ~= nil and genRefs) then
local cite = buildCite(reviewscore['references'][1]
if(cite ~= nil) then
Line 282 ⟶ 338:
if(iDf ~= nil and iDf ~= "") then
df = string.lower(iDf);
end;
end;
function p.setSystemFormat(iSf)
if(iSf ~= nil and iSf ~= "") then
systemFormat = string.lower(iSf);
end;
end;
function p.setUpdateLinkStyle(iStyle)
if(iStyle ~= nil and iStyle ~= "") then
updateLinkStyle = string.lower(iStyle);
end;
end;
Line 288 ⟶ 356:
-- Check for a game parameter. If missing, default to current article.
if(iGame ~= nil and iGame ~= "") then
entities[iGame] = mw.wikibase.getEntity(iGame);
end;
entity = entities[iGame]
else
-- Need to research if we can determine the entity's ID before retrieving it.
if(mw.wikibase ~= nil) then
entity = mw.wikibase.getEntity();
if(entity ~= nil) then
entities[entity['id']] = entity;
end;
end;
end;
Line 337 ⟶ 415:
function p.getUpdateLink()
if(updateLinkStyle == "pen") then
return "[[File:Blue pencil.svg|frameless|text-top|10px|alt=Edit this on Wikidata|link=https://www.wikidata.org/wiki/"..entity['id'].."?uselang="..mw.language.getContentLanguage().code.."#P444|Edit this on Wikidata]]";
elseif(updateLinkStyle == "noSub") then
return '[[d:'..entity['id']..'#P444|[±]]]';
elseif(updateLinkStyle == "text and pen") then
return '<span style="position: relative;"><span style="position: absolute; right: 0;">[[File:Blue pencil.svg|10px|baseline|link=|alt=]]</span>[[d:'..entity['id']..'#P444|<span style="position: relative; padding-right: 14px;">Edit on Wikidata</span>]]</span>'
end;
return '<sub>[[d:'..entity['id']..'#P444|[±]]]</sub>';
end;
Line 368 ⟶ 454:
if(pubDates) then
for i,pubDate in pairs(pubDates) do
if(pubDate['mainsnak']['datavalue']) then
local timestamp = pubDate['mainsnak']['datavalue']['value']['time']; local
table.insert(ret,accessdate);
end;
end;
end;
Line 381 ⟶ 466:
end;
table.sort(ret
return ret[1];
Line 395 ⟶ 480:
local reviewsToPrint = {}
for i,review in pairs(reviewscores) do
local scoreBy = nil
if(review['qualifiers']['P447'] ~= nil and review['qualifiers']['P447'][1] ~= nil) then scoreBy = review['qualifiers']['P447'][1]['datavalue']['value']['numeric-id'];
end;
if(scoreBy == reviewer) then
-- If template specified a system, we need to check for the specific system and only output that one.
if(system == nil or system == "") then
-- No system specified, so output each one found.
table.insert(reviewsToPrint,review);
else
-- Get platform if it exists.
if(review['qualifiers']['P400'] ~= nil and review['qualifiers']['P400'][1] ~= nil) then
-- Try to match based on QID.
local reviewSysId = review['qualifiers']['P400'][1]['datavalue']['value']['numeric-id'];
if(systemId == reviewSysId) then
table.insert(reviewsToPrint,review);
else
-- If that failed, try to match based on label.
local systemName = mw.wikibase.label('Q'..reviewSysId);
if(systemName ~= nil and string.upper(systemName) == system) then
table.insert(reviewsToPrint,review);
end;
end;
end;
Line 421 ⟶ 508:
end;
end;
end;
-- Sort the array by platform label.
table.sort(reviewsToPrint, sortByPlatform);
-- If a system was not specified, showSystem has defaulted to true. If this title only has one platform and one review, we will turn it off.
-- Note: If the title has zero or more platforms defined, we leave showSystem on. We are unable to determine if this is a single-platform game.
--if((system == nil or system == "") and #reviewsToPrint == 1 and entity['claims']['P400'] ~= nil and #entity['claims']['P400'] == 1) then
-- Simplifying this based on discussion at [Template:Video game reviews]. If there's only one review, don't display system unless explicitly requested.
if((system == nil or system == "") and #reviewsToPrint == 1) then
showSystem = false;
end;
-- Print the reviews
|