Module:Video game reviews/sandbox: Difference between revisions

Content deleted Content added
m vgwd.getUpdateLink takes no argument
No edit summary
 
(47 intermediate revisions by 8 users not shown)
Line 1:
require('Module:No globalsstrict')
 
local p = {}
local data = require('Module:Video game reviews/data/sandbox')
local yesno = require('Module:Yesno')
local vgwd = require('Module:Video game wikidata/sandbox')
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)
Line 23:
local reviewers, aggregators, awards = {}, {}, {}
for k in pairs(args) do
if string.match(k, '^rev%d+$'data.i18n.pattern.reviewer) then
table.insert(reviewers, k)
elseif string.match(k, '^agg%d+$'data.i18n.pattern.aggregator) then
table.insert(aggregators, k)
elseif string.match(k, '^data.i18n.pattern.award%d+$') then
table.insert(awards, k)
end
Line 78:
end
 
local function renderTitlerenderHeadingRowWithSystems(asidebuilder, titleactiveSystems, headingText)
local titleElement = aside:tag('div')
:attr('id', 'reception-title')
:css('font-weight', 'bold')
 
if title then
titleElement
:wikitext(title)
else
titleElement
:addClass('Reception')
:wikitext(data.i18n.reception)
end
end
 
local function renderCaption(builder, captionText, borderTop)
builder:tag('caption')
:css('font-size', 'inherit')
:css('background', '#d1dbdf')
:css('border-top', borderTop or '1px solid #a2a9b1')
:css('border-left', '1px solid #a2a9b1')
:css('border-right', '1px solid #a2a9b1')
:wikitext(captionText)
end
 
local function renderHeadingRowWithSystems(builder, captionText, activeSystems)
renderCaption(builder, captionText)
builder:tag('tr')
:addClass(data.i18n.class.headerrow)
:tag('th')
:attr('scope', 'col')
:attr('rowspan', '2')
:wikitext(headingText)
:css('background', '#e8f4f8')
:done()
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(data.i18n.publication)
:done()
:tag('th')
:attr('scope', 'colcolgroup')
:attr('colspan', #activeSystems)
:wikitext(data.i18n.display.score)
:css('background', '#e8f4f8')
:done()
:css('vertical-align', 'middle')
:wikitext(data.i18n.score)
builder = builder:tag('tr')
for _, v in ipairs(activeSystems) do
builder:tag('th')
:attr('scope', 'col')
:wikitext(data.systems[v].name)
:attr('scope', 'col')
:done()
end
end
 
local function renderHeadingRow(builder, captionText, nameHeading)
renderCaption(builder, captionText:tag('tr')
:addClass(data.i18n.class.headerrow)
builder
:tag('trth')
:tagattr('thscope', 'col')
:attrwikitext('scope', 'col'nameHeading)
:done()
:css('background', '#e8f4f8')
:csstag('text-align', 'centerth')
:cssattr('vertical-alignscope', 'middlecol')
:wikitext(nameHeadingdata.i18n.display.score)
:done()
:tag('th')
:attr('scope', 'col')
:css('background', '#e8f4f8')
:css('vertical-align', 'middle')
:wikitext(data.i18n.score)
end
 
Line 149 ⟶ 116:
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])
:done()
elseif na then
cell
:cssaddClass('color', '#707070'data.i18n.class.na)
:wikitext(data.i18n.display.na)
:css('vertical-align','middle')
:cssdone('text-align', 'center')
:addClass('table-na')
:wikitext(data.i18n.na)
end
end
Line 173 ⟶ 137:
builder:tag('tr')
:tag('td')
:addClass(data.i18n.class.centeredpub)
:css('text-align', 'center')
:css('vertical-align', 'middle')
:wikitext(name)
:done()
:tag('td')
:css('text-align', 'center')
:wikitext(rating)
:done()
end
 
