Open main menu

Changes

Module:Commons link

225 bytes added, 06:41, 14 December 2020
add fallback parameter
-- linktext = text to display in link
-- search = string to search for
-- fallback = string to search for if wikidata fails
-- lcfirst = lower case the first letter in linktext
-- qid = QID to lookup in wikidata (for testing only)
-- Returns:
-- formatted wikilink to Commons in specified namespace
function p._getCommons(namespace,default,linktext,search,fallback,lcfirst,qid)
local nsColon
if not namespace or namespace == "" then
wp_title, wp_ns, qid = _getTitleQID(qid)
-- construct default result (which searches for title)
local searchResult = "[[Commons:Special:Search/"..nsColon..(fallback or wp_title) searchResult = searchResult.."|".._lcfirst(lcfirst,linktext or fallback or wp_title).."]]"
local commonsLink = nil
local consistent = true
-- Returns:
-- formatted wikilink to Commons "best" landing page
function p._getGalleryOrCategory(default,linktext,search,fallback,qid)
if default then
return "[[Commons:"..default.."|"..(linktext or default).."]]"
wp_title, wp_ns, qid = _getTitleQID(qid)
-- construct default result (which searches for title)
local searchResult = "[[Commons:Special:Search/"..(fallback or wp_title) searchResult = searchResult.."|"..(linktext or fallback or wp_title).."]]"
local trackingCats = ""
local galleryLink, consistent, commonsSitelink = _lookupGallery(qid,true)
function p.getGallery(frame)
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})
return p._getCommons("",args[1],args.linktext,args.search,args.fallback,args.lcfirst,args.qid)
end
function p.getCategory(frame)
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})
local retval = p._getCommons("Category",args[1],args.linktext,args.search,args.fallback,args.lcfirst,args.qid)
if args.tracking then
local default = nil
function p.getGalleryOrCategory(frame)
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})
local retval = p._getGalleryOrCategory(args[1],args.linktext,args.search,args.fallback,args.qid)
if args.tracking then
retval = retval..p._tracking(args[1],true,true,args.qid)
Anonymous user