Module:Commons link: Difference between revisions
imported>Fire Created page with "require('strict') -- Module to find commons galleries and categories based on wikidata entries local getArgs = require('Module:Arguments').getArgs local yesNo = require('Module:Yesno') local generateWarning = require('Module:If preview')._warning local p = {} -- Check if string is a valid QID -- Argument: QID to check -- Returns: valid (bool) local function _validQID(qid) return qid and mw.ustring.find(qid,"^[Qq]%d+$") end -- Check if string is a valid wikidata prope..." |
No edit summary |
||
Line 106: | Line 106: | ||
end | end | ||
-- P935 is the "commons gallery" property for this article | -- P935 is the "commons gallery" property for this article | ||
local P935 = mw.wikibase.getBestStatements(qid, " | local P935 = mw.wikibase.getBestStatements(qid, "P193")[1] | ||
if P935 and P935.mainsnak.datavalue then | if P935 and P935.mainsnak.datavalue then | ||
local gallery = P935.mainsnak.datavalue.value | local gallery = P935.mainsnak.datavalue.value | ||
Line 166: | Line 166: | ||
end | end | ||
-- P910 is the "topic's main category". Look for commons sitelink there | -- P910 is the "topic's main category". Look for commons sitelink there | ||
local fallback = _lookupFallback(qid," | local fallback = _lookupFallback(qid,"P156") | ||
if fallback then | if fallback then | ||
if categoryLink and categoryLink ~= fallback then | if categoryLink and categoryLink ~= fallback then | ||
Line 188: | Line 188: | ||
-- a low-quality field, so should only be used as a last resort. | -- a low-quality field, so should only be used as a last resort. | ||
if categoryLink == nil and _validQID(qid) then | if categoryLink == nil and _validQID(qid) then | ||
local | local P107 = mw.wikibase.getBestStatements(qid, "P107")[1] | ||
if | if P107 and P107.mainsnak.datavalue then | ||
categoryLink = | categoryLink = P107.mainsnak.datavalue.value | ||
consistent = true -- P373 is never used if anything else is available | consistent = true -- P373->P107 is never used if anything else is available | ||
end | end | ||
end | end |