Page MenuHomePhabricator

Provide Lua function to check if an item is a redirect and what the target is
Closed, DuplicatePublic

Description

Some templates on Commons like for example https://commons.wikimedia.org/wiki/Creator:Jan_Ekels_%28II%29 link to Wikidata items. I merged the item this template is pointing to. I'm looking for a Lua function to check if a certain item (in this case "Q18516596") is a redirect and what the target item is (in this case "Q2450553"). Maybe this is already possible, but couldn't find it anywhere in the documentation.

Event Timeline

Multichill raised the priority of this task from to Low.
Multichill updated the task description. (Show Details)
Multichill added a subscriber: Multichill.

In theory it shouldn't matter which ID you access an item with. Can you elaborate what you need to know it for?

To find creator templates that point to a redirect so we can keep the data consistent.

Ricordisamoa renamed this task from Provide LUA function to check if an item is a redirect an what the target is to Provide Lua function to check if an item is a redirect and what the target is.Sep 23 2015, 8:40 PM
Ricordisamoa updated the task description. (Show Details)
Ricordisamoa added a subscriber: Ricordisamoa.

Workaround: mw.wikibase.getEntity() always returns the target entity with the new id. So you can do:

local id = ...
local entity = mw.wikibase.getEntity(id)
if id ~= entity.id then
    it's redirected
end

I verified that the solution proposed at T68974 for regular redirects also works with redirect items (and there's no reason it shouldn't)

Oddly enough, the id of that task is an anagram of this one's. I'd like to know how many times such a thing has happened.

Workaround: mw.wikibase.getEntity() always returns the target entity with the new id. So you can do:

local id = ...
local entity = mw.wikibase.getEntity(id)
if id ~= entity.id then
    it's redirected
end

Matej, workaround seems to solve the problem. Maybe we should document the way to check for redirects and close this task, or do we want to add short trivial function to mw.wikibase to do the test?

Opps the task is already closed after code change. If there is such a function than it should be documented at https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua