Skip to content

Commit

Permalink
feat: pagify links in ExternalMediaLink storage (#5108)
Browse files Browse the repository at this point in the history
* Update external_media_link.lua

* Query for pagenames with and without underscores

* Linelength
  • Loading branch information
mbergen authored Nov 21, 2024
1 parent 1166cf8 commit 15da217
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 4 additions & 5 deletions components/external_media_links/external_media_link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ function ExternalMediaLink._store(args)

local authors = {}
for _, author, authorIndex in Table.iter.pairsByPrefix(args, 'by') do
authors['author' .. authorIndex] =
mw.ext.TeamLiquidIntegration.resolve_redirect(args['by_link' .. authorIndex] or author)
authors['author' .. authorIndex] = Page.pageifyLink(args['by_link' .. authorIndex] or author)
authors['author' .. authorIndex .. 'dn'] = author
end
-- set a maximum for authors due to the same being used in queries
Expand All @@ -87,23 +86,23 @@ function ExternalMediaLink._store(args)
translation = args.translation,
translator = args.translator,
event = args.event,
event_link = mw.ext.TeamLiquidIntegration.resolve_redirect(
event_link = Page.pageifyLink(
Logic.emptyOr(args['event-link'], args.event) or ''
),
subject_organization = args.subject_organization1, --legacy
}

local orgs = {}
for _, org, orgIndex in Table.iter.pairsByPrefix(args, 'subject_organization') do
orgs['subject_organization' .. orgIndex] = mw.ext.TeamLiquidIntegration.resolve_redirect(org)
orgs['subject_organization' .. orgIndex] = Page.pageifyLink(org)
end
-- set a maximum for orgs due to the same being used in queries
assert(Table.size(orgs) <= MAXIMUM_VALUES.organisations,
'Maximum Value of organisations subjects (' .. MAXIMUM_VALUES.organisations .. ') exceeded')

local subjects = {}
for _, subject, subjectIndex in Table.iter.pairsByPrefix(args, 'subject') do
subjects['subject' .. subjectIndex] = mw.ext.TeamLiquidIntegration.resolve_redirect(subject)
subjects['subject' .. subjectIndex] = Page.pageifyLink(subject)
end
-- set a maximum for subjects due to the same being used in queries
assert(Table.size(subjects) <= MAXIMUM_VALUES.subjects,
Expand Down
24 changes: 20 additions & 4 deletions components/external_media_links/external_media_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,30 @@ function MediaList._buildConditions(args)
end

if args.org then
table.insert(additionalConditions, '[[extradata_subject_organization::' .. args.org .. ']]')
table.insert(additionalConditions, MediaList._buildMultiKeyCondition(args.org, 'extradata_subject_organization', 5))
table.insert(
additionalConditions,
'([[extradata_subject_organization::'
.. args.org
']] OR [[extradata_subject_organization::'
.. args.org:gsub(' ', '_')
.. ']])'
)
table.insert(additionalConditions, MediaList._buildMultiKeyCondition(args.org, 'extraata_subject_organization', 5))
end

if args.author then
table.insert(additionalConditions, MediaList._buildMultiKeyCondition(args.author, 'authors_author', 5))
end

if args.event then
table.insert(additionalConditions, '[[extradata_event_link::' .. args.event .. ']]')
table.insert(
additionalConditions,
'([[extradata_event_link::'
.. args.event
.. ']] OR [[extradata_event_link::'
.. args.event:gsub(' ', '_')
.. ']])'
)
end

if Logic.isNotEmpty(additionalConditions) then
Expand All @@ -125,14 +139,16 @@ function MediaList._buildConditions(args)

return table.concat(conditions, ' AND ')
end

---Builds a multi key condition for a given prefix and value
---@param value string|number
---@param prefix string
---@param limit integer
---@return string
function MediaList._buildMultiKeyCondition(value, prefix, limit)
return table.concat(Array.map(Array.range(1, limit), function(index)
return '[[' .. prefix .. index .. '::' .. value .. ']]'
return '([[' .. prefix .. index .. '::' .. value .. ']]'
.. ' OR [['.. prefix .. index .. '::' .. value:gsub(' ', '_') .. ']])'
end), ' OR ')
end

Expand Down

0 comments on commit 15da217

Please sign in to comment.