Module:Commons link: Difference between revisions
Richardpruen (talk | contribs) m 1 revision imported: Wikipedia article on Nicotine templates needed |
add fallback parameter |
||
Line 224: | Line 224: | ||
-- linktext = text to display in link | -- linktext = text to display in link | ||
-- search = string to search for | -- search = string to search for | ||
-- fallback = string to search for if wikidata fails | |||
-- lcfirst = lower case the first letter in linktext | -- lcfirst = lower case the first letter in linktext | ||
-- qid = QID to lookup in wikidata (for testing only) | -- qid = QID to lookup in wikidata (for testing only) | ||
-- Returns: | -- Returns: | ||
-- formatted wikilink to Commons in specified namespace | -- formatted wikilink to Commons in specified namespace | ||
function p._getCommons(namespace,default,linktext,search,lcfirst,qid) | function p._getCommons(namespace,default,linktext,search,fallback,lcfirst,qid) | ||
local nsColon | local nsColon | ||
if not namespace or namespace == "" then | if not namespace or namespace == "" then | ||
Line 244: | Line 245: | ||
wp_title, wp_ns, qid = _getTitleQID(qid) | wp_title, wp_ns, qid = _getTitleQID(qid) | ||
-- construct default result (which searches for title) | -- construct default result (which searches for title) | ||
local searchResult = "[[Commons:Special:Search/"..nsColon..wp_title.."|".._lcfirst(lcfirst,linktext or wp_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 commonsLink = nil | ||
local consistent = true | local consistent = true | ||
Line 277: | Line 279: | ||
-- Returns: | -- Returns: | ||
-- formatted wikilink to Commons "best" landing page | -- formatted wikilink to Commons "best" landing page | ||
function p._getGalleryOrCategory(default,linktext,search,qid) | function p._getGalleryOrCategory(default,linktext,search,fallback,qid) | ||
if default then | if default then | ||
return "[[Commons:"..default.."|"..(linktext or default).."]]" | return "[[Commons:"..default.."|"..(linktext or default).."]]" | ||
Line 287: | Line 289: | ||
wp_title, wp_ns, qid = _getTitleQID(qid) | wp_title, wp_ns, qid = _getTitleQID(qid) | ||
-- construct default result (which searches for title) | -- construct default result (which searches for title) | ||
local searchResult = "[[Commons:Special:Search/"..wp_title.."|"..(linktext or wp_title).."]]" | local searchResult = "[[Commons:Special:Search/"..(fallback or wp_title) | ||
searchResult = searchResult.."|"..(linktext or fallback or wp_title).."]]" | |||
local trackingCats = "" | local trackingCats = "" | ||
local galleryLink, consistent, commonsSitelink = _lookupGallery(qid,true) | local galleryLink, consistent, commonsSitelink = _lookupGallery(qid,true) | ||
Line 469: | Line 472: | ||
function p.getGallery(frame) | function p.getGallery(frame) | ||
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | ||
return p._getCommons("",args[1],args.linktext,args.search,args.lcfirst,args.qid) | return p._getCommons("",args[1],args.linktext,args.search,args.fallback,args.lcfirst,args.qid) | ||
end | end | ||
Line 475: | Line 478: | ||
function p.getCategory(frame) | function p.getCategory(frame) | ||
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | ||
local retval = p._getCommons("Category",args[1],args.linktext,args.search,args.lcfirst,args.qid) | local retval = p._getCommons("Category",args[1],args.linktext,args.search,args.fallback,args.lcfirst,args.qid) | ||
if args.tracking then | if args.tracking then | ||
local default = nil | local default = nil | ||
Line 488: | Line 491: | ||
function p.getGalleryOrCategory(frame) | function p.getGalleryOrCategory(frame) | ||
local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false}) | ||
local retval = p._getGalleryOrCategory(args[1],args.linktext,args.search,args.qid) | local retval = p._getGalleryOrCategory(args[1],args.linktext,args.search,args.fallback,args.qid) | ||
if args.tracking then | if args.tracking then | ||
retval = retval..p._tracking(args[1],true,true,args.qid) | retval = retval..p._tracking(args[1],true,true,args.qid) |