⚓ T305378 Add convenience function getBadges() to Lua
Page Menu
Phabricator
Create Task
Maniphest
T305378
Add convenience function getBadges() to Lua
Closed, Resolved
Public
5 Estimated Story Points
Feature
Actions
Edit Task
Edit Related Tasks...
Create Subtask
Edit Parent Tasks
Edit Subtasks
Merge Duplicates In
Close As Duplicate
Edit Related Objects...
Edit Commits
Edit Mocks
Mute Notifications
Protect as security issue
Assigned To
hoo
Authored By
Manuel
Apr 4 2022, 3:00 PM
2022-04-04 15:00:50 (UTC+0)
Tags
Wikidata
(incoming)
MediaWiki-extensions-Wikibase-Client
(Backlog)
Wikibase-Lua
(Incoming)
Wikidata-Campsite
(Unconnected Stories)
[Archived]Wikidata Dev Team (Sprint-∞)
(2023 completed tasks)
MW-1.40-notes (1.40.0-wmf.22; 2023-02-06)
Referenced Files
None
Subscribers
Agabi10
Aklapper
Arian_Bozorg
aude
ChristianKl
eranroz
hoo
View All 28 Subscribers
Description
Main components:
Wikibase-Lua
User story:
As a Wikipedia template editor / Lua programmer, I want to find the badges a specific Wikipedia article has using Lua in order to use it in my Lua module and template.
Problem:
Getting information about badges using Lua is currently possible, but it requires loading the whole entity. This is problematic in some items as it can cause Lua errors (e.g. needs too much memory).
Solution:
Add a Lua convenience function
getBadges
(similar to
getSitelink
).
See:
This would be run similarly to the 'getSitelink' i.e.
-- @param {string} itemId
-- @param {string} [globalSiteId]
function wikibase.getBadges( itemId, globalSiteId )
and the return value is a Lua table (with numeric indices), containing zero or more badges (identified by the corresponding badge QID).
The globalSiteID can remain empty and this will default to the local wiki.
BDD:
GIVEN a Wikipedia article
AND a Wikidata Item has sitelinks with badges for this article
WHEN a Lua 'getBadges' convenience function is run
THEN a Lua table with the QIDs of the badges is returned
Acceptance criteria:
A Lua 'getBadges' convenience function is available
mark the function as expensive, unless we can figure out a fast way to retrieve the badges
Wikibade: Lua page
is updated with the information on how the 'getBadges' convenience function will operate
Notes
For engineers, you need to have:
Scribunto extension
installed
configure at least one badge
Configure a Lua console to call this function
See
P43183
for example
LocalSettings.php
configurations
Original:
Details
Related Changes in Gerrit:
Subject
Repo
Branch
Lines +/-
Add getBadges convenience function to Lua
mediawiki/extensions/Wikibase
master
+236
-10
Update EntityUsage::SITELINK_USAGE's documentation
mediawiki/extensions/Wikibase
master
+4
-9
Customize query in gerrit
Related Objects
Search...
Task Graph
Mentions
Status
Subtype
Assigned
Task
Open
None
T182147
more convenience functions for Lua
Resolved
Feature
hoo
T305378
Add convenience function getBadges() to Lua
Mentioned In
T338942: Add a Lua function to get all sitelinks/ all badges
Mentioned Here
T179638: Property filter to reduce computing time of mw.wikibase.getEntity()
T338942: Add a Lua function to get all sitelinks/ all badges
P43183 Local configuration for badges and Lua
Event Timeline
Manuel
created this task.
Apr 4 2022, 3:00 PM
2022-04-04 15:00:50 (UTC+0)
Tacsipacsi
updated the task description.
(Show Details)
Apr 5 2022, 11:44 PM
2022-04-05 23:44:02 (UTC+0)
Tacsipacsi
subscribed.
Manuel
updated the task description.
(Show Details)
Apr 6 2022, 10:03 AM
2022-04-06 10:03:47 (UTC+0)
Comment Actions
This might be a nice hackathon project or something to get someone onboarded.
Manuel
added a comment.
Apr 6 2022, 10:16 AM
2022-04-06 10:16:57 (UTC+0)
This comment was removed by
Manuel
Zebulon84
subscribed.
Apr 8 2022, 4:10 PM
2022-04-08 16:10:04 (UTC+0)
Manuel
moved this task from
Incoming
to
Miscellaneous
on the
Wikidata-Campsite
board.
Jul 12 2022, 12:07 PM
2022-07-12 12:07:22 (UTC+0)
Tacsipacsi
updated the task description.
(Show Details)
Jul 13 2022, 5:58 PM
2022-07-13 17:58:46 (UTC+0)
Tacsipacsi
changed the subtype of this task from "Task" to "Feature Request".
Manuel
moved this task from
Miscellaneous
to
Unconnected Stories
on the
Wikidata-Campsite
board.
Aug 2 2022, 11:41 AM
2022-08-02 11:41:14 (UTC+0)
Lydia_Pintscher
added a project:
[Archived]Wikidata Dev Team
Dec 4 2022, 12:41 PM
2022-12-04 12:41:44 (UTC+0)
Lydia_Pintscher
moved this task from
Incoming
to
Product Backlog
on the
[Archived]Wikidata Dev Team
board.
Dec 4 2022, 12:47 PM
2022-12-04 12:47:14 (UTC+0)
karapayneWMDE
moved this task from
Product Backlog
to
SEND TO OMEGA BOARD. Will land in the 'incoming' column and need to be moved to the correct location (former Unified DOT Backlog)
on the
[Archived]Wikidata Dev Team
board.
Dec 7 2022, 10:37 AM
2022-12-07 10:37:33 (UTC+0)
karapayneWMDE
moved this task from
SEND TO OMEGA BOARD. Will land in the 'incoming' column and need to be moved to the correct location (former Unified DOT Backlog)
to
Product Backlog
on the
[Archived]Wikidata Dev Team
board.
Lydia_Pintscher
added a subscriber:
TomT0m
Dec 13 2022, 11:30 AM
2022-12-13 11:30:07 (UTC+0)
Comment Actions
Could one of the people who would like to have this please give an example of what the call and the return value would be for this?
Ghuron
unsubscribed.
Dec 13 2022, 12:01 PM
2022-12-13 12:01:01 (UTC+0)
Tacsipacsi
added a comment.
Dec 14 2022, 2:34 PM
2022-12-14 14:34:34 (UTC+0)
Comment Actions
I suppose the call could be exactly the same as for
getSitelink
, i.e.
-- @param {string} itemId
-- @param {string} [globalSiteId]
function
wikibase
getBadges
itemId
globalSiteId
and the return value could be a Lua table (with numeric indices), containing zero or more badges.
Arian_Bozorg
updated the task description.
(Show Details)
Jan 10 2023, 1:39 PM
2023-01-10 13:39:49 (UTC+0)
Arian_Bozorg
updated the task description.
(Show Details)
Jan 10 2023, 1:46 PM
2023-01-10 13:46:17 (UTC+0)
Arian_Bozorg
updated the task description.
(Show Details)
Jan 18 2023, 10:16 AM
2023-01-18 10:16:26 (UTC+0)
ItamarWMDE
updated the task description.
(Show Details)
Jan 18 2023, 10:21 AM
2023-01-18 10:21:49 (UTC+0)
ItamarWMDE
updated the task description.
(Show Details)
Lydia_Pintscher
moved this task from
Product Backlog
to
SEND TO OMEGA BOARD. Will land in the 'incoming' column and need to be moved to the correct location (former Unified DOT Backlog)
on the
[Archived]Wikidata Dev Team
board.
Jan 18 2023, 10:51 AM
2023-01-18 10:51:45 (UTC+0)
Michael
updated the task description.
(Show Details)
Jan 24 2023, 10:00 AM
2023-01-24 10:00:15 (UTC+0)
Michael
set the point value for this task to
Jan 24 2023, 10:02 AM
2023-01-24 10:02:57 (UTC+0)
Michael
moved this task from
SEND TO OMEGA BOARD. Will land in the 'incoming' column and need to be moved to the correct location (former Unified DOT Backlog)
to
Sprint-∞
on the
[Archived]Wikidata Dev Team
board.
Michael
edited projects, added
[Archived]Wikidata Dev Team (Sprint-∞)
; removed
[Archived]Wikidata Dev Team
hoo
claimed this task.
Jan 24 2023, 2:21 PM
2023-01-24 14:21:10 (UTC+0)
hoo
moved this task from
Parents/Waiting
to
Doing
on the
[Archived]Wikidata Dev Team (Sprint-∞)
board.
gerritbot
added a comment.
Jan 30 2023, 9:09 PM
2023-01-30 21:09:46 (UTC+0)
Comment Actions
Change 885034 had a related patch set uploaded (by Hoo man; author: Hoo man):
[mediawiki/extensions/Wikibase@master] Update EntityUsage::SITELINK_USAGE's documentation
gerritbot
added a project:
Patch-For-Review
Jan 30 2023, 9:09 PM
2023-01-30 21:09:47 (UTC+0)
gerritbot
added a comment.
Jan 30 2023, 9:26 PM
2023-01-30 21:26:32 (UTC+0)
Comment Actions
Change 885039 had a related patch set uploaded (by Hoo man; author: Hoo man):
[mediawiki/extensions/Wikibase@master] Add getBadges convenience function to Lua
hoo
moved this task from
Doing
to
Peer Review
on the
[Archived]Wikidata Dev Team (Sprint-∞)
board.
Jan 30 2023, 9:26 PM
2023-01-30 21:26:42 (UTC+0)
gerritbot
added a comment.
Jan 31 2023, 11:37 AM
2023-01-31 11:37:24 (UTC+0)
Comment Actions
Change 885034
merged
by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Update EntityUsage::SITELINK_USAGE's documentation
ReleaseTaggerBot
added a project:
MW-1.40-notes (1.40.0-wmf.22; 2023-02-06)
Jan 31 2023, 12:00 PM
2023-01-31 12:00:34 (UTC+0)
gerritbot
added a comment.
Jan 31 2023, 3:14 PM
2023-01-31 15:14:25 (UTC+0)
Comment Actions
Change 885039
merged
by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Add getBadges convenience function to Lua
Maintenance_bot
removed a project:
Patch-For-Review
Jan 31 2023, 3:31 PM
2023-01-31 15:31:39 (UTC+0)
Lucas_Werkmeister_WMDE
moved this task from
Peer Review
to
Product Verification
on the
[Archived]Wikidata Dev Team (Sprint-∞)
board.
Jan 31 2023, 4:17 PM
2023-01-31 16:17:18 (UTC+0)
Arian_Bozorg
closed this task as
Resolved
Jan 31 2023, 5:13 PM
2023-01-31 17:13:25 (UTC+0)
Arian_Bozorg
moved this task from
Product Verification
to
Our work done
on the
[Archived]Wikidata Dev Team (Sprint-∞)
board.
Arian_Bozorg
subscribed.
Comment Actions
This looks good to me :)
Thanks so much
karapayneWMDE
moved this task from
Our work done
to
2023 completed tasks
on the
[Archived]Wikidata Dev Team (Sprint-∞)
board.
Feb 6 2023, 4:28 PM
2023-02-06 16:28:34 (UTC+0)
Od1n
subscribed.
Edited
Mar 25 2023, 3:29 PM
2023-03-25 15:29:48 (UTC+0)
Comment Actions
We have an use case on French wiki, where we want a list of all foreign badges of a given article.
Previously, we were retrieving the whole entity, then we could iterate the
sitelinks
table. But retrieving the whole entity was eating a lot of memory (it was a bit slow too).
Thanks to this new
getBadges()
function, a new approach has been developed: we iterate a hardcoded list of wikis, and we call
getBadges()
for each of these. It uses a lot less memory (and it's a bit faster too). The downside with this approach is that we have to use a hardcoded list of wikis, whereas the previous approach was exhaustively retrieving the badges.
Here is the code change:
I thought about adding new functions like
getAllBadges()
or
getAllSitelinks()
, but that would introduce discrepancies with the existing functions:
if adding a
getAllBadges()
function, why not adding the same for
getSitelink()
but adding
getAllSitelinks()
(notice the singular/plural difference with
getSitelink()
) would be confusing, because we have the
sitelinks
table, but these functions retrieve
entity.sitelinks[globalSiteId].title
actually.
To avoid confusion, another solution could be to add a
getSitelinksTable()
function. The only downside is that it still would add a function to the API, and a function that returns a "raw" table (i.e. not directly the desired properties), though this table is quite straightforward.
hoo
mentioned this in
T338942: Add a Lua function to get all sitelinks/ all badges
Jun 13 2023, 11:39 AM
2023-06-13 11:39:46 (UTC+0)
hoo
added a comment.
Jun 13 2023, 12:04 PM
2023-06-13 12:04:55 (UTC+0)
Comment Actions
In
T305378#8726591
@Od1n
wrote:
We have an use case on French wiki, where we want a list of all foreign badges of a given article.

Thank you for your input, I have created a new task for that:
T338942: Add a Lua function to get all sitelinks/ all badges
Od1n
added a comment.
Nov 9 2024, 7:13 PM
2024-11-09 19:13:27 (UTC+0)
Comment Actions
Refs
T179638
, which is a more general application of the same principle (filtering properties to avoid loading the whole entity).
Log In to Comment
Content licensed under Creative Commons Attribution-ShareAlike (CC BY-SA) 4.0 unless otherwise noted; code licensed under GNU General Public License (GPL) 2.0 or later and other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct.
Wikimedia Foundation
Code of Conduct
Disclaimer
CC-BY-SA
GPL
Credits