require('strict')
--
-- Module layout for reviewer section in the work
--
-- 1 get args
-- 2 extract all reviewer args
-- 3 sort args for reviewer then system
-- 4 output args value where reviewer + system correlate
--
--
-- This module will implement {{Video game multiple console reviews}}
--
local p = {}
local data = require('Module:Video game reviews/data/sandbox')
local yesno = require('Module:Yesno')
local vgwd = require('Module:Video game wikidata')
local getArgs
local function getActiveSystems(args)
local reviewer = {{'[[1UP.com]]', '1UP'}, {'[[ActionTrip]]', 'Atrip'}, {'[[Adventure Gamers]]', 'AdvGamers'}, {'[[Allgame]]', 'Allgame'}, {'[[Amstrad Action]]', 'AAction'}, {'[[Amtix!]]', 'Amtix'}, {'[[Computer and Video Games]]', 'CVG'}, {'[[Crash (magazine)|Crash]]', 'CRASH'}, {'[[Destructoid]]', 'Destruct'}, {'[[Dragon (magazine)]]', 'Dragon'}, {'[[Edge (magazine)|Edge]]', 'Edge'}, {'[[Electronic Gaming Monthly]]', 'EGM'}, {'[[Eurogamer]]', 'EuroG'}, {'[[Famitsu]]', 'Fam'}, {'[[G4 (TV channel)|G4]]', 'G4'}, {'GameCritics', 'GCritics'}, {'[[GameFan]]', 'GameFan'}, {'[[Game Informer]]', 'GI'}, {'[[GamePro]]', 'GamePro'}, {'[[Game Revolution]]', 'GameRev'}, {'[[GamesMaster]]', 'GMaster'}, {'[[GamesRadar]]', 'GRadar'}, {'[[GameSpot]]', 'GSpot'}, {'[[GameSpy]]', 'GSpy'}, {'[[GamesTM]]', 'GTM'}, {'[[GameTrailers]]', 'GT'}, {'GameWire', 'GW'}, {'[[GameZone]]', 'GameZone'}, {'[[Giant Bomb]]', 'GB'}, {'[[Hyper (magazine)|Hyper Magazine]]', 'Hyper'}, {'[[IGN]]', 'IGN'}, {'[[Joystiq]]', 'Joystiq'}, {'[[Maximum PC]]', 'MaxPC'}, {'[[NGC Magazine]]', 'N64'}, {'[[NGC Magazine]]', 'NGC'}, {'[[NGamer]]', 'NG'}, {'NintendoLife', 'NLife'}, {'[[Nintendo Power]]', 'NP'}, {'Nintendo World Report', 'NWR'}, {'[[Official Nintendo Magazine]]', 'ONM'}, {'[[Official U.S. PlayStation Magazine|Official PlayStation Magazine (US)]]', 'OPM'}, {'[[PlayStation Official Magazine (UK)|Official PlayStation Magazine (UK)]]', 'OPMUK'}, {'[[Official PlayStation Magazine (Australia)]]', 'OPMAU'}, {'[[Official Xbox Magazine]]', 'OXM'}, {'[[Official Xbox Magazine|Official Xbox Magazine UK]]', 'OXMUK'}, {'[[PALGN]]', 'PALGN'}, {'[[PC Format]]', 'PCF'}, {'[[PC Gamer|PC Gamer UK]]', 'PCGUK'}, {'[[PC Gamer|PC Gamer US]]', 'PCGUS'}, {'[[PC PowerPlay]]', 'PCPP'}, {'[[PC Zone]]', 'PCZone'}, {'[[Play (UK magazine)|Play Magazine]]', 'Play'}, {'[[Polygon (website)|Polygon]]', 'Poly'}, {'[[PlayStation: The Official Magazine|PlayStation Magazine]]', 'PSM'}, {'[[PSM3|PlayStation 3 Magazine]]', 'PSM3'}, {'[[RPGamer]]', 'RPG'}, {'[[Sinclair User]]', 'SUser'}, {'[[TeamXbox]]', 'TX'}, {'[[VideoGamer.com]]', 'VG'}, {'[[X-Play]]', 'XPlay'}, {'[[Your Sinclair]]', 'YSinclair'}}
local activeSystems = {}
for k, v in pairs(args) do
if data.systems[k] and yesno(v) then
table.insert(activeSystems, k)
end
end
table.sort(activeSystems, function(a, b)
return data.systems[a].sortkey < data.systems[b].sortkey
end)
return activeSystems
end
local function getArgKeyTables(args)
local aggregator = {{'[[GameRankings]]','GR'}, {'[[Metacritic]]','MC'}}
local reviewers, aggregators, awards = {}, {}, {}
for k in pairs(args) do
-- 2 arrays with the title and code of each predefined "system type" field to be used.
if string.match(k, data.i18n.pattern.reviewer) then
local system = {{'[[Atari 2600]]','A2600'}, {'[[ColecoVision]]','CV'}, {'[[Nintendo DS|DS]]','DS'}, {'[[Game Boy]]','GB'}, {'[[Game Boy Advance|GBA]]','GBA'}, {'[[Game Boy Color|GBC]]','GBC'}, {'[[List of video game consoles|General]]', 'GEN'}, {'[[iOS]]','iOS'}, {'[[N-Gage (device)|N-Gage]]','N-G'}, {'[[Nintendo 64|N64]]','N64'}, {'[[Nintendo Entertainment System|NES]]','NES'}, {'[[GameCube|GC]]','NGC'}, {'[[Nvidia Shield|Shield]]','NSHI'}, {'[[Personal Computer|PC]]','PC'}, {'[[PlayStation|PS]]','PS'}, {'[[PlayStation 2|PS2]]','PS2'}, {'[[PlayStation 3|PS3]]','PS3'}, {'[[PlayStation 4|PS4]]','PS4'}, {'[[PlayStation Portable|PSP]]','PSP'}, {'[[Dreamcast]]','SDC'}, {'[[Sega Game Gear|SGG]]','SGG'}, {'[[Super Nintendo Entertainment System|SNES]]','SNES'}, {'[[Sega Genesis|Mega Drive]]','SMD'}, {'[[Master System]]','SMS'}, {'[[Sega Saturn|Saturn]]','SSAT'}, {'[[TurboGrafx-16]]','TG16'}, {'[[PlayStation Vita]]','VITA'}, {'[[Xbox]]','XBOX'}, {'[[Xbox 360]]','X360'}, {'[[Xbox One]]','XONE'}, {'[[Wii]]','WII'}}
table.insert(reviewers, k)
elseif string.match(k, data.i18n.pattern.aggregator) then
-- Require necessary modules.
table.insert(aggregators, k)
local HtmlBuilder = require('Module:HtmlBuilder')
elseif string.match(k, data.i18n.pattern.award) then
local categoryHandler = require('Module:Category handler').main
table.insert(awards, k)
end
-- Set aliases for often-used functions to reduce table lookups.
end
local args
local function comparator(a, b)
local frame
return tonumber(a:match('%d+')) < tonumber(b:match('%d+'))
local keys
end
local halfkeysrev
table.sort(reviewers, comparator)
local halfkeysagg
table.sort(aggregators, comparator)
local platforms
table.sort(awards, comparator)
local custome_agg
return reviewers, aggregators, awards
local custome_rev
local awardnums = {}
--
-- Splits a string on a delimiter n number of times.
--
function Split(str, delim, maxNb)
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gfind(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
local function getProvidedReviewersAndAggregators(args, usePlatforms)
--
local providedReviewers, providedAggregators = {}, {}
-- Sorts keys by string.
if usePlatforms then
--
local seen = {}
function pairsByKeys (t, f)
for k in pairs(args) do
local a = {}
local splitPos = string.find(k, '_')
for n in pairs(t) do
if type(n) == 'string'splitPos then
local halfarg = string.sub(k, 1, splitPos - 1)
table.insert(a, n)
if not seen[halfarg] then
end
seen[halfarg] = true
end
if data.reviewers[halfarg] then
table.sort(a, f)
table.insert(providedReviewers, halfarg)
local i = 0 -- iterator variable
elseif data.aggregators[halfarg] then
local iter = function () -- iterator function
table.insert(providedAggregators, halfarg)
i = i + 1
end
if a[i] == nil then
end
return nil
end
else
end
return a[i]
else
end
for k in pairs(args) do
end
if not string.find(k, '_') then
return iter
if data.reviewers[k] then
table.insert(providedReviewers, k)
elseif data.aggregators[k] then
table.insert(providedAggregators, k)
end
end
end
end
table.sort(providedReviewers, function(a, b)
return data.reviewers[a].sortkey < data.reviewers[b].sortkey
end)
table.sort(providedAggregators, function(a, b)
return data.aggregators[a].sortkey < data.aggregators[b].sortkey
end)
return providedReviewers, providedAggregators
end
local function renderHeadingRowWithSystems(builder, activeSystems, headingText)
--
builder:tag('tr')
-- Return all the keys of an array
:addClass(data.i18n.class.headerrow)
--
:tag('th')
function array_keys(input)
:attr('scope', 'col')
local key
:attr('rowspan', '2')
local keys = {}
:wikitext(headingText)
:done()
for key in pairs(input) do
:tag('th')
table.insert(keys, key)
:attr('scope', 'colgroup')
end
:attr('colspan', #activeSystems)
:wikitext(data.i18n.display.score)
return keys
:done()
builder = builder:tag('tr')
for _, v in ipairs(activeSystems) do
builder:tag('th')
:wikitext(data.systems[v].name)
:attr('scope', 'col')
:done()
end
end
local function renderHeadingRow(builder, nameHeading)
--
builder:tag('tr')
-- Returns the count of how many platforms are active.
:addClass(data.i18n.class.headerrow)
--
:tag('th')
function platforms()
:attr('scope', 'col')
local count = 0
:wikitext(nameHeading)
for i = 1, #system do
:done()
if args[tostring(system[i][2])] ~= nil then
:tag('th')
if string.lower(tostring(args[tostring(system[i][2])])) == 'true' then
:attr('scope', 'col')
count=count+1
:wikitext(data.i18n.display.score)
end
:done()
end
end
return count
end
local function renderRatingsBySystem(builder, code, name, activeSystems, args, na)
--
builder = builder:tag('tr')
-- Returns the count of how many custom aggregators are active.
builder:tag('td')
--
:wikitext(name)
function custome_agg()
local cagg = 0
for i_, =v 1,in 10ipairs(activeSystems) do
local combinedCode = code .. '_' .. v
if args['agg' .. tostring(i)] ~= nil then
local cell = builder:tag('td')
cagg = cagg + 1
if args[combinedCode] then
end
cell
end
:wikitext(args[combinedCode])
return cagg
:done()
elseif na then
cell
:addClass(data.i18n.class.na)
:wikitext(data.i18n.display.na)
:done()
end
end
end
local function renderRating(builder, name, rating)
--
builder:tag('tr')
-- Returns the count of how many custom reviewers are active.
:tag('td')
--
:addClass(data.i18n.class.centeredpub)
function custome_rev()
:wikitext(name)
local crev = 0
:done()
for i = 1, 10 do
:tag('td')
if args['rev' .. tostring(i)] ~= nil then
:wikitext(rating)
crev = crev + 1
:done()
end
end
return crev
end
--
-- Title row
--
function renderTitleRow(tbl)
local titleCell = tbl.tag('tr').tag('th').css('font-size', '120%')
local function renderAggregators(builder, providedAggregators, activeSystems, customAggregatorKeys, args)
if args.state == 'plain' then
titleCell
local aggregatorCount = #providedAggregators + #customAggregatorKeys
.tag('span')
if aggregatorCount == 0 then return end
.css('padding-left', '5.7em')
.wikitext(' ')
builder = builder:tag('table')
end
:addClass(data.i18n.class.aggregators)
:addClass(data.i18n.class.wikitable)
:addClass(args.state and 'mw-collapsible-content' or nil)
:tag('caption')
:wikitext(data.i18n.display[aggregatorCount == 1 and 'aggregateScore' or 'aggregateScores'])
:done()
if #activeSystems ~= 0 then
if args.title then
local na = yesno(args.na)
titleCell
local showplatforms = #activeSystems ~= 1 or yesno(args.showplatforms)
.wikitext(args.title)
if showplatforms then
.done()
renderHeadingRowWithSystems(builder, activeSystems, data.i18n.display.aggregator)
else
else
titleCell
renderHeadingRow(builder, data.i18n.display.aggregator)
.addClass('Reception')
end
.wikitext('Reception')
.done()
end
for _, v in ipairs(providedAggregators) do
if args.subtitle then
renderRatingsBySystem(builder, v, data.aggregators[v].name, activeSystems, args, na)
tbl
end
.tag('tr')
for _, v in ipairs(customAggregatorKeys) do
.tag('th')
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
.css('font-size', '120%')
end
.wikitext(args.subtitle)
else
.done()
renderHeadingRow(builder, data.i18n.display.aggregator)
end
for _, v in ipairs(providedAggregators) do
renderRating(builder, data.aggregators[v].name, args[v])
end
for _, v in ipairs(customAggregatorKeys) do
renderRating(builder, args[v], args[v .. 'Score'])
end
end
end
local function renderReviews(builder, providedReviewers, activeSystems,
--
customReviewerKeys, args, reviewerCount, priorReviewCount)
-- Insert reviews
--
if reviewerCount == 0 then return end
function reviews()
local arg_system
builder = builder:tag('table')
local tbl2
:addClass(data.i18n.class.reviews)
if (#halfkeysrev > 0 or #halfkeysagg > 0) and platforms >= 1 then
:addClass(data.i18n.class.wikitable)
tbl2 = HtmlBuilder.create('table')
:addClass(args.state and 'mw-collapsible-content' or nil)
.addClass('infobox wikitable')
:tag('caption')
.attr('cellpadding', 0)
:wikitext(data.i18n.display[reviewerCount == 1 and 'reviewScore' or 'reviewScores'])
.attr('cellspacing', 0)
:addClass(priorReviewCount > 0 and data.i18n.class.stacked or nil)
.css('width', '100%')
:done()
.css('border-bottom', 'none')
.css('margin', '0em')
if #activeSystems ~= 0 then
.done()
local na = yesno(args.na)
elseif (#halfkeysrev > 0 or #halfkeysagg > 0 or custome_agg > 0 or custome_rev > 0) and platforms == 0 then
local showplatforms = #activeSystems ~= 1 or yesno(args.showplatforms)
tbl2 = HtmlBuilder.create('table')
if showplatforms then
.addClass('infobox wikitable')
renderHeadingRowWithSystems(builder, activeSystems, data.i18n.display.publication)
.attr('cellpadding', 0)
else
.attr('cellspacing', 0)
renderHeadingRow(builder, data.i18n.display.publication)
.css('width', '100%')
end
.css('font-size', '100%')
.css('border-bottom', 'none')
.css('margin', '0em')
.done()
end
if #halfkeysrev > 0 and (platforms > 1 or string.lower(tostring(args['showplatforms'])) == 'true') then
tbl2.tag('tr').tag('th')
.attr('colspan', #system + 1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
for _, v in ipairs(providedReviewers) do
tbl2
renderRatingsBySystem(builder, v, data.reviewers[v].name, activeSystems, args, na)
.tag('tr')
end
.tag('th')
for _, v in ipairs(customReviewerKeys) do
.attr('rowspan', '2')
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
.css('background', '#e8f4f8')
end
.css('text-align', 'center')
else
.css('vertical-align', 'middle')
renderHeadingRow(builder, data.i18n.display.publication)
.wikitext('Publication')
for _, v in ipairs(providedReviewers) do
.done()
renderRating(builder, data.reviewers[v].name, args[v])
.tag('th')
end
.attr('colspan', #system)
for _, v in ipairs(customReviewerKeys) do
.css('background', '#e8f4f8')
renderRating(builder, args[v], args[v .. 'Score'])
.css('vertical-align', 'middle')
end
.wikitext('Score')
end
.done()
end
local forloop = tbl2.tag('tr')
for j = 1, #system do
if string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
forloop.tag('th').wikitext(tostring(system[j][1]))
end
end
elseif #halfkeysrev > 0 and platforms == 1 and string.lower(tostring(args['showplatforms'])) ~= 'true' then
tbl2.tag('tr').tag('th')
.attr('colspan', '2')
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
tbl2
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext('Publication')
.done()
.tag('th')
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
.done()
end
if platforms >= 1 then
for i = 1, #reviewer do
for k = 1, #halfkeysrev do
if reviewer[i][2] == halfkeysrev[k] then
local forloop = tbl2.tag('tr')
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(reviewer[i][1])
.done()
for j = 1, #system do
local temp = tostring(reviewer[i][2]) .. '_' .. tostring(system[j][2])
if string.lower(tostring(args[tostring(system[j][2])])) == 'true' and args[temp] ~= nil then
forloop.tag('td')
.css('vertical-align', 'middle')
.wikitext(tostring(args[temp]))
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' and string.lower(tostring(args['na'])) == 'true' then
forloop.tag('td')
.css('color', 'lightgray')
.css('vertical-align','middle')
.css('text-align', 'center')
.addClass('table-na')
.wikitext('N/A')
.done()
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
forloop.tag('td').done()
end
end
end
end
end
for i = 1, 10 do
if args['rev' .. tostring(i)] ~= nil then
local forloop = tbl2.tag('tr')
forloop.tag('td').wikitext(tostring(args['rev' .. tostring(i)]))
for j = 1, #system do
local temp = 'rev'.. tostring(i) .. '_' .. tostring(system[j][2])
if string.lower(tostring(args[tostring(system[j][2])])) == 'true' and args[temp] ~= nil then
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(tostring(args[temp]))
.done()
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' and string.lower(tostring(args['na'])) == 'true' then
forloop.tag('td')
.css('color', 'lightgray')
.css('vertical-align','middle')
.css('text-align', 'center')
.addClass('table-na')
.wikitext('N/A')
.done()
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
forloop.tag('td').done()
end
end
end
end
if (#halfkeysagg > 0 and platforms > 1) and #halfkeysrev == 0 then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #system+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
tbl2
.tag('tr')
.tag('th')
.attr('rowspan', '2')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', #system+1)
.css('background', '#e8f4f8')
.css('vertical-align', 'middle')
.wikitext('Score')
.done()
local forloop = tbl2.tag('tr')
for j = 1, #system do
if string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
forloop.tag('th').wikitext(tostring(system[j][1]))
end
end
elseif (#halfkeysagg > 0 and #halfkeysrev > 0) or (#halfkeysagg > 0 and platforms == 1)then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', #system+1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
end
for i = 1, #aggregator do
for k = 1, #halfkeysagg do
if aggregator[i][2] == halfkeysagg[k] then
local forloop = tbl2.tag('tr')
forloop.tag('td')
.css('vertical-align','middle')
.wikitext(aggregator[i][1])
.done()
local function renderAwards(builder, args, awardKeys, priorReviewCount)
for j = 1, #system do
if #awardKeys == 0 then return end
local temp = tostring(aggregator[i][2]) .. '_' .. tostring(system[j][2])
if string.lower(tostring(args[tostring(system[j][2])])) == 'true' and args[temp] ~= nil then
builder = builder:tag('table')
forloop.tag('td').wikitext(tostring(args[temp]))
:addClass(data.i18n.class.awards)
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' and string.lower(tostring(args['na'])) == 'true' then
:addClass(data.i18n.class.wikitable)
forloop.tag('td')
:addClass(args.state and 'mw-collapsible-content' or nil)
.css('color', 'lightgray')
:tag('caption')
.css('vertical-align','middle')
:wikitext(data.i18n.display[#awardKeys == 1 and 'award' or 'awards'])
.css('text-align', 'center')
:addClass(priorReviewCount > 0 and data.i18n.class.stacked or nil)
.addClass('table-na')
:done()
.wikitext('N/A')
:tag('tr')
.done()
:tag('th')
elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
:attr('scope', 'col')
forloop.tag('td').done()
:wikitext(data.i18n.display.publication)
end
:done()
end
:tag('th')
end
:attr('scope', 'col')
end
:wikitext(data.i18n.display.award)
end
:done()
elseif platforms == 0 then
if #halfkeysagg > 0 or custome_agg > 0 then
tbl2
.tag('tr')
.tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Aggregate scores')
.done()
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.wikitext('Aggregator')
.done()
.tag('th')
.css('background', '#e8f4f8')
.wikitext('Score')
.done()
end
for i = 1, #aggregator do
for k = 1, #halfkeysagg do
if aggregator[i][2] == halfkeysagg[k] then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(aggregator[i][1])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args[tostring(aggregator[i][2])]))
.done()
end
end
end
for i = 1, 10 do
if args['agg' .. tostring(i)] ~= nil then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(tostring(args['agg' .. tostring(i)]))
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args['agg'.. tostring(i) .. 'Score']))
.done()
end
end
if #halfkeysrev > 0 or custome_rev > 0 then
tbl2.tag('tr').tag('th')
.attr('colspan', #system + 1)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.wikitext('Review scores')
.done()
tbl2
.tag('tr')
.tag('th')
.css('background', '#e8f4f8')
.css('text-align', 'center')
.wikitext('Publication')
.done()
.tag('th')
.attr('colspan', '25')
.css('background', '#e8f4f8')
.wikitext('Score')
.done()
for i_, =v 1,in #revieweripairs(awardKeys) do
builder:tag('tr')
for k = 1, #halfkeysrev do
:tag('td')
if reviewer[i][2] == halfkeysrev[k] then
:wikitext(args[v .. 'Pub'])
tbl2
:done()
.tag('tr')
. :tag('td')
:wikitext(args[v])
.css('text-align', 'center')
:done()
.css('vertical-align', 'middle')
.wikitext(reviewer[i][1])
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args[tostring(reviewer[i][2])]))
.done()
end
end
end
for i = 1, 10 do
if args['rev' .. tostring(i)] ~= nil then
tbl2
.tag('tr')
.tag('td')
.css('text-align', 'center')
.css('vertical-align', 'middle')
.wikitext(tostring(args['rev' .. tostring(i)]))
.done()
.tag('td')
.css('text-align', 'center')
.css('font-size', '110%')
.wikitext(tostring(args['rev'.. tostring(i) .. 'Score']))
.done()
end
end
end
end
builder:done()
return tbl2
builder:done()
end
local function renderEditOnWikidata(builder, wikidata, state)
--
if not wikidata then return end
-- Inserts a award into the table output.
--
builder:tag('div')
function award(tbl, awardnum)
:addClass(data.i18n.class.wikidata)
local temp = tbl.tag('tr')
:addClass(state and 'mw-collapsible-content' or nil)
.tag('td')
:wikitext(vgwd.getUpdateLink())
.css('font-weight','bold')
:done()
.css('background-color','#f2f2f2')
.wikitext(args['award' .. awardnum .. 'Pub'])
.done()
.tag('td')
.css('background-color','#f2f2f2')
.wikitext(args['award' .. awardnum])
.done()
return temp
end
local function categorizePlatformCount(builder, platformCount)
--
if platformCount ~= 0 then
-- Insert awards header and calls award row creation.
builder:wikitext(data.i18n.category.multiplatform)
--
else
function awards()
builder:wikitext(data.i18n.category.singleplatform)
if args['award1'] then
end
local Cell = HtmlBuilder.create('table')
.addClass('infobox wikitable')
.css('width', '100%')
.css('margin', '0em')
.css('border-top', 'none')
.attr('cellpadding', 3)
.attr('cellspacing', 0)
Cell
.tag('tr')
.tag('th')
.attr('colspan', 2)
.css('background', '#d1dbdf')
.css('font-size', '120%')
.css('border-top', 'none')
.wikitext('Awards')
.done()
Cell
.tag('tr')
.tag('th').wikitext('Publication')
.tag('th').wikitext('Award')
for i, awardnum in ipairs(awardnums) do
local awardRow = award(Cell, awardnum)
awardRow
.done()
end
return Cell
end
end
local function renderTitles(builder, title, subtitle)
--
builder:tag('div')
-- Main tables
:addClass(data.i18n.class.title)
--
:wikitext(title or data.i18n.display.reception)
:done()
if subtitle then
function renderMainTable()
builder:tag('div')
local tbl
:addClass(data.i18n.class.subtitle)
-- The only reason to use the subtitle is collapsible content
if args['award1'] or ((#halfkeysagg > 0 or #halfkeysrev > 0 or custome_agg > 0 or custome_rev > 0) and platforms >= 0) then
-- So always add the related class.
if platforms == 0 then
:addClass('mw-collapsible-content')
-- Width: 20% Seems better since it scales with the article size.
:wikitext(subtitle)
tbl = HtmlBuilder.create('table')
:done()
.attr('cellpadding', 0)
end
.attr('cellspacing', 0)
end
.css('background', 'transparent')
.css('padding', '0em')
.css('margin', '0em 1em 1em 1em')
.css('text-align', 'center')
.css('font-size', '80%')
if args.width then
tbl
.css('width',args.width)
else
tbl
.css('width', '23em')
end
else
tbl = HtmlBuilder.create('table')
.attr('cellpadding', 0)
.attr('cellspacing', 0)
.css('background', 'transparent')
.css('padding', '0em')
.css('margin', '0em 1em 1em 1em')
.css('text-align', 'center')
.css('font-size', '80%')
end
if args.state then
tbl
.addClass(args.state)
else
tbl
.addClass('collapsible')
end
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
tbl
.addClass('collapsible')
.addClass(args.state)
end
tbl.css('float', args.align or 'right').css('clear', args.align or 'right')
local function render(providedReviewers, providedAggregators, awardKeys,
renderTitleRow(tbl)
activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
local is_collapsible = args.title and args.state and
(args.state == data.i18n.state.autocollapse or
args.state == data.i18n.state.collapsed or
args.state == data.i18n.state.expanded
)
local div = mw.html.create('div')
:attr('role', 'complementary')
:addClass(data.i18n.class.container)
:addClass(#activeSystems == 0 and data.i18n.class.containersingle or nil)
:addClass(args.align == data.i18n.align.left and data.i18n.class.containerleft or nil)
:addClass(args.align == data.i18n.align.none and data.i18n.class.containernone or nil)
:addClass(is_collapsible and 'mw-collapsible' or nil)
:addClass(is_collapsible and args.state == data.i18n.state.collapsed and 'mw-collapsed' or nil)
:addClass(is_collapsible and args.state == data.i18n.state.autocollapse and args.state or nil)
renderTitles(div, args.title, args.subtitle)
tbl
.tag('tr')
.tag('td')
.node(reviews())
.done()
local aggregatorCount = #providedAggregators + #customAggregatorKeys
tbl
renderAggregators(
.tag('tr')
div,
.tag('td')
providedAggregators,
.node(awards())
activeSystems,
.done()
customAggregatorKeys,
else
args,
category = categoryHandler{
aggregatorCount
main = '[[Category:Empty templates on articles]]'
)
}
local reviewerCount = #customReviewerKeys + #providedReviewers
category = category or '' -- Check that we don't have a nil value for the category variable.
renderReviews(
tbl = HtmlBuilder.create()
div,
tbl.wikitext(category)
providedReviewers,
end
activeSystems,
return tbl
customReviewerKeys,
args,
reviewerCount,
aggregatorCount
)
renderAwards(
div,
args,
awardKeys,
reviewerCount + aggregatorCount
)
renderEditOnWikidata(div, wikidata, args.state)
categorizePlatformCount(div, #activeSystems)
return div
end
local function checkForWikidata(frame, args, activeSystems, providedAggregators)
--
local wikidata = false
-- Creates the table and calls functions that create the reviews and awards tables/columns/rows.
--
if args.qid == 'none' then
function p._reviewbox(reviewBoxArgs)
return wikidata
local t = {}
end
local flags = {}
local nitem = {}
local halfargs = {}
local j = 1
-- calls for the args.
args = reviewBoxArgs
platforms = platforms()
custome_rev = custome_rev()
custome_agg = custome_agg()
vgwd.setDateFormat(args.df)
-- sorts args by string.
vgwd.setGame(args.qid)
for k in pairsByKeys(args) do
vgwd.setSystem(nil)
table.insert(t, k)
vgwd.setGenerateReferences(true)
end
vgwd.setShowUpdateLink(false)
keys = t
vgwd.setUpdateLinkStyle("text and pen")
vgwd.setSystemFormat(args.systemFormat)
-- Loop through aggregators if we have any.
-- creates a table of all unique reviewers.
if #providedAggregators ~= 0 then
for i=1,#keys do
for _, aggr in ipairs(providedAggregators) do
if string.find(tostring(keys[i]), '_') ~= nil and platforms >= 1 then
-- Check if vgwd knows this aggregator.
halfargs = Split(tostring(keys[i]),'_')
if vgwd.setReviewer(aggr) == nil then
for k=1, #reviewer do
-- Loop through active systems
if reviewer[k][2] == halfargs[1] then
if #activeSystems ~= 0 then
if not flags[halfargs[1]] then
for _, sys in ipairs(activeSystems) do
flags[halfargs[1]] = true
local combinedCode = aggr .. '_' .. sys
nitem[j] = halfargs[1]
if args[combinedCode] == 'wikidata' then
j = j + 1
vgwd.setSystem(sys)
end
vgwd.setShowSystem(false)
end
local vgwdScore = vgwd.printReviewScores(frame)
end
if vgwdScore then
elseif string.find(tostring(keys[i]), '_') == nil and platforms == 0 then
args[combinedCode] = vgwdScore
for k=1, #reviewer do
end
if reviewer[k][2] == keys[i] then
wikidata = true
nitem[j] = keys[i]
end
j = j + 1
end
end
else
end
vgwd.setShowSystem(true)
end
if args[aggr] == 'wikidata' then
end
local vgwdScore = vgwd.printReviewScores(frame)
halfkeysrev = nitem
if vgwdScore then
args[aggr] = vgwdScore
end
wikidata = true
end
end
end
end
end
return wikidata
local flags = {}
end
local nitem = {}
local halfargs = {}
local j = 1
-- creates a table of all unique aggregators.
for i=1,#keys do
if string.find(tostring(keys[i]), '_') ~= nil and platforms >= 1 then
halfargs = Split(tostring(keys[i]),'_')
for k=1, #aggregator do
if aggregator[k][2] == halfargs[1] then
if not flags[halfargs[1]] then
flags[halfargs[1]] = true
nitem[j] = halfargs[1]
j = j + 1
end
end
end
elseif string.find(tostring(keys[i]), '_') == nil and platforms == 0 then
for k=1, #aggregator do
if aggregator[k][2] == keys[i] then
nitem[j] = keys[i]
j = j + 1
end
end
end
end
halfkeysagg = nitem
-- sorts awards by number from args.
for k, v in pairs(args) do
local awardnum = ('' .. k):match('^award(%d+)$')
if awardnum then table.insert(awardnums, tonumber(awardnum)) end
end
if awardnums then table.sort(awardnums) end
function p._reviewbox(frame, args)
-- render the main body of the Review Box
local tblactiveSystems = renderMainTablegetActiveSystems(args)
local customReviewerKeys, customAggregatorKeys, awardKeys = getArgKeyTables(args)
local providedReviewers, providedAggregators = getProvidedReviewersAndAggregators(args, #activeSystems ~= 0)
-- render the appropriate wrapper around the Review Box, depending on the border param
local wikidata = checkForWikidata(frame, args, activeSystems, providedAggregators)
local res = HtmlBuilder.create()
if #customAggregatorKeys ~= 0 or #customReviewerKeys ~= 0 or
#providedAggregators ~= 0 or #providedReviewers ~= 0 or #awardKeys ~= 0 then
res.node(tbl)
return frame:extensionTag{
name='templatestyles', args = { src = data.i18n.templatestyles }
return tostring(res)
} .. tostring(render(
providedReviewers,
providedAggregators,
awardKeys,
activeSystems,
customAggregatorKeys,
customReviewerKeys,
args,
wikidata
))
elseif mw.title.getCurrentTitle().namespace == 0 then
return data.i18n.category.empty
end
end
--
-- Main: frame function.
--
function p.reviewbox(frame)
if not getArgs then
-- ParserFunctions considers the empty string to be false, so to preserve the previous
getArgs = require('Module:Arguments').getArgs
-- behavior of {{Video game multiple console reviews}}, change any empty arguments to nil, so Lua will consider
end
-- them false too.
return p._reviewbox(frame, getArgs(frame,
local args = {}
{ wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n }
local parent_args = frame:getParent().args;
))
for k, v in pairs(parent_args) do
if v ~= '' then
args[k] = v
end
end
return p._reviewbox(args)
end
|