Module:Video game reviews/sandbox: Difference between revisions

Content deleted Content added
move css
No edit summary
 
(33 intermediate revisions by 6 users not shown)
Line 1:
require('Module:No globalsstrict')
 
local p = {}
Line 78:
end
 
local function renderMainHeadingrenderHeadingRowWithSystems(builder, colspanactiveSystems, headingText, borderTop)
builder:tag('tr')
:addClass('vgr-main-heading'data.i18n.class.headerrow)
:tag('th')
:attr('colspanscope', colspan'col')
:attr('scoperowspan', colspan == 1 and 'col' or 'colgroup2')
:css('border-top', borderTop)
:wikitext(headingText)
:done()
end
 
local function renderHeadingRowWithSystems(builder, mainHeading, activeSystems)
renderMainHeading(builder, #activeSystems + 1, mainHeading)
builder:tag('tr')
:addClass('vgr-systems')
:tag('th')
:attr('rowspan', '2')
:attr('scope', 'col')
:wikitext(data.i18n.publication)
:done()
:tag('th')
:attr('scope', 'colgroup')
:attr('colspan', #activeSystems)
:wikitext(data.i18n.display.score)
:attr('scope', #activeSystems == 1 and 'col' or 'colgroup')
:wikitext(data.i18n.score)
:done()
builder = builder:tag('tr')
Line 112 ⟶ 100:
end
 
local function renderHeadingRow(builder, mainHeading, nameHeading)
renderMainHeading(builder, 2, mainHeading)
builder:tag('tr')
:addClass('vgr-hrow'data.i18n.class.headerrow)
:tag('th')
:wikitext(nameHeading)
:attr('scope', 'col')
:wikitext(nameHeading)
:done()
:tag('th')
:wikitext(data.i18n.score)
:attr('scope', 'col')
:wikitext(data.i18n.display.score)
:done()
end
 
local function renderRatingsBySystem(builder, code, name, activeSystems, args, na)
builder = builder:tag('tr'):addClass('vgr-ratings')
builder:tag('td')
:wikitext(name)
Line 140 ⟶ 127:
elseif na then
cell
:addClass('table-data.i18n.class.na')
:wikitext(data.i18n.display.na)
:done()
end
Line 148 ⟶ 135:
 
local function renderRating(builder, name, rating)
builder:tag('tr'):addClass('vgr-rating')
:tag('td')
:addClass(data.i18n.class.centeredpub)
:wikitext(name)
:done()
Line 157 ⟶ 145:
end
 
local function renderReviewsrenderAggregators(builder, providedReviewersprovidedAggregators, providedAggregatorsactiveSystems, customAggregatorKeys, args)
activeSystems, customAggregatorKeys, customReviewerKeys, args)
local aggregatorCount = #providedAggregators + #customAggregatorKeys
if aggregatorCount == 0 then return end
builder = builder:tag('table')
:addClass('vgr-reviews'data.i18n.class.aggregators)
:addClass(data.i18n.class.wikitable)
if args.state then builder:addClass('mw-collapsible-content') end
:addClass(args.state and 'mw-collapsible-content' or nil)
:tag('caption')
:wikitext(data.i18n.display[aggregatorCount == 1 and 'aggregateScore' or 'aggregateScores'])
: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
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: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('vgr-awards'data.i18n.class.reviews)
:addClass(data.i18n.class.wikitable)
:css('border-top', borderTop)
if :addClass(args.state thenand builder:addClass('mw-collapsible-content') endor nil)
:tag('caption')
:wikitext(data.i18n.display[reviewerCount == 1 and 'reviewScore' or 'reviewScores'])
:addClass(priorReviewCount > 0 and data.i18n.class.stacked or nil)
:done()
if #activeSystems ~= 0 then
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
renderMainHeading(builder, 2, data.i18n[#awardKeys == 1 and 'award' or 'awards'], borderTop)
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
else
renderHeadingRow(builder, data.i18n.display.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)
builder:tag('tr')
if #awardKeys == 0 then return end
:tag('th')
:wikitext(data.i18n.publication)
builder = builder:tag('table')
:attr('scope', 'col')
:addClass(data.i18n.class.awards)
:done()
:addClass(data.i18n.class.wikitable)
:tag('th')
:addClass(args.state and 'mw-collapsible-content' or nil)
:wikitext(data.i18n.award)
:attrtag('scope', 'colcaption')
: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
Line 255 ⟶ 258:
end
 
local function renderrenderEditOnWikidata(providedReviewersbuilder, providedAggregatorswikidata, awardKeys,state)
if not wikidata then return end
activeSystems, customAggregatorKeys, customReviewerKeys, args, wikidata)
local div = mw.html.create('div')
:addClass('video-game-reviews')
builder:tag('div')
if args.align then
:addClass(data.i18n.class.wikidata)
if args.align == 'left' then
div:addClass(state and 'vgrmw-leftcollapsible-content' or nil)
:wikitext(vgwd.getUpdateLink())
elseif args.align == 'none' then
:done()
div:addClass('vgr-none')
end
end
if #activeSystems == 0 then
div:addClass('vgr-single')
:css('width', args.width or nil)
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)
div
else
:addClass('mw-collapsible')
builder:wikitext(data.i18n.category.singleplatform)
if args.state == 'collapsed' then
div:addClass('mw-collapsed')
elseif args.state == 'autocollapse' or args.state == 'expanded' then
div:addClass(args.state)
end
end
end
 
local function renderTitles(builder, title, subtitle)
div:tag('div')
builder:tag('div')
:addClass('vgr-title')
:wikitextaddClass(args.title or data.i18n.receptionclass.title)
:wikitext(title or data.i18n.display.reception)
:done()
 
if args.subtitle then
divbuilder:tag('div')
:addClass('vgr-data.i18n.class.subtitle')
-- The only reason to use the subtitle is collapsible content
-- So always add the related class.
:addClass('mw-collapsible-content')
:wikitext(args.subtitle)
:done()
end
end
 
local function render(providedReviewers, providedAggregators, awardKeys,
renderReviews(
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)
 
local aggregatorCount = #providedAggregators + #customAggregatorKeys
renderAggregators(
div,
providedReviewers,
providedAggregators,
activeSystems,
customAggregatorKeys,
args,
aggregatorCount
)
local reviewerCount = #customReviewerKeys + #providedReviewers
renderReviews(
div,
providedReviewers,
activeSystems,
customReviewerKeys,
args,
reviewerCount,
aggregatorCount
)
renderAwards(
if #awardKeys ~= 0 then
div,
local borderTop =
args,
(#customAggregatorKeys ~= 0 or
awardKeys,
#customReviewerKeys ~= 0 or
reviewerCount + aggregatorCount
#providedAggregators ~= 0 or
)
#providedReviewers ~= 0
renderEditOnWikidata(div, wikidata, args.state)
) and 'none' or nil
categorizePlatformCount(div, #activeSystems)
renderAwards(
div,
args,
awardKeys,
borderTop
)
end
 
if wikidata == true then
div:tag('div')
:addClass('vgr-edit-on-wikidata')
-- TODO: I think getUpdateLink can be made const in the other module.
:wikitext(data.i18n.editOnWikidata .. vgwd.getUpdateLink('nosub'))
if args.state then div:addClass('mw-collapsible-content') end
end
 
return div
end
Line 337 ⟶ 345:
local function checkForWikidata(frame, args, activeSystems, providedAggregators)
local wikidata = false
if args.qid == 'none' then
return wikidata
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.
Line 402 ⟶ 414:
))
elseif mw.title.getCurrentTitle().namespace == 0 then
return data.i18n.emptyCategorycategory.empty
end
end
Line 410 ⟶ 422:
getArgs = require('Module:Arguments').getArgs
end
return p._reviewbox(frame, getArgs(frame,
{ wrappers = data.i18n.wrapper, trim = false, translate = data.argi18n }
))
end