-- only track if test or namespace=article or namespace=category
if not (qid or wp_ns == "" or wp_ns == "Category") then
return ""
end  
-- determine title and namespace of wikidata and wp article
local wikidata = nil
local consistent = nil
-- Tracking code works for all 4 cases of states of fetchGallery/Category
-- fetchGallery takes precedence
if fetchGallery then
wikidata, consistent = p._hasGalleryConsistent(qid)
if default or not fetchCategory or (consistent and wikidata) then
return selectTrackingCat(galleryTrackingCats,wikidata,consistent,
default,title)
end
end
if fetchCategory then
local cat_wikidata, cat_consistent = p._hasCategoryConsistent(qid,true)
if not fetchGallery or (cat_consistent and cat_wikidata) then
return selectTrackingCat(categoryTrackingCats,cat_wikidata,
cat_consistent,default,title)
end
return selectTrackingCat(galleryTrackingCats,wikidata,consistent,
default,title)
end
return "" -- nothing fetched, nothing tracked
end  
local function _createFormatting(args)
local formatting = {}
formatting.linktext = args.linktext
formatting.lcfirst = yesNo(args.lcfirst)
formatting.bold = yesNo(args.bold)
formatting.italic = yesNo(args.italic)
formatting.nowrap = yesNo(args.nowrap)
return formatting
end  
-- Testing-only entry point for _getTitleQID
function p.getTitleQID
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
local text, ns, qid = _getTitleQID(args[1],args[2])
return text..","..ns..","..(qid or "nil")
end  
-- Testing-only entry point for _lookupFallback
function p.lookupFallback
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
local fallback = _lookupFallback(args[1],args[2])
return fallback or "nil"
end  
-- Find the Commons gallery page associated with article
function p.getGallery
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._getCommons("",args[1],args.search,args.fallback,_createFormatting(args),args.qid)
end  
-- Find the Commons category page associated with article
function p.getCategory
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
local retval = p._getCommons("Category", args[1],
args.search, args.fallback, _createFormatting(args), args.qid
if args.tracking then
local default = nil
if args[1] then
default = "Category:"..args[1]
end
retval = retval..p._tracking(default, false, true, args.qid)
end
return retval
end  
function p.getGalleryOrCategory
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
local retval = p._getGalleryOrCategory(
args[1], args.search, args.fallback, _createFormatting(args), args.qid
if args.tracking then
retval = retval..p._tracking(args[1],true,true,args.qid)
end
return retval
end  
function p.hasGallery
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._hasGallery(args.qid) or ""
end  
function p.hasCategory
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._hasCategory(args.qid) or ""
end  
function p.hasGalleryOrCategory
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._hasGallery(args.qid) or p._hasCategory(args.qid) or ""
end  
function p.getGalleryAndCategory
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._getGalleryAndCategory(args[1], args[2],
args.categoryText, args.oneSearch, _createFormatting(args), args.qid)
end  
function p.tracking
local args = getArgs(,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._tracking(args[1], args.fetchGallery, args.fetchCategory, args.qid)
end  
return p