Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions lua/wikis/commons/Infobox/Extension/PatchAuto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

local Lua = require('Module:Lua')

local DateExt = Lua.import('Module:Date/Ext')
local Patch = Lua.import('Module:Patch')
local String = Lua.import('Module:StringUtils')

local TODAY = os.date('!%Y-%m-%d', os.time())
local Condition = Lua.import('Module:Condition')
local ConditionNode = Condition.Node
local Comparator = Condition.Comparator
local ColumnName = Condition.ColumnName

local PatchAuto = {}

Expand All @@ -23,15 +28,10 @@ function PatchAuto.run(data, args)
return PatchAuto._toData(data, patch or {}, endPatch or {})
end

local endDate = data.endDate or TODAY --[[@as string]]
local patches = mw.ext.LiquipediaDB.lpdb('datapoint', {
conditions = '[[type::patch]] AND ([[date::<' .. endDate .. ']] OR [[date::' .. endDate .. ']])',
query = 'name, pagename, date',
limit = 5000,
order = 'date desc',
})
patch = patch or PatchAuto._getPatch(patches, data.startDate)
endPatch = endPatch or PatchAuto._getPatch(patches, endDate)
local endDate = data.endDate or DateExt.toYmdInUtc(DateExt.getCurrentTimestamp())

patch = patch or PatchAuto._getPatch(data.startDate)
endPatch = endPatch or PatchAuto._getPatch(endDate)

return PatchAuto._toData(data, patch or {}, endPatch or {})
end
Expand All @@ -47,31 +47,23 @@ function PatchAuto._fetchPatchData(patch, patchDisplay)
return {link = patch, display = patchDisplay}
end

patch = patch:gsub(' ', '_')

local patchData = mw.ext.LiquipediaDB.lpdb('datapoint', {
conditions = '[[type::patch]] AND [[pagename::' .. patch .. ']]',
query = 'name',
local patchData = Patch.queryPatches{
additionalConditions = ConditionNode(ColumnName('pagename'), Comparator.eq, patch:gsub(' ', '_')),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to query this by pagename? I would have assumed that the patch input is a version? or am I wrong here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw stormgate is the only wiki taking advantage of this extension and they do use pagename as patch input for whatever reason
you are right on patch input being a version on most wikis but stormgate doesn't seem to be one of them ¯\_(ツ)_/¯

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bot fix this on stormgate and use versio number instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not against it, but they don't use a numeric system for patch either; see stormgate:Special:PrefixIndex/Patch
so I don't think it would be a straightforward bot job :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as version is unique you can use that, right?
and iirc they always have the version as last part of the pagename, so bot job should be able to just replace the input params, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and iirc they always have the version as last part of the pagename, so bot job should be able to just replace the input params, right?

oh right that does seem to be the pattern

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update SG Tournament Pages, or?

limit = 1
})[1]
}[1]

assert(patchData, '"' .. patch .. '" is not a valid patch')

patchDisplay = String.nilIfEmpty(patchData.name) or patch:gsub('_', ' ')
patchDisplay = String.nilIfEmpty(patchData.displayName) or patch
return {link = patch, display = patchDisplay}
end

---@param patches {pagename: string, name: string?, date: string}[]
---@param date string
---@return table
function PatchAuto._getPatch(patches, date)
for _, patch in ipairs(patches) do
if patch.date <= date then
return {link = patch.pagename, display = patch.name}
end
end
---@return {link: string?, display: string?}
function PatchAuto._getPatch(date)
local patch = Patch.getPatchByDate(date) or {}

return {}
return {link = patch.pageName, display = patch.displayName}
end

---@param data table
Expand Down
Loading