模組:VG Reviews/testcases

--
-- 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 reviewer = {{'[[1UP.com]]', '1UP'}, {'ActionTrip', 'Atrip'}, {'Adventure Gamer', 'AdvGamers'}, {'[[Allgame]]', 'Allgame'}, {'[[Amstrad Action]]', 'AAction'}, {'[[Amtix!]]', 'Amtix'}, {'[[Computer and Video Games]]', 'CVG'}, {'[[Crash (杂志)|Crash]]', 'CRASH'}, {'[[Destructoid]]', 'Destruct'}, {'[[Dragon (杂志)]]', 'Dragon'}, {'[[Edge (杂志)|Edge]]', 'Edge'}, {'[[电子游戏月刊]]', 'EGM'}, {'[[Eurogamer]]', 'EuroG'}, {'[[Fami通]]', 'Fam'}, {'[[G4 (电视节目)|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 (杂志)|Hyper Magazine]]', 'Hyper'}, {'[[IGN]]', 'IGN'}, {'[[Joystiq]]', 'Joystiq'}, {'[[Maximum PC]]', 'MaxPC'}, {'[[NGC杂志]]', 'N64'}, {'[[NGC杂志]]', 'NGC'}, {'[[NGamer]]', 'NG'}, {'NintendoLife', 'NLife'}, {'[[任天堂力量]]', 'NP'}, {'任天堂世界报道', 'NWR'}, {'[[官方任天堂杂志]]', 'ONM'}, {'[[官方PlayStation杂志 (美国)|官方PlayStation杂志(美国)]]', 'OPM'}, {'[[官方PlayStation杂志 (英国)|官方PlayStation杂志(英国)]]', 'OPMUK'}, {'[[官方PlayStation杂志 (澳大利亚)|官方PlayStation杂志(澳大利亚)]]', 'OPMAU'}, {'[[官方Xbox杂志]]', 'OXM'}, {'[[官方Xbox杂志|官方Xbox杂志(英国)]]', 'OXMUK'}, {'[[PALGN]]', 'PALGN'}, {'[[PC Format]]', 'PCF'}, {'[[PC Gamer|PC Gamer英国]]', 'PCGUK'}, {'[[PC Gamer|PC Gamer美国]]', 'PCGUS'}, {'[[PC PowerPlay]]', 'PCPP'}, {'[[PC Zone]]', 'PCZone'}, {'[[Play (英国杂志)|Play]]', 'Play'}, {'[[Polygon (网站)|Polygon]]', 'Poly'}, {'[[PlayStation: The Official Magazine|PlayStation杂志]]', 'PSM'}, {'[[PSM3|PlayStation 3杂志]]', 'PSM3'}, {'[[RPGamer]]', 'RPG'}, {'[[Sinclair User]]', 'SUser'}, {'[[TeamXbox]]', 'TX'}, {'[[VideoGamer.com]]', 'VG'}, {'[[X-Play]]', 'XPlay'}, {'[[游戏机实用技术]]', 'UCG'}, {'[[电子游戏软件 (杂志)|电子游戏软件]]', '电软'}, {'[[大众软件]]', '大软'}, {'[[家用电脑与游戏]]', '家游'}, {'[[电脑游戏攻略]]', '电攻'}, {'[[软件与光盘]]', '软光'}}

local aggregator = {{'[[GameRankings]]','GR'}, {'Game Ratio','GRO'}, {'[[IGN|GameStats]]','GMS'}, {'GameTab','GTab'}, {'[[Metacritic]]','MC'}}

-- 2 arrays with the title and code of each predefined "system type" field to be used.
local system = {{'[[雅達利2600]]','A2600'}, {'[[ColecoVision]]','CV'}, {'[[任天堂DS|DS]]','DS'}, {'[[Game Boy]]','GB'}, {'[[Game Boy Advance|GBA]]','GBA'}, {'[[Game Boy Color|GBC]]','GBC'}, {'[[游戏机列表|General]]', 'GEN'}, {'[[iOS]]','iOS'}, {'[[N-Gage]]','N-G'}, {'[[任天堂64|N64]]','N64'}, {'[[FC游戏机|FC]]','NES'}, {'[[FC游戏机|FC]]','FC'}, {'[[任天堂GameCube|NGC]]','NGC'}, {'[[NVIDIA SHIELD|Shield]]','NSHI'}, {'[[个人电脑|PC]]','PC'}, {'[[PlayStation|PS]]','PS'}, {'[[PlayStation 2|PS2]]','PS2'}, {'[[PlayStation 3|PS3]]','PS3'}, {'[[PlayStation 4|PS4]]','PS4'}, {'[[PlayStation Portable|PSP]]','PSP'}, {'[[Dreamcast]]','DC'}, {'[[Game Gear|GG]]','SGG'}, {'[[超級任天堂|SFC]]','SNES'}, {'[[Mega Drive|MD]]','SMD'}, {'[[世嘉Master System|SMS]]','SMS'}, {'[[SEGA Saturn|SS]]','SSAT'}, {'[[PC Engine|PCE]]','TG16'}, {'[[PlayStation Vita|PSV]]','VITA'}, {'[[Xbox]]','XBOX'}, {'[[Xbox 360|X360]]','X360'}, {'[[Xbox One|XOne]]','XONE'}, {'[[Wii]]','WII'}}

