Page MenuHomePhabricator

Create mw.wikibase.getDescriptionByLang
Closed, ResolvedPublic3 Estimated Story Points

Description

As a Lua module writer I want to access the description of an Item in a specific language in order to make use of it in my Lua module.

Problem:
According to the documentation at:
https://doc.wikimedia.org/Wikibase/master/php/docs_topics_lua.html
we currently have 'mw.wikibase.getLabelByLang' and 'mw.wikibase.getDescription' - but not 'mw.wikibase.getDescriptionByLang'.

That means one has to fetch the whole Item and parse it. This is an expensive operation.

Solution
Add a new 'mw.wikibase.getDescriptionByLang' convenience function similar to 'mw.wikibase.getLabelByLang'

An example call might look like this:

mw.wikibase.getDescriptionByLang( 'QID', 'lang' )

Returns the description of the Item as a string.

BDD
GIVEN Wikidata Item with a description in language X
WHEN a Lua 'getDescriptionByLang' convenience function is run for this Item in language X
THEN a Lua string with the description in the requested language is returned

Acceptance criteria:

Original report:
It would be useful to be able to use Lua to fetch a description given an input language, without having to fetch and parse the whole item. Ideally, this would also allow an option to use the fallback languages or not.

According to the documentation at:
https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua#mw.wikibase.getLabelByLang
we currently have mw.wikibase.getLabelByLang and mw.wikibase.getDescription - but not mw.wikibase.getDescriptionByLang.

For on-wiki discussion, see:
https://www.wikidata.org/w/index.php?title=Wikidata:Project_chat&oldid=999529340#Obtain_a_label_onwiki_in_a_specific_language

Note that the "WithLang" options aren't relevant here, as they just return the defined language, they don't let you select the language to use.

Related Objects

StatusSubtypeAssignedTask
InvalidNone
OpenNone
Resolvednoarave

Event Timeline

The priority for me would be to have mw.wikibase.getDescriptionByLang with no language fallback (the way that mw.wikibase.getLabelByLang already works). as we already have a request for that functionality.

It would be nice to have the option to switch language fallback on or off, but that's a secondary consideration at present.

Michael set the point value for this task to 3.Jan 24 2023, 9:55 AM
Michael moved this task from Unified DOT Backlog to Sprint-∞ on the Wikidata Dev Team board.

Task breakdown notes:

  • An easy way to test Lua changes on a local wiki is to use the Lua console that appears when editing a module page. The module page doesn’t need to actually exist, so you can just go to index.php?title=Module:Whatever&action=edit on your local wiki (once Scribunto is installed).
  • The new function can be added following the model of getLabelByLang (implementation, tests, documentation in docs/topics/lua.md).
  • No feature flag needed, this gets deployed with the train.

Change 883569 had a related patch set uploaded (by Noa wmde; author: Noa wmde):

[mediawiki/extensions/Wikibase@master] WIP Introduce mw.wikibase.getDescriptionByLang

https://gerrit.wikimedia.org/r/883569

Change 883569 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Introduce mw.wikibase.getDescriptionByLang

https://gerrit.wikimedia.org/r/883569

Change 885352 had a related patch set uploaded (by Hoo man; author: Hoo man):

[mediawiki/extensions/Wikibase@master] docs/topics/lua.md: Fix getDescriptionByLang example

https://gerrit.wikimedia.org/r/885352

Change 885352 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] docs/topics/lua.md: Fix getDescriptionByLang example

https://gerrit.wikimedia.org/r/885352

Arian_Bozorg subscribed.

Thanks everyone this looks all good to me :)