This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
{{#invoke:Video game wikidata|getSystemAlias|<numeric-id>}}
{{#invoke:Video game wikidata|getSystemID|<alias>}}
{{#invoke:Video game wikidata|getAggregatorAlias|<numeric-id>}}
{{#invoke:Video game wikidata|getAggregatorID|<alias>}}
{{#invoke:Video game wikidata|getReviewerAlias|<numeric-id>}}
{{#invoke:Video game wikidata|getReviewerID|<alias>}}
localDate=require('Module:Date')._Datelocalyesno=require('Module:Yesno')localp={}-- Local variables.localreviewer=nil;localdf="mdy";localentity=nil;localgenRefs=true;localshowSystem=true;localshowUpdateLink=true;localsystem=nil;localsystemId=nil;localsystemFormat="colon";localupdateLinkStyle=nil;localentities={};-- Translation table for converting numeric-IDs to shorthand aliases.localsystemAliases={[10677]='PS1',[1323662]='PS1',-- Placeholder, this is actually the series but could be mistakenly used for PS1.[10680]='PS2',[10683]='PS3',[5014725]='PS4',[16338]='PC',[8079]='Wii',[56942]='WiiU',[132020]='XBOX',[48263]='X360',[13361286]='XONE',[203597]='3DS',[188808]='PSV',[170323]='DS',-- Sometimes has been NDS[170325]='PSP',[48493]='IOS',-- iOS, iPhone, iPad[94]='AND',-- Android[186437]='GB',[188642]='GBA',[203992]='GBC',[184198]='DC',[200912]='SAT',[172742]='NES',[183259]='SNES',[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'}-- Translation table for converting system aliases to QIDslocalsystemIDs={['PS1']=10677,['PS2']=10680,['PS3']=10683,['PS4']=5014725,['PC']=16338,['WII']=8079,['WIIU']=56942,['XBOX']=132020,['X360']=48263,['XONE']=13361286,['3DS']=203597,['PSV']=188808,['DS']=170323,['NDS']=170323,['PSP']=170325,['IOS']=48493,['AND']=94,['GB']=186437,['GBA']=188642,['GBC']=203992,['DC']=184198,['SAT']=200912,['NES']=172742,['SNES']=183259,['N64']=184839,['GC']=182172,['NGC']=182172,['NS']=19610114,['XSXS']=98973368,-- This is the template parameter, which cannot contain a / or | character.['PS5']=63184502}-- List of accepted aggregator arguments and their related QID.localaggregatorAliases={[150248]='MC',[40160]='GR',[21039459]='OC'}-- List of accepted aggregator arguments and their related QID.localaggregatorIDs={['MC']=150248,['GR']=40160,['OC']=21039459}-- List of accepted reviewer arguments and their related QID.localreviewerAliases={[591573]='FAM',[207708]='IGN'}-- List of accepted reviewer arguments and their related QID.localreviewerIDs={['FAM']=591573,['IGN']=207708}localfunctionsortByPlatform(a,b)localplatformA="";localplatformB="";if(a['qualifiers']['P400']~=nilanda['qualifiers']['P400'][1]~=nil)thenplatformA=p.getSystemAlias(a['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);if(platformA==nil)thenplatformA=mw.wikibase.label('Q'..a['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);end;end;if(b['qualifiers']['P400']~=nilandb['qualifiers']['P400'][1]~=nil)thenplatformB=p.getSystemAlias(b['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);if(platformB==nil)thenplatformB=mw.wikibase.label('Q'..b['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);end;end;returnplatformA<platformBend;localfunctionbuildCite(reference)localreferenceUrl=nil;localcite=nil;if(reference['snaks']['P854']~=nilandreference['snaks']['P854'][1]~=nil)thenreferenceUrl=reference['snaks']['P854'][1]['datavalue']['value'];end;if(referenceUrl~=nilandreferenceUrl~="")thencite="{{cite web|url="..referenceUrl;localpubdate=nil;localaccessdate=nil;localpublisher=nil;localwork=nil;localtitle=nil;localarchiveUrl=nil;localarchiveDate=nil;localauthors={};if(reference['snaks']['P577']~=nilandreference['snaks']['P577'][1]~=nil)thenpubdate=reference['snaks']['P577'][1]['datavalue']['value']['time'];end;if(reference['snaks']['P813']~=nilandreference['snaks']['P813'][1]~=nil)thenaccessdate=reference['snaks']['P813'][1]['datavalue']['value']['time'];end;if(reference['snaks']['P123']~=nilandreference['snaks']['P123'][1]~=nil)thenpublisher=mw.wikibase.label('Q'..reference['snaks']['P123'][1]['datavalue']['value']['numeric-id']);end;if(reference['snaks']['P1433']~=nilandreference['snaks']['P1433'][1]~=nil)thenwork=mw.wikibase.label('Q'..reference['snaks']['P1433'][1]['datavalue']['value']['numeric-id']);end;if(reference['snaks']['P1476']~=nilandreference['snaks']['P1476'][1]~=nil)thentitle=reference['snaks']['P1476'][1]['datavalue']['value']['text'];end;if(reference['snaks']['P1065']~=nilandreference['snaks']['P1065'][1]~=nil)thenarchiveUrl=reference['snaks']['P1065'][1]['datavalue']['value'];end;if(reference['snaks']['P2960']~=nilandreference['snaks']['P2960'][1]~=nil)thenarchiveDate=reference['snaks']['P2960'][1]['datavalue']['value']['time'];end;if(reference['snaks']['P50']~=niland#reference['snaks']['P50']>0)thenfori,authorDatinpairs(reference['snaks']['P50'])dolocalauthorQid='Q'..authorDat['datavalue']['value']['numeric-id'];if(entities[authorQid]==nil)thenentities[authorQid]=mw.wikibase.getEntity(authorQid);end;localauthor={};author['fullname']=mw.wikibase.label(authorQid);-- Default to labelauthor['first']=nil;author['last']=nil;if(entities[authorQid]['claims']['P735']~=nilandentities[authorQid]['claims']['P735'][1]~=nil)thenauthor['first']=mw.wikibase.label('Q'..entities[authorQid]['claims']['P735'][1]['mainsnak']['datavalue']['value']['numeric-id']);end;if(entities[authorQid]['claims']['P734']~=nilandentities[authorQid]['claims']['P734'][1]~=nil)thenauthor['last']=mw.wikibase.label('Q'..entities[authorQid]['claims']['P734'][1]['mainsnak']['datavalue']['value']['numeric-id']);end;table.insert(authors,author);end;end;if(title~=nilandtitle~="")thencite=cite.."|title="..title;end;if(publisher~=nilandpublisher~="")thencite=cite.."|publisher="..publisher;end;if(work~=nilandwork~="")thencite=cite.."|work="..work;end;if(pubdate~=nilandpubdate~="")thenlocalpubdateText=Date(pubdate):text(df);cite=cite.."|date="..pubdateText;end;if(accessdate~=nilandaccessdate~="")thenlocalaccessdateText=Date(accessdate):text(df);cite=cite.."|accessdate="..accessdateText;end;if(archiveUrl~=nilandarchiveUrl~=""andarchiveDate~=nilandarchiveDate~="")thenlocalarchivedateText=Date(archiveDate):text(df);cite=cite.."|archiveurl="..archiveUrl;cite=cite.."|archivedate="..archivedateText;end;if(#authors>0)thenfori,authorinpairs(authors)doif(author['first']~=nilandauthor['last']~=nilandauthor['first']~=""andauthor['last']~="")thenif(#authors==1)thencite=cite.."|last="..author['last'].."|first="..author['first'];elsecite=cite.."|last"..i.."="..author['last'].."|first"..i.."="..author['first'];end;elseif(#authors==1)thencite=cite.."|author="..author['fullname'];elsecite=cite.."|author"..i.."="..author['fullname'];end;end;end;end;cite=cite..'}}';end;returncite;end;localfunctionprintReviewRow(frame,reviewscore)localscore=nil;if(reviewscore['mainsnak']['datavalue']~=nilandreviewscore['mainsnak']['datavalue']['value']~=nil)thenscore=reviewscore['mainsnak']['datavalue']['value'];elsereturn"";end;localret=""localsystem=nil;localreference=nil;if(reviewscore['qualifiers']['P400']~=nilandreviewscore['qualifiers']['P400'][1]~=nil)thensystem=p.getSystemAlias(reviewscore['qualifiers']['P400'][1]['datavalue']['value']['numeric-id']);endif(system~=nilandsystem~=""andshowSystem)thenif(systemFormat=="para")thenret=ret.."("..system..") ";elseret=ret..system..": ";end;end;ret=ret..score;if(reviewscore['references']~=nilandreviewscore['references'][1]~=nilandgenRefs)thenlocalcite=buildCite(reviewscore['references'][1]);if(cite~=nil)thenlocalscoreBy=p.getAggregatorAlias(reviewscore['qualifiers']['P447'][1]['datavalue']['value']['numeric-id']);if(scoreBy==nil)thenscoreBy=p.getReviewerAlias(reviewscore['qualifiers']['P447'][1]['datavalue']['value']['numeric-id']);end;localname=entity:getLabel()..'-'..scoreBy;if(system~=nilandsystem~="")thenname=name..system;end;cite=frame:extensionTag{name="ref",args={name=name},content=cite};ret=ret..cite;end;end;returnret.."<br />";endfunctionp.getSystemAlias(numericId)returnsystemAliases[numericId];endfunctionp.getSystemID(system)returnsystemIDs[system];endfunctionp.getAggregatorAlias(numericId)returnaggregatorAliases[numericId];endfunctionp.getAggregatorID(system)returnaggregatorIDs[system];endfunctionp.getReviewerAlias(numericId)returnreviewerAliases[numericId];endfunctionp.getReviewerID(system)returnreviewerIDs[system];endfunctionp.setReviewer(iReviewer)-- No reviewer, stop. Must have reviewer at least.if(iReviewer==niloriReviewer=="")thenreturn"Missing reviewer";end;-- See if supplied reviewer is in the aggregator table.iReviewer=string.upper(iReviewer)reviewer=p.getAggregatorID(iReviewer);if(reviewer==nilorreviewer=="")then-- No? Maybe in the reviewer table.reviewer=p.getReviewerID(iReviewer);if(reviewer==nilorreviewer=="")thenreturn"Invalid reviewer";end;end;returnnil;end;functionp.setDateFormat(iDf)-- Check for a date format parameter. Default to mdy if missing.if(iDf~=nilandiDf~="")thendf=string.lower(iDf);end;end;functionp.setSystemFormat(iSf)if(iSf~=nilandiSf~="")thensystemFormat=string.lower(iSf);end;end;functionp.setUpdateLinkStyle(iStyle)if(iStyle~=nilandiStyle~="")thenupdateLinkStyle=string.lower(iStyle);end;end;functionp.setGame(iGame)-- Check for a game parameter. If missing, default to current article.if(iGame~=nilandiGame~="")thenif(entities[iGame]==nilandmw.wikibase~=nil)thenentities[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)thenentity=mw.wikibase.getEntity();if(entity~=nil)thenentities[entity['id']]=entity;end;end;end;if(entity==nil)thenreturn"No matching wikidata entity found";end;returnnil;end;functionp.setSystem(iSystem)-- Check for system parameter, and resolve it's QID if possible.if(iSystem~=nilandiSystem~="")thensystem=string.upper(iSystem);systemId=p.getSystemID(system);elseif(notshowSystem)then-- If no system was specified, force showSystem on.showSystem=true;end;end;functionp.setGenerateReferences(iGenRefs)-- Reference suppression.if(iGenRefs~=nilandiGenRefs~="")thengenRefs=yesno(iGenRefs,true);end;end;functionp.setShowSystem(iShowSystem)-- Suppression of system aliases in front of score, i.e. (XBOX) xx/100.if(iShowSystem~=nilandiShowSystem~="")thenshowSystem=yesno(iShowSystem,false);end;if(system==nilorsystem=='')then-- If no system was specified, force showSystem on.showSystem=true;end;end;functionp.setShowUpdateLink(iShowUpdateLink)-- Suppression of update link to Wikidata at the end of the score, i.e. (XBOX) xx/100[+].if(iShowUpdateLink~=nilandiShowUpdateLink~="")thenshowUpdateLink=yesno(iShowUpdateLink,false);end;end;functionp.getUpdateLink()if(updateLinkStyle=="pen")thenreturn"[[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")thenreturn'[[d:'..entity['id']..'#P444|[±]]]';elseif(updateLinkStyle=="text and pen")thenreturn'<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;functionp.getSitelink()returnmw.wikibase.sitelink(entity['id']);end;functionp.getLabel()returnmw.wikibase.label(entity['id']);end;functionp.getParts()localret={};-- Loop all of "has Part" for this titlelocalparts=entity['claims']['P527'];if(parts)thenfori,partinpairs(parts)dotable.insert(ret,"Q"..part['mainsnak']['datavalue']['value']['numeric-id']);end;end;returnret;end;functionp.getEarliestPublicationDate()localret={};localpubDates=entity['claims']['P577'];if(pubDates)thenfori,pubDateinpairs(pubDates)doif(pubDate['mainsnak']['datavalue'])thenlocaltimestamp=pubDate['mainsnak']['datavalue']['value']['time'];localaccessdate=Date(timestamp);table.insert(ret,accessdate);end;end;end;if(#ret<1)thenreturnnil;end;table.sort(ret);returnret[1];end;functionp.printReviewScores(frame)localret="";-- Loop all of "review scores" for this titlelocalreviewscores=entity['claims']['P444'];if(reviewscores)then-- Find reviews that qualify for printing and insert into array.localreviewsToPrint={}fori,reviewinpairs(reviewscores)doif(review['qualifiers']~=nil)thenlocalscoreBy=nilif(review['qualifiers']['P447']~=nilandreview['qualifiers']['P447'][1]~=nil)thenscoreBy=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==nilorsystem=="")then-- No system specified, so output each one found.table.insert(reviewsToPrint,review);else-- Get platform if it exists.if(review['qualifiers']['P400']~=nilandreview['qualifiers']['P400'][1]~=nil)then-- Try to match based on QID.localreviewSysId=review['qualifiers']['P400'][1]['datavalue']['value']['numeric-id'];if(systemId==reviewSysId)thentable.insert(reviewsToPrint,review);else-- If that failed, try to match based on label.localsystemName=mw.wikibase.label('Q'..reviewSysId);if(systemName~=nilandstring.upper(systemName)==system)thentable.insert(reviewsToPrint,review);end;end;end;end;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==nilorsystem=="")and#reviewsToPrint==1)thenshowSystem=false;end;-- Print the reviewsfori,reviewinipairs(reviewsToPrint)doret=ret..printReviewRow(frame,review);end;end;if(ret~="")thenret=string.sub(ret,1,-7);elseif(notshowUpdateLink)thenret=nil;end;-- Add edit link at end if showUpdateLink is on.if(showUpdateLink)thenret=ret..p.getUpdateLink();end;returnret;end;returnp