-- Require necessary modules.
local HtmlBuilder = require('Module:HtmlBuilder')
local categoryHandler = require('Module:Category handler').main

-- Set aliases for often-used functions to reduce table lookups.
local args
local frame
local keys
local halfkeysrev
local halfkeysagg
local platforms
local custome_agg
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

--
-- Sorts keys by string.
--
function pairsByKeys (t, f)
    local a = {}
    for n in pairs(t) do
        if type(n) == 'string' then
            table.insert(a, n)
        end
    end
    table.sort(a, f)
    local i = 0 -- iterator variable
    local iter = function () -- iterator function
        i = i + 1
        if a[i] == nil then
            return nil
        else
            return a[i]
        end
    end
    return iter
end

--
-- Return all the keys of an array
--
function array_keys(input)
    local key
    local keys = {}

    for key in pairs(input) do
        table.insert(keys, key)
    end

    return keys
end

--
-- Returns the count of how many platforms are active.
--
function platforms()
    local count = 0
    for i = 1, #system do
        if args[tostring(system[i][2])] ~= nil then
            if string.lower(tostring(args[tostring(system[i][2])])) == 'true' then
                count=count+1
            end
        end
    end
    return count
end

--
-- Returns the count of how many custom aggregators are active.
--
function custome_agg()
    local cagg = 0
    for i = 1, 10 do
        if args['agg' .. tostring(i)] ~= nil then
            cagg = cagg + 1
        end
    end
    return cagg
end

--
-- Returns the count of how many custom reviewers are active.
--
function custome_rev()
    local crev = 0
    for i = 1, 10 do
        if args['rev' .. tostring(i)] ~= nil then
            crev = crev + 1
        end
    end
    return crev
end
--
-- Title row
--
function renderTitleRow(tbl)
    local titleCell = tbl.tag('tr').tag('th').css('font-size', '120%')

    if args.state == 'plain' then
        titleCell
            .tag('span')
            .css('padding-left', '5.7em')
            .wikitext('&nbsp;')
    end

    if args.title then
        titleCell
            .wikitext(args.title)
            .done()
    else
        titleCell
            .addClass('Reception')
            .wikitext('游戏评价')
            .done()
    end

    if args.subtitle then
        tbl
            .tag('tr')
                .tag('th')
                    .css('font-size', '120%')
                    .wikitext(args.subtitle)
                    .done()
    end
end

