1,068
edits
(Created page with "-- Module to find commons galleries and categories based on wikidata entries local getArgs = require('Module:Arguments').getArgs local p = {} -- Check if string is a valid QI...") |
No edit summary |
||
Line 45: | Line 45: | ||
local nsText = mw.ustring.gsub(titleObject.nsText,"_"," ") | local nsText = mw.ustring.gsub(titleObject.nsText,"_"," ") | ||
if not _validQID(qid) then | if not _validQID(qid) then | ||
return titleObject.text, nsText, qid | return titleObject.text, nsText, qid | ||
end | end | ||
Line 51: | Line 50: | ||
-- always use namespace from current page (to suppress tracking cat) | -- always use namespace from current page (to suppress tracking cat) | ||
qid = qid:upper() | qid = qid:upper() | ||
-- strip any namespace from sitelink | -- strip any namespace from sitelink | ||
local firstColon = mw.ustring.find(title,':',1,true) | local firstColon = mw.ustring.find(title,':',1,true) | ||
Line 82: | Line 80: | ||
local consistent = true | local consistent = true | ||
-- look up commons sitelink for article, use if not category | -- look up commons sitelink for article, use if not category | ||
if commonsSitelink and mw.ustring.sub(commonsSitelink,1,9) ~= "Category:" then | |||
galleryLink = commonsSitelink | galleryLink = commonsSitelink | ||
end | end | ||
-- P935 is the "commons gallery" property for this article | -- P935 is the "commons gallery" property for this article | ||
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 113: | Line 107: | ||
property = property:upper() | property = property:upper() | ||
-- If property exists on current article, get value (other article qid) | -- If property exists on current article, get value (other article qid) | ||
if value and value.mainsnak.datavalue and value.mainsnak.datavalue.value.id then | |||
-- Look up Commons sitelink of other article | -- Look up Commons sitelink of other article | ||
-- Check to see if it starts with "Category:". If so, strip it and return | |||
if sitelink and mw.ustring.sub(sitelink,1,9) == "Category:" then | if sitelink and mw.ustring.sub(sitelink,1,9) == "Category:" then | ||
return mw.ustring.sub(sitelink,10) | return mw.ustring.sub(sitelink,10) | ||
Line 142: | Line 134: | ||
local consistent = true | local consistent = true | ||
-- look up commons sitelink for article, use if starts with "Category:" | -- look up commons sitelink for article, use if starts with "Category:" | ||
if commonsSitelink and mw.ustring.sub(commonsSitelink,1,9) == "Category:" then | if commonsSitelink and mw.ustring.sub(commonsSitelink,1,9) == "Category:" then | ||
categoryLink = mw.ustring.sub(commonsSitelink,10) | categoryLink = mw.ustring.sub(commonsSitelink,10) | ||
end | end | ||
-- P373 is the "commons category" property for this article | -- P373 is the "commons category" property for this article | ||
if P373 and P373.mainsnak.datavalue then | |||
P373 = P373.mainsnak.datavalue.value | P373 = P373.mainsnak.datavalue.value | ||
if categoryLink and categoryLink ~= P373 then | if categoryLink and categoryLink ~= P373 then |
edits