local function renderReviewsrenderAggregators(builder, providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
local aggregatorCount = #providedAggregators + #customAggregatorKeys
if aggregatorCount == 0 then return end
builder = builder:tag('table')
:addClass('infobox wikitable'data.i18n.class.aggregators)
:addClass(data.i18n.class.wikitable)
:css('border-spacing', 0)
:addClass(args.state and 'mw-collapsible-content' or nil)
:css('width', '100%')
:csstag('border-bottom', 'nonecaption')
:wikitext(data.i18n.display[aggregatorCount == 1 and 'aggregateScore' or 'aggregateScores'])
:css('margin', '0em')
:done()
 
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 ~= 0showplatforms then
renderHeadingRowWithSystems(builder, activeSystems, data.i18n.display.aggregator)
if showplatforms then
else
renderHeadingRowWithSystems(builder, reviewScore, activeSystems)
renderHeadingRow(builder, data.i18n.display.aggregator)
else
end
renderHeadingRow(builder, reviewScore, data.i18n.publication)
end
 
for _, v in ipairs(providedReviewersprovidedAggregators) do
renderRatingsBySystem(builder, v, data.reviewersaggregators[v].name, activeSystems, args, na)
end
for _,v in ipairs(customReviewerKeys) do
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
end
end
for _, v in ipairs(customAggregatorKeys) do
if aggregatorCount ~= 0 then
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
if reviewerCount ~= 0 then
renderCaption(builder, 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:wikitextrenderHeadingRow(builder, data.i18n.singleplatformCategorydisplay.aggregator)
for _, v in ipairs(providedAggregators) do
if aggregatorCount ~= 0 then
renderHeadingRowrenderRating(builder, aggregateScore, data.i18naggregators[v].aggregatorname, args[v])
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
for _, v in ipairs(customAggregatorKeys) do
if reviewerCount ~= 0 then
renderHeadingRowrenderRating(builder, reviewScoreargs[v], dataargs[v .i18n.publication 'Score'])
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 renderAwardsrenderReviews(builder, argsprovidedReviewers, awardKeysactiveSystems, borderTop)
customReviewerKeys, args, reviewerCount, priorReviewCount)
if reviewerCount == 0 then return end
builder = builder:tag('table')
:addClass('infobox wikitable'data.i18n.class.reviews)
:addClass(data.i18n.class.wikitable)
:css('width', '100%')
:addClass(args.state and 'mw-collapsible-content' or nil)
:css('margin', '0em')
:csstag('border-topcaption', borderTop)
:wikitext(data.i18n.display[reviewerCount == 1 and 'reviewScore' or 'reviewScores'])
:css('border-spacing', 0)
:addClass(priorReviewCount > 0 and data.i18n.class.stacked or nil)
:done()
if #activeSystems ~= 0 then
renderCaption(builder, data.i18n[#awardKeys == 1 and 'award' or 'awards'], borderTop)
local na = yesno(args.na)
local showplatforms = #activeSystems ~= 1 or yesno(args.showplatforms)
if showplatforms then
renderHeadingRowWithSystems(builder, activeSystems, data.i18n.display.publication)
else
renderHeadingRow(builder, data.i18n.display.publication)
end
 
for _, v in ipairs(providedReviewers) do
builder:tag('tr')
renderRatingsBySystem(builder, v, data.reviewers[v].name, activeSystems, args, na)
:tag('th')
end
:attr('scope', 'col')
for _, v in ipairs(customReviewerKeys) do
:wikitext(data.i18n.publication)
renderRatingsBySystem(builder, v, args[v], activeSystems, args, na)
:done()
end
:tag('th')
else
:attr('scope', 'col')
:wikitextrenderHeadingRow(builder, data.i18n.awarddisplay.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
 
local function renderAwards(builder, args, awardKeys, priorReviewCount)
if #awardKeys == 0 then return end
builder = builder:tag('table')
:addClass(data.i18n.class.awards)
:addClass(data.i18n.class.wikitable)
:addClass(args.state and 'mw-collapsible-content' or nil)
:tag('caption')
:wikitext(data.i18n.display[#awardKeys == 1 and 'award' or 'awards'])
:addClass(priorReviewCount > 0 and data.i18n.class.stacked or nil)
:done()
:tag('tr')
:tag('th')
:attr('scope', 'col')
:wikitext(data.i18n.display.publication)
:done()
:tag('th')
:attr('scope', 'col')
:wikitext(data.i18n.display.award)
:done()
 
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])
:done()
end
builder:done()
builder:done()
end
 
local function renderEditOnWikidata(builder, wikidata, state)
local function renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
if not wikidata then return end
local aside = mw.html.create('div')
:attr('role', 'complementary')
builder:tag('div')
:attr('aria-labelledby', 'reception-title')
:addClass(data.i18n.class.wikidata)
:css('margin', args.align and
:addClass(state and 'mw-collapsible-content' or nil)
((args.align == 'left' or args.align == 'none') and '0em 1em 1em 0em') or
:wikitext(vgwd.getUpdateLink())
'0em 1em 1em 1em')
:done()
:css('text-align', 'center')
end
: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.
aside
:css('width', args.width or '23em')
end
 
local function categorizePlatformCount(builder, platformCount)
if args.title and args.state and (args.state == 'autocollapse'
if platformCount ~= 0 then
or args.state == 'collapsed' or args.state == 'expanded') then
builder:wikitext(data.i18n.category.multiplatform)
aside
else
:addClass('mw-collapsible')
builder:wikitext(data.i18n.category.singleplatform)
:addClass(args.state == 'collapsed' and 'mw-collapsed' or args.state)
end
end
renderTitle(aside, args.title)
 
local function renderTitles(builder, title, subtitle)
if args.subtitle then
aside builder:tag('div')
:addClass(data.i18n.class.title)
:css('font-weight', 'bold')
:wikitext(argstitle or data.subtitlei18n.display.reception)
:done()
end
 
if subtitle then
renderReviews(aside:tag('div'), providedReviewers, providedAggregators, activeSystems, customAggregatorKeys, customReviewerKeys, args)
builder:tag('div')
if #awardKeys ~= 0 then
:addClass(data.i18n.class.subtitle)
renderAwards(aside:tag('div'), args, awardKeys, (#customAggregatorKeys ~= 0 or #customReviewerKeys ~= 0 or #providedAggregators ~= 0 or #providedReviewers ~= 0) and 'none' or nil)
-- The only reason to use the subtitle is collapsible content
-- So always add the related class.
:addClass('mw-collapsible-content')
:wikitext(subtitle)
:done()
end
end
 
local function render(providedReviewers, providedAggregators, awardKeys,
if wikidata == true then
activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
aside:tag('div')
local is_collapsible = args.title and args.state and
:tag('table')
(args.state == data.i18n.state.autocollapse or
:addClass('infobox wikitable noprint')
args.state == data.i18n.state.collapsed or
:attr('role', 'presentation')
args.state == data.i18n.state.expanded
:css('width', '100%')
)
:css('margin', '0em')
local div = mw.html.create('div')
:css('border-top', 'none')
:cssattr('border-spacingrole', 0'complementary')
:addClass(data.i18n.class.container)
:tag('tr'):tag('td')
:addClass(#activeSystems == 0 and data.i18n.class.containersingle or nil)
:css('border-top', 'none')
:addClass(args.align == data.i18n.align.left and data.i18n.class.containerleft or nil)
:css('background', '#d1dbdf')
:addClass(args.align == data.i18n.align.none and data.i18n.class.containernone or nil)
:css('text-align', 'center')
:addClass(is_collapsible and 'mw-collapsible' or nil)
:css('font-weight', 'bold')
:addClass(is_collapsible and args.state == data.i18n.state.collapsed and 'mw-collapsed' or nil)
:wikitext('Edit on wikidata '.. vgwd.getUpdateLink())
:addClass(is_collapsible and args.state == data.i18n.state.autocollapse and args.state or nil)
end
 
renderTitles(div, args.title, args.subtitle)
return aside
 
local aggregatorCount = #providedAggregators + #customAggregatorKeys
renderAggregators(
div,
providedAggregators,
activeSystems,
customAggregatorKeys,
args,
aggregatorCount
)
local reviewerCount = #customReviewerKeys + #providedReviewers
renderReviews(
div,
providedReviewers,
activeSystems,
customReviewerKeys,
args,
reviewerCount,
aggregatorCount
)
renderAwards(
div,
args,
awardKeys,
reviewerCount + aggregatorCount
)
renderEditOnWikidata(div, wikidata, args.state)
categorizePlatformCount(div, #activeSystems)
return div
end
 
Line 342 ⟶ 346:
local wikidata = false
if args.qid == 'none' then
vgwd.setDateFormat(args["df"])
return wikidata
vgwd.setGame(args["qid"])
end
 
vgwd.setDateFormat(args.df)
vgwd.setGame(args.qid)
vgwd.setSystem(nil)
vgwd.setGenerateReferences(true)
vgwd.setShowUpdateLink(false)
vgwd.setUpdateLinkStyle("text and pen")
vgwd.setSystemFormat(args[".systemFormat"])
 
-- Loop through aggregators if we have any.
if #providedAggregators ~= 0 then
for _i_, 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 _j_, sys in ipairs(activeSystems) do
local combinedCode = aggr .. '_' .. sys
if args[combinedCode] == 'wikidata' then
Line 366 ⟶ 374:
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
Line 378 ⟶ 386:
wikidata = true
end
end
end
end
Line 391 ⟶ 399:
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 frame:extensionTag{
return renderMainTable(providedReviewers, providedAggregators, awardKeys, activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
name='templatestyles', args = { src = data.i18n.templatestyles }
} .. tostring(render(
providedReviewers,
providedAggregators,
awardKeys,
activeSystems,
customAggregatorKeys,
customReviewerKeys,
args,
wikidata
))
elseif mw.title.getCurrentTitle().namespace == 0 then
return data.i18n.emptyCategorycategory.empty
end
end
Line 402 ⟶ 422:
getArgs = require('Module:Arguments').getArgs
end
return p._reviewbox(frame, getArgs(frame,
{ wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n }
))
end