--
-- Insert reviews
--
function reviews()
    local arg_system
    local tbl2
    if (#halfkeysrev > 0 or #halfkeysagg > 0) and platforms >= 1 then
	     tbl2 = HtmlBuilder.create('table')
            .addClass('infobox wikitable')
            .attr('cellpadding', 0)
            .attr('cellspacing', 0)
            .css('width', '100%')
            .css('border-bottom', 'none')
            .css('margin', '0em')
            .done()
    elseif (#halfkeysrev > 0 or #halfkeysagg > 0 or custome_agg > 0 or custome_rev > 0) and  platforms == 0 then
        tbl2 = HtmlBuilder.create('table')
            .addClass('infobox wikitable')
            .attr('cellpadding', 0)
            .attr('cellspacing', 0)
            .css('width', '100%')
            .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('媒体评分')
            .done()

        tbl2
            .tag('tr')
                .tag('th')
                    .attr('rowspan', '2')
                    .css('background', '#e8f4f8')
                    .css('text-align', 'center')
                    .css('vertical-align', 'middle')
                    .wikitext('媒体')
                    .done()
                .tag('th')
                    .attr('colspan', #system)
                    .css('background', '#e8f4f8')
                    .css('vertical-align', 'middle')
                    .wikitext('得分')
                    .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 #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('媒体评分')
            .done()

	    tbl2
            .tag('tr')
                .tag('th')
                    .css('background', '#e8f4f8')
                    .css('text-align', 'center')
                    .css('vertical-align', 'middle')
                    .wikitext('媒体')
                    .done()
                .tag('th')
                    .css('background', '#e8f4f8')
                    .css('vertical-align', 'middle')
                    .wikitext('得分')
                    .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('不适用')
                                .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('不适用')
                            .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('汇总得分')
                        .done()
            tbl2
                .tag('tr')
                    .tag('th')
                        .attr('rowspan', '2')
                        .css('background', '#e8f4f8')
                        .css('text-align', 'center')
                        .css('vertical-align', 'middle')
                        .wikitext('媒体')
                        .done()
                    .tag('th')
                        .attr('colspan', #system+1)
                        .css('background', '#e8f4f8')
                        .css('vertical-align', 'middle')
                        .wikitext('得分')
                        .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('汇总得分')
                        .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()

                    for j = 1, #system do
                        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
                            forloop.tag('td').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('不适用')
                                .done()
                        elseif string.lower(tostring(args[tostring(system[j][2])])) == 'true' then
                            forloop.tag('td').done()
                        end
                    end
                end
            end
        end
	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('汇总得分')
                        .done()
                .tag('tr')
                    .tag('th')
                        .css('background', '#e8f4f8')
                        .css('text-align', 'center')
                        .wikitext('媒体')
                        .done()
                    .tag('th')
                        .css('background', '#e8f4f8')
                        .wikitext('得分')
                        .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('评论得分')
                .done()
            tbl2
                .tag('tr')
                    .tag('th')
                        .css('background', '#e8f4f8')
                        .css('text-align', 'center')
                        .wikitext('媒体')
                        .done()
                    .tag('th')
                        .attr('colspan', '25')
                        .css('background', '#e8f4f8')
                        .wikitext('得分')
                        .done()

            for i = 1, #reviewer do
                for k = 1, #halfkeysrev do
                    if reviewer[i][2] == halfkeysrev[k] then
                        tbl2
                            .tag('tr')
                                .tag('td')
                                    .css('text-align', 'center')
                                    .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
    return tbl2
end

--
-- Inserts a award into the table output.
--
function award(tbl, awardnum)
    local temp = tbl.tag('tr')
        .tag('td')
            .css('font-weight','bold')
            .css('background-color','#f2f2f2')
            .wikitext(args['award' .. awardnum .. 'Pub'])
            .done()
        .tag('td')
            .css('background-color','#f2f2f2')
            .wikitext(args['award' .. awardnum])
            .done()
    return temp
end

--
-- Insert awards header and calls award row creation.
--
function awards()
    if args['award1'] then
        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('所获奖项')
                    .done()
        Cell
            .tag('tr')
                .tag('th').wikitext('媒体')
                .tag('th').wikitext('奖项')

        for i, awardnum in ipairs(awardnums) do
            local awardRow = award(Cell, awardnum)
            awardRow
                .done()
        end
        return Cell
    end
end

--
-- Main tables
--

function renderMainTable()
    local tbl

    if args['award1'] or ((#halfkeysagg > 0 or #halfkeysrev > 0 or custome_agg > 0 or custome_rev > 0) and platforms >= 0) then
        if platforms == 0 then
            -- Width: 20% Seems better since it scales with the article size.
            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%')
            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

        if args.align and args.align ~= 'right' then
            tbl
                .css('float', args.align)
        else
            tbl
                .css('float', 'right')
        end

        renderTitleRow(tbl)

        tbl
            .tag('tr')
                .tag('td')
                    .node(reviews())
                    .done()

        tbl
            .tag('tr')
                .tag('td')
                    .node(awards())
                    .done()
    else
        category = categoryHandler{
            main = '[[Category:Empty templates on articles]]'
        }
        category = category or '' -- Check that we don't have a nil value for the category variable.
        tbl = HtmlBuilder.create()
		tbl.wikitext(category)
    end
    return tbl
end

--
-- Creates the table and calls functions that create the reviews and awards tables/columns/rows.
--
function p._reviewbox(reviewBoxArgs)
    local t = {}
    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()

    -- sorts args by string.
    for k in pairsByKeys(args) do
        table.insert(t, k)
    end
    keys = t

    -- creates a table of all unique reviewers.
    for i=1,#keys do
        if string.find(tostring(keys[i]), '_') ~= nil and platforms >= 1 then
            halfargs = Split(tostring(keys[i]),'_')
            for k=1, #reviewer do
                if reviewer[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, #reviewer do
                if reviewer[k][2] == keys[i] then
                    nitem[j] = keys[i]
                    j = j + 1
                end
            end
        end
    end
    halfkeysrev = nitem

    local flags = {}
    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

    -- render the main body of the Review Box
    local tbl = renderMainTable()

    -- render the appropriate wrapper around the Review Box, depending on the border param
    local res = HtmlBuilder.create()

    res.node(tbl)

    return tostring(res)
end

--
-- Main: frame function.
--
function p.reviewbox(frame)
    -- ParserFunctions considers the empty string to be false, so to preserve the previous
    -- behavior of {{Video game multiple console reviews}}, change any empty arguments to nil, so Lua will consider
    -- them false too.
    local args = {}
    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

return p