Module:Wikidata/debug
-- Helper functions for debugging Wikidata data, do not use them on any article or template
local p = {}
-- Dump data tree structure
-- From pl:Module:Wikidane, by User:Paweł Ziemian
-- On any page associated with Wikidata, preview {{#invoke:Wikidata/debug|Dump}}. Do not save.
function p.Dump(frame)
local f = (frame.args[1] or frame.args.id) and frame or frame:getParent()
local data = mw.wikibase.getEntityObject(f.args.id)
if not data then
return
end
local i = 1
while true do
local index = f.args[i]
if not index then
return frame:extensionTag('syntaxhighlight', mw.dumpObject(data), {lang = 'json'})
end
data = data[index] or data[tonumber(index)]
if not data then
return
end
i = i + 1
end
end
-- Look into entity object
-- Add parameters as needed. Example: {{#invoke:Wikidata/debug|ViewSomething|claims|P17|1|mainsnak}}
function p.ViewSomething(frame)
local f = (frame.args[1] or frame.args.item) and frame or frame:getParent()
local id = f.args.item
if id and (#id == 0) then
id = nil
end
local data = mw.wikibase.getEntity(id)
if not data then
return nil
end
local i = 1
while true do
local index = f.args[i]
if not index then
if type(data) == "table" then
return frame:extensionTag('syntaxhighlight', mw.text.jsonEncode(data, mw.text.JSON_PRETTY), {lang = 'json'})
else
return tostring(data)
end
end
data = data[index] or data[tonumber(index)]
if not data then
return
end
i = i + 1
end
end
-- Look into entity object
-- From pl:Module:Wikidane, function V, by User:Paweł Ziemian
function p.getEntityFromTree(frame)
local data = mw.wikibase.getEntity()
if not data then
return nil
end
local f = frame.args[1] and frame or frame:getParent()
local i = 1
while true do
local index = f.args[i]
if not index then
return tostring(data)
end
data = data[index] or data[tonumber(index)]
if not data then
return
end
i = i + 1
end
end
-- helper function for debugging mw.wikibase.getAllStatements(id, P)
-- on debug console use: =p.ViewAllStatements({'Qid', 'Pid'})
function p.ViewAllStatements(frame)
local args = frame.args or frame -- from invoke or from debug console
local qid, pid
qid = mw.text.trim(args[1] or ""):upper()
if qid:sub(1,1) ~= "Q" then
pid = qid
qid = mw.wikibase.getEntityIdForCurrentPage()
else
pid = mw.text.trim(args[2] or ""):upper()
end
if not qid then return "Ítem no trobat" end
if pid:sub(1,1) ~= "P" then return "Cal una propietat" end
local statements = mw.wikibase.getAllStatements(qid, pid)
if args == frame then
return mw.dumpObject(statements)
else
return frame:extensionTag('syntaxhighlight', mw.text.jsonEncode(statements, mw.text.JSON_PRETTY), {lang = 'json'})
end
end
-- utility for tracking how the module is used
-- see documentation at [[wikt:en:Template:tracking]]
-- see your tracking at Special:WhatLinksHere/Template:track/wikidata/<your label>
function p.track(label)
local frame = mw.getCurrentFrame()
pcall(frame.expandTemplate, frame, {title = 'track/wikidata/' .. label})
end
-- Return fall back language codes
function p.getFallbacks(frame)
local args = frame.args or frame -- from invoke or from debug console
local lang = args[1] and mw.text.trim(args[1]) or mw.language.getContentLanguage().code
return table.concat(mw.language.getFallbacksFor(lang), ', ')
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.