Module:EditAtWikidata: Difference between revisions
Appearance
m 1 revision imported |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| Line 25: | Line 16: | ||
local local_parm = trimToNil(args[1]) | local local_parm = trimToNil(args[1]) | ||
if local_parm then return "" end | if local_parm then return "" end | ||
-- | |||
-- Only access mw.wikibase if it exists | |||
local qid | |||
if qid and mw.wikibase.entityExists(qid) then | if mw and mw.wikibase and mw.wikibase.getEntityIdForCurrentPage then | ||
qid = trimToNil(args.qid) or mw.wikibase.getEntityIdForCurrentPage() | |||
else | |||
qid = trimToNil(args.qid) | |||
end | |||
-- Only check entity existence if mw.wikibase is available | |||
if qid and mw and mw.wikibase and mw.wikibase.entityExists and mw.wikibase.entityExists(qid) then | |||
local anchor = trimToNil(args.pid) | local anchor = trimToNil(args.pid) | ||
local space = trimToNil(args.nbsp) and " " or " " | local space = trimToNil(args.nbsp) and " " or " " | ||
return | return | ||
Revision as of 17:50, 30 May 2025
Documentation for this module may be created at Module:EditAtWikidata/doc
local p = {}
local i18n =
{
["message"] = "Edit this at Wikidata"
}
local function trimToNil(text)
-- Return trimmed non-empty text, or nil.
if type(text) == 'string' then
return text:match('(%S.-)%s*$')
end
end
function p._showMessage(args)
local local_parm = trimToNil(args[1])
if local_parm then return "" end
-- Only access mw.wikibase if it exists
local qid
if mw and mw.wikibase and mw.wikibase.getEntityIdForCurrentPage then
qid = trimToNil(args.qid) or mw.wikibase.getEntityIdForCurrentPage()
else
qid = trimToNil(args.qid)
end
-- Only check entity existence if mw.wikibase is available
if qid and mw and mw.wikibase and mw.wikibase.entityExists and mw.wikibase.entityExists(qid) then
local anchor = trimToNil(args.pid)
local space = trimToNil(args.nbsp) and " " or " "
return
space ..
"[[File:OOjs UI icon edit-ltr-progressive.svg|frameless|text-top|10px" ..
"|alt=" .. i18n.message ..
"|link=https://www.wikidata.org/wiki/" .. qid ..
(anchor and ("#" .. anchor) or "") ..
"|class=noprint" ..
"|" .. i18n.message ..
"]]"
end
return ""
end
function p.showMessage(frame)
return p._showMessage(frame.args)
end
return p