Difference between revisions of "Module:Video game reviews"
Jump to navigation
Jump to search
blackwiki>Frietjes (adjust margins for align=left and align=none) |
blackwiki>IceWelder m (fmt) |
||
| Line 9: | Line 9: | ||
local function getActiveSystems(args) | local function getActiveSystems(args) | ||
local activeSystems = {} | local activeSystems = {} | ||
| − | for k,v in pairs(args) do | + | for k, v in pairs(args) do |
if data.systems[k] and yesno(v) then | if data.systems[k] and yesno(v) then | ||
table.insert(activeSystems, k) | table.insert(activeSystems, k) | ||
| Line 83: | Line 83: | ||
if title then | if title then | ||
titleCell | titleCell | ||
| − | + | :wikitext(title) | |
else | else | ||
titleCell | titleCell | ||
| − | + | :addClass('Reception') | |
| − | + | :wikitext(data.i18n.reception) | |
end | end | ||
end | end | ||
| Line 93: | Line 93: | ||
local function renderMainHeading(builder, colspan, headingText, borderTop) | local function renderMainHeading(builder, colspan, headingText, borderTop) | ||
builder:tag('tr'):tag('th') | builder:tag('tr'):tag('th') | ||
| − | + | :attr('colspan', colspan) | |
| − | + | :css('background', '#d1dbdf') | |
| − | + | :css('border-top', borderTop) | |
| − | + | :wikitext(headingText) | |
end | end | ||
| Line 102: | Line 102: | ||
renderMainHeading(builder, #activeSystems + 1, mainHeading) | renderMainHeading(builder, #activeSystems + 1, mainHeading) | ||
builder:tag('tr') | builder:tag('tr') | ||
| − | + | :tag('th') | |
| − | + | :attr('rowspan', '2') | |
| − | + | :css('background', '#e8f4f8') | |
| − | + | :css('text-align', 'center') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(data.i18n.publication) | |
| − | + | :done() | |
| − | + | :tag('th') | |
| − | + | :attr('colspan', #activeSystems) | |
| − | + | :css('background', '#e8f4f8') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(data.i18n.score) | |
builder = builder:tag('tr') | builder = builder:tag('tr') | ||
| − | for _,v in ipairs(activeSystems) do | + | for _, v in ipairs(activeSystems) do |
builder:tag('th'):wikitext(data.systems[v].name) | builder:tag('th'):wikitext(data.systems[v].name) | ||
end | end | ||
| Line 123: | Line 123: | ||
renderMainHeading(builder, 2, mainHeading) | renderMainHeading(builder, 2, mainHeading) | ||
builder | builder | ||
| − | + | :tag('tr') | |
:tag('th') | :tag('th') | ||
| − | + | :css('background', '#e8f4f8') | |
| − | + | :css('text-align', 'center') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(nameHeading) | |
:done() | :done() | ||
:tag('th') | :tag('th') | ||
| − | + | :css('background', '#e8f4f8') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(data.i18n.score) | |
end | end | ||
| Line 139: | Line 139: | ||
builder = builder:tag('tr') | builder = builder:tag('tr') | ||
builder:tag('td') | builder:tag('td') | ||
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(name) | |
| − | for _,v in ipairs(activeSystems) do | + | for _, v in ipairs(activeSystems) do |
local combinedCode = code .. '_' .. v | local combinedCode = code .. '_' .. v | ||
local cell = builder:tag('td') | local cell = builder:tag('td') | ||
if args[combinedCode] then | if args[combinedCode] then | ||
cell | cell | ||
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(args[combinedCode]) | |
elseif na then | elseif na then | ||
cell | cell | ||
| − | + | :css('color', '#707070') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :css('text-align', 'center') | |
| − | + | :addClass('table-na') | |
| − | + | :wikitext(data.i18n.na) | |
end | end | ||
end | end | ||
| Line 162: | Line 162: | ||
local function renderRating(builder, name, rating) | local function renderRating(builder, name, rating) | ||
builder:tag('tr') | builder:tag('tr') | ||
| − | + | :tag('td') | |
| − | + | :css('text-align', 'center') | |
| − | + | :css('vertical-align', 'middle') | |
| − | + | :wikitext(name) | |
| − | + | :done() | |
| − | + | :tag('td') | |
| − | + | :css('text-align', 'center') | |
| − | + | :wikitext(rating) | |
end | end | ||
local function renderReviews(builder, providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args) | local function renderReviews(builder, providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args) | ||
builder = builder:tag('table') | builder = builder:tag('table') | ||
| − | + | :addClass('infobox wikitable') | |
| − | + | :attr('cellpadding', 0) | |
| − | + | :attr('cellspacing', 0) | |
| − | + | :css('width', '100%') | |
| − | + | :css('border-bottom', 'none') | |
| − | + | :css('margin', '0em') | |
local reviewerCount = #providedReviewers + #customReviewerKeys | local reviewerCount = #providedReviewers + #customReviewerKeys | ||
| Line 196: | Line 196: | ||
end | end | ||
| − | for _,v in ipairs(providedReviewers) do | + | for _, v in ipairs(providedReviewers) do |
renderRatingsBySystem(builder, v, data.reviewers[v].name, activeSystems, args, na) | renderRatingsBySystem(builder, v, data.reviewers[v].name, activeSystems, args, na) | ||
end | end | ||
| − | for _,v in ipairs(customReviewerKeys) do | + | for _, v in ipairs(customReviewerKeys) do |
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na) | renderRatingsBySystem(builder, v, args[v], activeSystems, args, na) | ||
end | end | ||
| Line 205: | Line 205: | ||
if aggregatorCount ~= 0 then | if aggregatorCount ~= 0 then | ||
if reviewerCount ~= 0 then | if reviewerCount ~= 0 then | ||
| − | renderMainHeading(builder, #activeSystems+1, aggregateScore) | + | renderMainHeading(builder, #activeSystems + 1, aggregateScore) |
elseif showplatforms then | elseif showplatforms then | ||
renderHeadingRowWithSystems(builder, aggregateScore, activeSystems) | renderHeadingRowWithSystems(builder, aggregateScore, activeSystems) | ||
| Line 212: | Line 212: | ||
end | end | ||
| − | for _,v in ipairs(providedAggregators) do | + | for _, v in ipairs(providedAggregators) do |
renderRatingsBySystem(builder, v, data.aggregators[v].name, activeSystems, args, na) | renderRatingsBySystem(builder, v, data.aggregators[v].name, activeSystems, args, na) | ||
end | end | ||
| − | for _,v in ipairs(customAggregatorKeys) do | + | for _, v in ipairs(customAggregatorKeys) do |
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na) | renderRatingsBySystem(builder, v, args[v], activeSystems, args, na) | ||
end | end | ||
| Line 223: | Line 223: | ||
if aggregatorCount ~= 0 then | if aggregatorCount ~= 0 then | ||
renderHeadingRow(builder, aggregateScore, data.i18n.aggregator) | renderHeadingRow(builder, aggregateScore, data.i18n.aggregator) | ||
| − | for _,v in ipairs(providedAggregators) do | + | for _, v in ipairs(providedAggregators) do |
renderRating(builder, data.aggregators[v].name, args[v]) | renderRating(builder, data.aggregators[v].name, args[v]) | ||
end | end | ||
| − | for _,v in ipairs(customAggregatorKeys) do | + | for _, v in ipairs(customAggregatorKeys) do |
renderRating(builder, args[v], args[v .. 'Score']) | renderRating(builder, args[v], args[v .. 'Score']) | ||
end | end | ||
| Line 232: | Line 232: | ||
if reviewerCount ~= 0 then | if reviewerCount ~= 0 then | ||
renderHeadingRow(builder, reviewScore, data.i18n.publication) | renderHeadingRow(builder, reviewScore, data.i18n.publication) | ||
| − | for _,v in ipairs(providedReviewers) do | + | for _, v in ipairs(providedReviewers) do |
renderRating(builder, data.reviewers[v].name, args[v]) | renderRating(builder, data.reviewers[v].name, args[v]) | ||
end | end | ||
| − | for _,v in ipairs(customReviewerKeys) do | + | for _, v in ipairs(customReviewerKeys) do |
renderRating(builder, args[v], args[v .. 'Score']) | renderRating(builder, args[v], args[v .. 'Score']) | ||
end | end | ||
| Line 244: | Line 244: | ||
local function renderAwards(builder, args, awardKeys, borderTop) | local function renderAwards(builder, args, awardKeys, borderTop) | ||
builder = builder:tag('table') | builder = builder:tag('table') | ||
| − | + | :addClass('infobox wikitable') | |
| − | + | :css('width', '100%') | |
| − | + | :css('margin', '0em') | |
| − | + | :css('border-top', borderTop) | |
| − | + | :attr('cellpadding', 3) | |
| − | + | :attr('cellspacing', 0) | |
| − | + | ||
renderMainHeading(builder, 2, data.i18n[#awardKeys == 1 and 'award' or 'awards'], borderTop) | renderMainHeading(builder, 2, data.i18n[#awardKeys == 1 and 'award' or 'awards'], borderTop) | ||
builder:tag('tr') | builder:tag('tr') | ||
| − | + | :tag('th') | |
| − | + | :wikitext(data.i18n.publication) | |
| − | + | :done() | |
| − | + | :tag('th') | |
| − | + | :wikitext(data.i18n.award) | |
| − | for _,v in ipairs(awardKeys) do | + | for _, v in ipairs(awardKeys) do |
| − | + | builder:tag('tr') | |
| − | + | :tag('td') | |
| − | + | :css('font-weight', 'bold') | |
| − | + | :css('background-color', '#f2f2f2') | |
| − | + | :wikitext(args[v .. 'Pub']) | |
| − | + | :done() | |
| − | + | :tag('td') | |
| − | + | :css('background-color', '#f2f2f2') | |
| − | + | :wikitext(args[v]) | |
end | end | ||
end | end | ||
| Line 275: | Line 275: | ||
local function renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata) | local function renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata) | ||
local tbl = mw.html.create('table') | local tbl = mw.html.create('table') | ||
| − | + | :attr('cellpadding', 0) | |
| − | + | :attr('cellspacing', 0) | |
| − | + | :css('background', 'transparent') | |
| − | + | :css('padding', '0em') | |
| − | + | :css('margin', args.align and | |
| − | ((args.align == 'left' or args.align == 'none') and '0em 1em 1em 0em') or | + | ((args.align == 'left' or args.align == 'none') and '0em 1em 1em 0em') or |
'0em 1em 1em 1em') | '0em 1em 1em 1em') | ||
| − | + | :css('text-align', 'center') | |
| − | + | :css('float', args.align or 'right') | |
| − | + | :css('clear', args.align or 'right') | |
if #activeSystems == 0 then | if #activeSystems == 0 then | ||
-- Width: 20% Seems better since it scales with the article size. | -- Width: 20% Seems better since it scales with the article size. | ||
tbl | tbl | ||
| − | + | :css('width', args.width or '23em') | |
end | end | ||
| Line 295: | Line 295: | ||
or args.state == 'collapsed' or args.state == 'expanded') then | or args.state == 'collapsed' or args.state == 'expanded') then | ||
tbl | tbl | ||
| − | + | :addClass('collapsible') | |
| − | + | :addClass(args.state) | |
end | end | ||
renderTitleRow(tbl, args.title) | renderTitleRow(tbl, args.title) | ||
| Line 302: | Line 302: | ||
if args.subtitle then | if args.subtitle then | ||
tbl:tag('tr'):tag('th') | tbl:tag('tr'):tag('th') | ||
| − | + | :wikitext(args.subtitle) | |
end | end | ||
| Line 312: | Line 312: | ||
if wikidata == true then | if wikidata == true then | ||
tbl:tag('tr'):tag('td') | tbl:tag('tr'):tag('td') | ||
| − | + | :tag('table') | |
| − | + | :addClass('infobox wikitable') | |
| − | + | :css('width', '100%') | |
| − | + | :css('margin', '0em') | |
| − | + | :css('border-top', 'none') | |
| − | + | :attr('cellpadding', 3) | |
| − | + | :attr('cellspacing', 0) | |
| − | + | :tag('tr'):tag('th') | |
| − | + | :css('background', '#d1dbdf') | |
| − | + | :css('border-top', 'none') | |
| − | + | :wikitext('Edit on wikidata ' .. vgwd.getUpdateLink('nosub')) | |
end | end | ||
| Line 330: | Line 330: | ||
local function checkForWikidata(frame, args, activeSystems, providedAggregators) | local function checkForWikidata(frame, args, activeSystems, providedAggregators) | ||
local wikidata = false | local wikidata = false | ||
| − | + | ||
vgwd.setDateFormat(args["df"]) | vgwd.setDateFormat(args["df"]) | ||
vgwd.setGame(args["qid"]) | vgwd.setGame(args["qid"]) | ||
| Line 338: | Line 338: | ||
vgwd.setUpdateLinkStyle("pen") | vgwd.setUpdateLinkStyle("pen") | ||
vgwd.setSystemFormat(args["systemFormat"]) | vgwd.setSystemFormat(args["systemFormat"]) | ||
| − | + | ||
-- Loop through aggregators if we have any. | -- Loop through aggregators if we have any. | ||
if #providedAggregators ~= 0 then | if #providedAggregators ~= 0 then | ||
| − | for | + | for _, aggr in ipairs(providedAggregators) do |
-- Check if vgwd knows this aggregator. | -- Check if vgwd knows this aggregator. | ||
if vgwd.setReviewer(aggr) == nil then | if vgwd.setReviewer(aggr) == nil then | ||
-- Loop through active systems | -- Loop through active systems | ||
if #activeSystems ~= 0 then | if #activeSystems ~= 0 then | ||
| − | for | + | for _, sys in ipairs(activeSystems) do |
local combinedCode = aggr .. '_' .. sys | local combinedCode = aggr .. '_' .. sys | ||
if args[combinedCode] == 'wikidata' then | if args[combinedCode] == 'wikidata' then | ||
| Line 355: | Line 355: | ||
args[combinedCode] = vgwdScore | args[combinedCode] = vgwdScore | ||
end | end | ||
| − | wikidata = true | + | wikidata = true |
end | end | ||
| − | end | + | end |
else | else | ||
vgwd.setShowSystem(true) | vgwd.setShowSystem(true) | ||
| − | + | if args[aggr] == 'wikidata' then | |
local vgwdScore = vgwd.printReviewScores(frame) | local vgwdScore = vgwd.printReviewScores(frame) | ||
if vgwdScore then | if vgwdScore then | ||
| Line 367: | Line 367: | ||
wikidata = true | wikidata = true | ||
end | end | ||
| − | end | + | end |
end | end | ||
end | end | ||
| Line 391: | Line 391: | ||
getArgs = require('Module:Arguments').getArgs | getArgs = require('Module:Arguments').getArgs | ||
end | end | ||
| − | return p._reviewbox(frame, getArgs(frame, {wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n})) | + | return p._reviewbox(frame, getArgs(frame, { wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n })) |
end | end | ||
return p | return p | ||
Revision as of 19:32, 24 March 2019
| This Lua module is used on approximately 11,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages. Consider discussing changes on the talk page before implementing them.
Transclusion count updated automatically (see documentation). |
| 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. |
| Related pages |
|---|
This module implements the {{Video game reviews}} template. Please see the template page for usage instructions.
Required submodules
Tracking/maintenance category
require('Module:No globals')
local p = {}
local data = require('Module:Video game reviews/data')
local yesno = require('Module:Yesno')
local vgwd = require('Module:Video game wikidata')
local getArgs
local function getActiveSystems(args)
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 reviewers, aggregators, awards = {}, {}, {}
for k in pairs(args) do
if string.match(k, '^rev%d+$') then
table.insert(reviewers, k)
elseif string.match(k, '^agg%d+$') then
table.insert(aggregators, k)
elseif string.match(k, '^award%d+$') then
table.insert(awards, k)
end
end
local function comparator(a, b)
return tonumber(a:match('%d+')) < tonumber(b:match('%d+'))
end
table.sort(reviewers, comparator)
table.sort(aggregators, comparator)
table.sort(awards, comparator)
return reviewers, aggregators, awards
end
local function getProvidedReviewersAndAggregators(args, usePlatforms)
local providedReviewers, providedAggregators = {}, {}
if usePlatforms then
local seen = {}
for k in pairs(args) do
local splitPos = string.find(k, '_')
if splitPos then
local halfarg = string.sub(k, 1, splitPos - 1)
if not seen[halfarg] then
seen[halfarg] = true
if data.reviewers[halfarg] then
table.insert(providedReviewers, halfarg)
elseif data.aggregators[halfarg] then
table.insert(providedAggregators, halfarg)
end
end
end
end
else
for k in pairs(args) do
if not string.find(k, '_') then
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 renderTitleRow(tbl, title)
local titleCell = tbl:tag('tr'):tag('th')
if title then
titleCell
:wikitext(title)
else
titleCell
:addClass('Reception')
:wikitext(data.i18n.reception)
end
end
local function renderMainHeading(builder, colspan, headingText, borderTop)
builder:tag('tr'):tag('th')
:attr('colspan', colspan)
:css('background', '#d1dbdf')
:css('border-top', borderTop)
:wikitext(headingText)
end
local function renderHeadingRowWithSystems(builder, mainHeading, activeSystems)
renderMainHeading(builder, #activeSystems + 1, mainHeading)
builder:tag('tr')
:tag('th')
:attr('rowspan', '2')
:css('background', '#e8f4f8')
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(data.i18n.publication)
:done()
:tag('th')
:attr('colspan', #activeSystems)
:css('background', '#e8f4f8')
:css('vertical-align', 'middle')
:wikitext(data.i18n.score)
builder = builder:tag('tr')
for _, v in ipairs(activeSystems) do
builder:tag('th'):wikitext(data.systems[v].name)
end
end
local function renderHeadingRow(builder, mainHeading, nameHeading)
renderMainHeading(builder, 2, mainHeading)
builder
:tag('tr')
:tag('th')
:css('background', '#e8f4f8')
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(nameHeading)
:done()
:tag('th')
:css('background', '#e8f4f8')
:css('vertical-align', 'middle')
:wikitext(data.i18n.score)
end
local function renderRatingsBySystem(builder, code, name, activeSystems, args, na)
builder = builder:tag('tr')
builder:tag('td')
:css('vertical-align', 'middle')
:wikitext(name)
for _, v in ipairs(activeSystems) do
local combinedCode = code .. '_' .. v
local cell = builder:tag('td')
if args[combinedCode] then
cell
:css('vertical-align', 'middle')
:wikitext(args[combinedCode])
elseif na then
cell
:css('color', '#707070')
:css('vertical-align', 'middle')
:css('text-align', 'center')
:addClass('table-na')
:wikitext(data.i18n.na)
end
end
end
local function renderRating(builder, name, rating)
builder:tag('tr')
:tag('td')
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(name)
:done()
:tag('td')
:css('text-align', 'center')
:wikitext(rating)
end
local function renderReviews(builder, providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
builder = builder:tag('table')
:addClass('infobox wikitable')
:attr('cellpadding', 0)
:attr('cellspacing', 0)
:css('width', '100%')
:css('border-bottom', 'none')
:css('margin', '0em')
local reviewerCount = #providedReviewers + #customReviewerKeys
local aggregatorCount = #providedAggregators + #customAggregatorKeys
local reviewScore = data.i18n[reviewerCount == 1 and 'reviewScore' or 'reviewScores']
local aggregateScore = data.i18n[aggregatorCount == 1 and 'aggregateScore' or 'aggregateScores']
if #activeSystems ~= 0 then
builder:wikitext(data.i18n.multiplatformCategory)
local na = yesno(args.na)
local showplatforms = #activeSystems ~= 1 or yesno(args.showplatforms)
if reviewerCount ~= 0 then
if showplatforms then
renderHeadingRowWithSystems(builder, reviewScore, activeSystems)
else
renderHeadingRow(builder, reviewScore, data.i18n.publication)
end
for _, v in ipairs(providedReviewers) do
renderRatingsBySystem(builder, v, data.reviewers[v].name, activeSystems, args, na)
end
for _, v in ipairs(customReviewerKeys) do
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
end
end
if aggregatorCount ~= 0 then
if reviewerCount ~= 0 then
renderMainHeading(builder, #activeSystems + 1, aggregateScore)
elseif showplatforms then
renderHeadingRowWithSystems(builder, aggregateScore, activeSystems)
else
renderHeadingRow(builder, aggregateScore, data.i18n.aggregator)
end
for _, v in ipairs(providedAggregators) do
renderRatingsBySystem(builder, v, data.aggregators[v].name, activeSystems, args, na)
end
for _, v in ipairs(customAggregatorKeys) do
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
end
end
else
builder:wikitext(data.i18n.singleplatformCategory)
if aggregatorCount ~= 0 then
renderHeadingRow(builder, aggregateScore, data.i18n.aggregator)
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
if reviewerCount ~= 0 then
renderHeadingRow(builder, reviewScore, data.i18n.publication)
for _, v in ipairs(providedReviewers) do
renderRating(builder, data.reviewers[v].name, args[v])
end
for _, v in ipairs(customReviewerKeys) do
renderRating(builder, args[v], args[v .. 'Score'])
end
end
end
end
local function renderAwards(builder, args, awardKeys, borderTop)
builder = builder:tag('table')
:addClass('infobox wikitable')
:css('width', '100%')
:css('margin', '0em')
:css('border-top', borderTop)
:attr('cellpadding', 3)
:attr('cellspacing', 0)
renderMainHeading(builder, 2, data.i18n[#awardKeys == 1 and 'award' or 'awards'], borderTop)
builder:tag('tr')
:tag('th')
:wikitext(data.i18n.publication)
:done()
:tag('th')
:wikitext(data.i18n.award)
for _, v in ipairs(awardKeys) do
builder:tag('tr')
:tag('td')
:css('font-weight', 'bold')
:css('background-color', '#f2f2f2')
:wikitext(args[v .. 'Pub'])
:done()
:tag('td')
:css('background-color', '#f2f2f2')
:wikitext(args[v])
end
end
local function renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
local tbl = mw.html.create('table')
:attr('cellpadding', 0)
:attr('cellspacing', 0)
:css('background', 'transparent')
:css('padding', '0em')
:css('margin', args.align and
((args.align == 'left' or args.align == 'none') and '0em 1em 1em 0em') or
'0em 1em 1em 1em')
:css('text-align', 'center')
:css('float', args.align or 'right')
:css('clear', args.align or 'right')
if #activeSystems == 0 then
-- Width: 20% Seems better since it scales with the article size.
tbl
:css('width', args.width or '23em')
end
if args.title and args.state and (args.state == 'autocollapse'
or args.state == 'collapsed' or args.state == 'expanded') then
tbl
:addClass('collapsible')
:addClass(args.state)
end
renderTitleRow(tbl, args.title)
if args.subtitle then
tbl:tag('tr'):tag('th')
:wikitext(args.subtitle)
end
renderReviews(tbl:tag('tr'):tag('td'), providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
if #awardKeys ~= 0 then
renderAwards(tbl:tag('tr'):tag('td'), args, awardKeys, (#customAggregatorKeys ~= 0 or #customReviewerKeys ~= 0 or #providedAggregators ~= 0 or #providedReviewers ~= 0) and 'none' or nil)
end
if wikidata == true then
tbl:tag('tr'):tag('td')
:tag('table')
:addClass('infobox wikitable')
:css('width', '100%')
:css('margin', '0em')
:css('border-top', 'none')
:attr('cellpadding', 3)
:attr('cellspacing', 0)
:tag('tr'):tag('th')
:css('background', '#d1dbdf')
:css('border-top', 'none')
:wikitext('Edit on wikidata ' .. vgwd.getUpdateLink('nosub'))
end
return tbl
end
local function checkForWikidata(frame, args, activeSystems, providedAggregators)
local wikidata = false
vgwd.setDateFormat(args["df"])
vgwd.setGame(args["qid"])
vgwd.setSystem(nil)
vgwd.setGenerateReferences(true)
vgwd.setShowUpdateLink(false)
vgwd.setUpdateLinkStyle("pen")
vgwd.setSystemFormat(args["systemFormat"])
-- Loop through aggregators if we have any.
if #providedAggregators ~= 0 then
for _, aggr in ipairs(providedAggregators) do
-- Check if vgwd knows this aggregator.
if vgwd.setReviewer(aggr) == nil then
-- Loop through active systems
if #activeSystems ~= 0 then
for _, sys in ipairs(activeSystems) do
local combinedCode = aggr .. '_' .. sys
if args[combinedCode] == 'wikidata' then
vgwd.setSystem(sys)
vgwd.setShowSystem(false)
local vgwdScore = vgwd.printReviewScores(frame)
if vgwdScore then
args[combinedCode] = vgwdScore
end
wikidata = true
end
end
else
vgwd.setShowSystem(true)
if args[aggr] == 'wikidata' then
local vgwdScore = vgwd.printReviewScores(frame)
if vgwdScore then
args[aggr] = vgwdScore
end
wikidata = true
end
end
end
end
end
return wikidata
end
function p._reviewbox(frame, args)
local activeSystems = getActiveSystems(args)
local customReviewerKeys, customAggregatorKeys, awardKeys = getArgKeyTables(args)
local providedReviewers, providedAggregators = getProvidedReviewersAndAggregators(args, #activeSystems ~= 0)
local wikidata = checkForWikidata(frame, args, activeSystems, providedAggregators)
if #customAggregatorKeys ~= 0 or #customReviewerKeys ~= 0 or #providedAggregators ~= 0 or #providedReviewers ~= 0 or #awardKeys ~= 0 then
return renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
elseif mw.title.getCurrentTitle().namespace == 0 then
return data.i18n.emptyCategory
end
end
function p.reviewbox(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
return p._reviewbox(frame, getArgs(frame, { wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n }))
end
return p