Page MenuHomePhabricator

Get sitelink from Item without loading the full Item (via Lua).
Closed, ResolvedPublic

Description

Thanks to T75460 we now get the label in the use's language in a multilingual project. However, on Commons, in many, perhaps, most cases, the label should be accompanied by a link to Wikipedia. For instance, if we provide an artist name, we want a put a link to Wikipedia in the user's language. If we want to get the link, we need to load the item, which annihilate the gain provided by T75460. A dedicated mw.wikibase.getSiteLinkForSite( 'foobarwiki', 'optional entity id' ) would really come in handy here.

Event Timeline

Which Wikipedia would that link to? Also Wikibase doesn't know anything about Wikipedia, so such a function name wouldn't be possible.

I can imagine building something like mw.wikibase.getSiteLinksBySite( 'eswiki' ) or mw.wikibase.getSiteLinksBySiteGroup( 'wikipedia' ) based on a SiteLinkLookup.

hoo renamed this task from Get Wikipedia link without loading the full item on sister projects. to Get sitelink from Item without loading the full Item (via Lua)..Aug 13 2016, 12:47 PM

Maybe modify existing mw.wikibase.entity:getLabel(lang) (or write new mw.wikibase.entity:getLabel&Sitelink) so in addition to returning a label in the most relevant language, it would also returned a link to most relevant wikipedia. At the moment that is THE main use of Wikidata on Commons (we hope to write code or other uses) and it should be optimized. Calls to get label+sitelink in the user language are used in many templates which are then transcluded into great many files. A single file could have up to dozen such links.

Maybe modify existing mw.wikibase.entity:getLabel(lang) (or write new mw.wikibase.entity:getLabel&Sitelink) so in addition to returning a label in the most relevant language, it would also returned a link to most relevant wikipedia. At the moment that is THE main use of Wikidata on Commons (we hope to write code or other uses) and it should be optimized. Calls to get label+sitelink in the user language are used in many templates which are then transcluded into great many files. A single file could have up to dozen such links.

That sounds tough, as we don't really have data to decided which Wikipedia fits best when. Building a lookup for a specific site (Wikipedia) or site group is doable.

I guess we could also provide a lookup mw.wikibase.getSiteLinkForLanguage( 'wikipedia', 'optionalLanguageOrUserLang' ).

Current LUA implementation assumes that lua knows user language ( through call to int:lang) and gets all the sitelinks to wikipedia projects. It looks for sitelink in the chosen language and if not found than it look for sitelinks in fallback languages ending on English. If that one is not present either than it returns no link. This process is following functionality of Template:LangSwitch, which over the years was used 12 million times on Commons. However now Template:LangSwitch is applied to data pulled from wikidata. For example 3M calls to Template:City recently switched to calls to Wikidata using the above mechanism.

Thinking about this more, we could provide a mw.wikibase.getUserLanguageSitelink( entityId, 'wikipedia' )/mw.wikibase.entity:getUserLanguageSitelink( entityId, 'wikipedia' ) which would return the sitelink on the Wikipedia which has the user's language or nil if there's none. Implementing a fallback here for finding other potentially relevant Wikipedias would be possible (based on Language fallbacks), but I'm not sure that's very useful.

We could even make the second parameter (the site group, like "wikipedia") default to the languageLinkSiteGroup which is "wikipedia" in case of commons.

Fallback languages are essential for all Commons templates and Lua modules that serve them. Maybe we can have a function wikibase.getEntityWithoutProperties( id ) which works just like wikibase.getEntity( id ) but the output entity will not have any properties.

hoo triaged this task as High priority.Aug 13 2017, 3:30 PM

Optimal solution for me would be to modify mw.wikibase.sitelink to take optional second parameter wikibase.sitelink( id, globalSiteId ) , which would be the same as used by mw.wikibase.entity:getSitelink. Another approach could be to create a new function, perhaps mw.wikibase.sitelinks, which returns a table with all sitelinks. For Q79822 it would be { ["afwiki"]="Adam Mickiewicz", ["anwiki"]="Adam Mickiewicz", ...}

Optimal solution for me would be to modify mw.wikibase.sitelink to take optional second parameter wikibase.sitelink( id, globalSiteId ) , which would be the same as used by mw.wikibase.entity:getSitelink. Another approach could be to create a new function, perhaps mw.wikibase.sitelinks, which returns a table with all sitelinks. For Q79822 it would be { ["afwiki"]="Adam Mickiewicz", ["anwiki"]="Adam Mickiewicz", ...}

This is about the first case (getting one sitelink by global site id). If getting all sitelinks is needed as well, we can open another ticket for this… but I would rather not do this, unless it's really needed.

This is about the first case (getting one sitelink by global site id). If getting all sitelinks is needed as well, we can open another ticket for this… but I would rather not do this, unless it's really needed.

I was just presenting two alternative approaches that would work for me. Only one is needed to accomplish the task.

Change 382334 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/extensions/Wikibase@master] Allow getting the sitelink to an arbitrary site with mw.wikibase.sitelink

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

Change 382443 had a related patch set uploaded (by Thiemo Mättig (WMDE); owner: Thiemo Mättig (WMDE)):
[mediawiki/extensions/Wikibase@master] Cleanups and minor fixes for mw.wikibase.sitelink Lua function

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

thiemowmde claimed this task.
thiemowmde removed a project: Patch-For-Review.
thiemowmde moved this task from Review to Done on the Wikidata-Former-Sprint-Board board.

Change 382334 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Allow getting the sitelink to an arbitrary site with mw.wikibase.sitelink

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

Change 382443 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Cleanups and minor fixes for mw.wikibase.sitelink Lua function

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