Module:Wb/sandbox
Jump to navigation
Jump to search
| This is the module sandbox page for Module:Wb (diff). See also the companion subpage for test cases (run). |
Tests
Wb/testcases
success: 1, error: 0, skipped: 0
All tests passed.
| Name | Expected | Actual | |
|---|---|---|---|
| test_get_item |
Wb/sandbox/testcases
success: 1, error: 0, skipped: 0
All tests passed.
| Name | Expected | Actual | |
|---|---|---|---|
| test_get_item |
-- Wikibase utility functions
require("strict")
local languages = require("Module:Languages")
local p = {}
-- get entity across languages
function p.get_item()
local entity = mw.wikibase.getEntity()
local title = mw.title.getCurrentTitle()
if not entity and languages.languageFromTitle(title) ~= "en" then
local en_title = languages.sourceTitleFromTitle(title)
local qid = mw.wikibase.getEntityIdForTitle(en_title.fullText)
entity = mw.wikibase.getEntity(qid)
end
return entity
end
function p._debug_get_item()
local entity = p.get_item()
if not entity then return "Data item not found!" end
return entity:getId()
end
return p