<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACommons_link</id>
	<title>Module:Commons link - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindpowe.red/wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACommons_link"/>
	<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Commons_link&amp;action=history"/>
	<updated>2026-04-06T05:13:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://mindpowe.red/wiki/index.php?title=Module:Commons_link&amp;diff=1763&amp;oldid=prev</id>
		<title>imported&gt;Hike395: fix bug</title>
		<link rel="alternate" type="text/html" href="https://mindpowe.red/wiki/index.php?title=Module:Commons_link&amp;diff=1763&amp;oldid=prev"/>
		<updated>2020-03-26T18:31:45Z</updated>

		<summary type="html">&lt;p&gt;fix bug&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Module to find commons galleries and categories based on wikidata entries&lt;br /&gt;
local getArgs = require('Module:Arguments').getArgs&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Check if string is a valid QID&lt;br /&gt;
-- Argument: QID to check&lt;br /&gt;
-- Returns: valid (bool)&lt;br /&gt;
local function _validQID(qid)&lt;br /&gt;
	return qid and mw.ustring.find(qid,&amp;quot;^[Qq]%d+$&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Check if string is a valid wikidata property string&lt;br /&gt;
-- Argument: property string to check&lt;br /&gt;
-- Returns: valid (bool)&lt;br /&gt;
local function _validProp(prop)&lt;br /&gt;
	return prop and mw.ustring.find(prop,&amp;quot;^[Pp]%d+$&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function _lcfirst(doit,s)&lt;br /&gt;
	if doit then&lt;br /&gt;
		return mw.ustring.lower(mw.ustring.sub(s,1,1))..mw.ustring.sub(s,2)&lt;br /&gt;
	end&lt;br /&gt;
	return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get title, namespace, and QID for current page&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   qid = testing only: get title of alternative page with QID=qid&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   title, namespace (number), qid of current page (or test page)&lt;br /&gt;
local function _getTitleQID(qid)&lt;br /&gt;
	local titleObject = mw.title.getCurrentTitle()&lt;br /&gt;
	-- look up qid for current page (if not testing)&lt;br /&gt;
	if not _validQID(qid) then&lt;br /&gt;
		qid = mw.wikibase.getEntityIdForCurrentPage()&lt;br /&gt;
		return titleObject.text, titleObject.namespace, qid&lt;br /&gt;
	end&lt;br /&gt;
	-- testing-only path: given a qid, determine title&lt;br /&gt;
	-- always use namespace from current page (to suppress tracking cat)&lt;br /&gt;
	qid = qid:upper()&lt;br /&gt;
	local title = mw.wikibase.getSitelink(qid) or &amp;quot;&amp;quot;&lt;br /&gt;
	-- strip any namespace from sitelink&lt;br /&gt;
	local firstColon = mw.ustring.find(title,':',1,true)&lt;br /&gt;
	if firstColon then&lt;br /&gt;
		title = mw.ustring.sub(title,firstColon+1)&lt;br /&gt;
	end&lt;br /&gt;
	return title, titleObject.namespace, qid&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Lookup Commons gallery in Wikidata&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   qid = QID of current article&lt;br /&gt;
--   fetch = whether to lookup Commons sitelink (bool)&lt;br /&gt;
--   commonsSitelink = default value for Commons sitelink&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   categoryLink = name of Commons category, nil if nothing is found&lt;br /&gt;
--   consistent = multiple wikidata fields are examined: are they consistent?&lt;br /&gt;
--   commonsSitelink = commons sitelink for current article&lt;br /&gt;
local function _lookupGallery(qid,fetch,commonsSitelink)&lt;br /&gt;
	if not _validQID(qid) then&lt;br /&gt;
		return nil, true, nil&lt;br /&gt;
	end&lt;br /&gt;
	qid = qid:upper()&lt;br /&gt;
	local galleryLink = nil&lt;br /&gt;
	local consistent = true&lt;br /&gt;
	-- look up commons sitelink for article, use if not category&lt;br /&gt;
	if fetch then&lt;br /&gt;
		commonsSitelink = mw.wikibase.getSitelink(qid,&amp;quot;commonswiki&amp;quot;) or commonsSitelink&lt;br /&gt;
	end&lt;br /&gt;
	if commonsSitelink and mw.ustring.sub(commonsSitelink,1,9) ~= &amp;quot;Category:&amp;quot; then&lt;br /&gt;
		galleryLink = commonsSitelink&lt;br /&gt;
	end&lt;br /&gt;
	-- P935 is the &amp;quot;commons gallery&amp;quot; property for this article&lt;br /&gt;
	local P935 = mw.wikibase.getBestStatements(qid, &amp;quot;P935&amp;quot;)[1]&lt;br /&gt;
	if P935 and P935.mainsnak.datavalue then&lt;br /&gt;
		local gallery = P935.mainsnak.datavalue.value&lt;br /&gt;
		if galleryLink and galleryLink ~= gallery then&lt;br /&gt;
			consistent = false&lt;br /&gt;
		else&lt;br /&gt;
			galleryLink = gallery&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return galleryLink, consistent, commonsSitelink&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find fallback category by looking up Commons sitelink of different page&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--    qid = QID for current article&lt;br /&gt;
--    property = property that refers to other article whose sitelink to return&lt;br /&gt;
-- Returns: either category-stripped name of article, or nil&lt;br /&gt;
local function _lookupFallback(qid,property)&lt;br /&gt;
	if not _validQID(qid) or not _validProp(property) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	qid = qid:upper()&lt;br /&gt;
	property = property:upper()&lt;br /&gt;
	-- If property exists on current article, get value (other article qid)&lt;br /&gt;
	local value = mw.wikibase.getBestStatements(qid, property)[1]&lt;br /&gt;
	if value and value.mainsnak.datavalue and value.mainsnak.datavalue.value.id then&lt;br /&gt;
		-- Look up Commons sitelink of other article&lt;br /&gt;
		local sitelink = mw.wikibase.getSitelink(value.mainsnak.datavalue.value.id,&amp;quot;commonswiki&amp;quot;)&lt;br /&gt;
		-- Check to see if it starts with &amp;quot;Category:&amp;quot;. If so, strip it and return&lt;br /&gt;
		if sitelink and mw.ustring.sub(sitelink,1,9) == &amp;quot;Category:&amp;quot; then&lt;br /&gt;
			return mw.ustring.sub(sitelink,10)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find Commons category by looking in wikidata&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   qid = QID of current article&lt;br /&gt;
--   fetch = whether to lookup Commons sitelink (bool)&lt;br /&gt;
--   commonsSitelink = default value for Commons sitelink&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   categoryLink = name of Commons category, nil if nothing is found&lt;br /&gt;
--   consistent = multiple wikidata fields are examined: are they consistent?&lt;br /&gt;
--   commonsSitelink = commons sitelink for current article&lt;br /&gt;
local function _lookupCategory(qid, fetch, commonsSitelink)&lt;br /&gt;
	if not _validQID(qid) then&lt;br /&gt;
		return nil, true, nil&lt;br /&gt;
	end&lt;br /&gt;
	qid = qid:upper()&lt;br /&gt;
	local categoryLink = nil&lt;br /&gt;
	local consistent = true&lt;br /&gt;
	-- look up commons sitelink for article, use if starts with &amp;quot;Category:&amp;quot;&lt;br /&gt;
	if fetch then&lt;br /&gt;
		commonsSitelink = mw.wikibase.getSitelink(qid,&amp;quot;commonswiki&amp;quot;) or commonsSitelink&lt;br /&gt;
	end&lt;br /&gt;
	if commonsSitelink and mw.ustring.sub(commonsSitelink,1,9) == &amp;quot;Category:&amp;quot; then&lt;br /&gt;
		categoryLink = mw.ustring.sub(commonsSitelink,10)&lt;br /&gt;
	end&lt;br /&gt;
	-- P373 is the &amp;quot;commons category&amp;quot; property for this article&lt;br /&gt;
	local P373 = mw.wikibase.getBestStatements(qid, &amp;quot;P373&amp;quot;)[1]&lt;br /&gt;
	if P373 and P373.mainsnak.datavalue then&lt;br /&gt;
		P373 = P373.mainsnak.datavalue.value&lt;br /&gt;
		if categoryLink and categoryLink ~= P373 then&lt;br /&gt;
			consistent = false&lt;br /&gt;
			qid = nil  -- stop searching on inconsistent data&lt;br /&gt;
		else&lt;br /&gt;
			categoryLink = P373&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- P910 is the &amp;quot;topic's main category&amp;quot;. Look for commons sitelink there&lt;br /&gt;
	local fallback = _lookupFallback(qid,&amp;quot;P910&amp;quot;)&lt;br /&gt;
	if fallback then&lt;br /&gt;
		if categoryLink and categoryLink ~= fallback then&lt;br /&gt;
			consistent = false&lt;br /&gt;
			qid = nil&lt;br /&gt;
		else&lt;br /&gt;
			categoryLink = fallback&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- P1754 is the &amp;quot;list's main category&amp;quot;. Look for commons sitelink there&lt;br /&gt;
	fallback = _lookupFallback(qid,&amp;quot;P1754&amp;quot;)&lt;br /&gt;
	if fallback then&lt;br /&gt;
		if categoryLink and categoryLink ~= fallback then&lt;br /&gt;
			consistent = false&lt;br /&gt;
		else&lt;br /&gt;
			categoryLink = fallback&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return categoryLink, consistent, commonsSitelink&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Does the article have a corresponding Commons gallery?&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   qid = QID to lookup in wikidata (for testing only)&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   filename at Commons if so, nil if not&lt;br /&gt;
function p._hasGallery(qid)&lt;br /&gt;
	local wp_title, wp_ns&lt;br /&gt;
	wp_title, wp_ns, qid = _getTitleQID(qid)&lt;br /&gt;
	local galleryLink, consistent = _lookupGallery(qid,true)&lt;br /&gt;
	if galleryLink and consistent then&lt;br /&gt;
		return galleryLink&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Does the article have a corresponding Commons category?&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   qid = QID to lookup in wikidata (for testing only)&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   filename at Commons if so, blank if not&lt;br /&gt;
function p._hasCategory(qid)&lt;br /&gt;
	local wp_title, wp_ns&lt;br /&gt;
	wp_title, wp_ns, qid = _getTitleQID(qid)&lt;br /&gt;
	local categoryLink, consistent = _lookupCategory(qid,true)&lt;br /&gt;
	if categoryLink and consistent then&lt;br /&gt;
		return &amp;quot;Category:&amp;quot;..categoryLink&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Create Commons link corresponding to current article&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   namespace = namespace in Commons (&amp;quot;&amp;quot; for galleries)&lt;br /&gt;
--   default = use as Commons link, don't access wikidata&lt;br /&gt;
--   linktext = text to display in link&lt;br /&gt;
--   search = string to search for&lt;br /&gt;
--   lcfirst = lower case the first letter in linktext&lt;br /&gt;
--   qid = QID to lookup in wikidata (for testing only)&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   formatted wikilink to Commons in specified namespace&lt;br /&gt;
function p._getCommons(namespace,default,linktext,search,lcfirst,qid)&lt;br /&gt;
	local nsColon&lt;br /&gt;
	if not namespace or namespace == &amp;quot;&amp;quot; then&lt;br /&gt;
		nsColon = &amp;quot;&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		nsColon = namespace..&amp;quot;:&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	if default then&lt;br /&gt;
		return &amp;quot;[[Commons:&amp;quot;..nsColon..default..&amp;quot;|&amp;quot;.._lcfirst(lcfirst,linktext or default)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	if search then&lt;br /&gt;
		return &amp;quot;[[Commons:Special:Search/&amp;quot;..nsColon..search..&amp;quot;|&amp;quot;.._lcfirst(lcfirst,linktext or search)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	local wp_title, wp_ns&lt;br /&gt;
	wp_title, wp_ns, qid = _getTitleQID(qid)&lt;br /&gt;
	-- construct default result (which searches for title)&lt;br /&gt;
	local searchResult = &amp;quot;[[Commons:Special:Search/&amp;quot;..nsColon..wp_title..&amp;quot;|&amp;quot;.._lcfirst(lcfirst,linktext or wp_title)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	local commonsLink = nil&lt;br /&gt;
	local consistent = true&lt;br /&gt;
	if nsColon == &amp;quot;&amp;quot; then&lt;br /&gt;
		commonsLink, consistent = _lookupGallery(qid,true)&lt;br /&gt;
	elseif namespace:lower() == &amp;quot;category&amp;quot; then&lt;br /&gt;
		commonsLink, consistent = _lookupCategory(qid,true)&lt;br /&gt;
	end&lt;br /&gt;
	-- use wikidata if consistent&lt;br /&gt;
	if commonsLink and consistent then&lt;br /&gt;
		return &amp;quot;[[Commons:&amp;quot;..nsColon..commonsLink..&amp;quot;|&amp;quot;.._lcfirst(lcfirst,linktext or commonsLink)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	-- if not consistent, fall back to search and add to tracking cat&lt;br /&gt;
	if not consistent and wp_ns == 0 then&lt;br /&gt;
		local friendlyNS&lt;br /&gt;
		if nsColon == &amp;quot;&amp;quot; then&lt;br /&gt;
			friendlyNS = &amp;quot;gallery&amp;quot;&lt;br /&gt;
		else&lt;br /&gt;
			friendlyNS = namespace:lower()&lt;br /&gt;
		end&lt;br /&gt;
		searchResult = searchResult..&amp;quot;[[Category:Inconsistent wikidata for Commons &amp;quot;..friendlyNS..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	return searchResult&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Returns &amp;quot;best&amp;quot; Commons link: first look for gallery, then try category&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   default = use as Commons link, don't access wikidata&lt;br /&gt;
--   linktext = text to display in link&lt;br /&gt;
--   search = string to search for&lt;br /&gt;
--   qid = QID to lookup in wikidata (for testing only)&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   formatted wikilink to Commons &amp;quot;best&amp;quot; landing page&lt;br /&gt;
function p._getGalleryOrCategory(default,linktext,search,qid)&lt;br /&gt;
	if default then&lt;br /&gt;
		return &amp;quot;[[Commons:&amp;quot;..default..&amp;quot;|&amp;quot;..(linktext or default)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	if search then&lt;br /&gt;
		return &amp;quot;[[Commons:Special:Search/&amp;quot;..search..&amp;quot;|&amp;quot;..(linktext or search)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	local wp_title, wp_ns&lt;br /&gt;
	wp_title, wp_ns, qid = _getTitleQID(qid)&lt;br /&gt;
	-- construct default result (which searches for title)&lt;br /&gt;
	local searchResult = &amp;quot;[[Commons:Special:Search/&amp;quot;..wp_title..&amp;quot;|&amp;quot;..(linktext or wp_title)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	local trackingCats = &amp;quot;&amp;quot;&lt;br /&gt;
	local galleryLink, consistent, commonsSitelink = _lookupGallery(qid,true)&lt;br /&gt;
	-- use wikidata if either sitelink or P935 exist, and they both agree&lt;br /&gt;
	if galleryLink and consistent then&lt;br /&gt;
		return &amp;quot;[[Commons:&amp;quot;..galleryLink..&amp;quot;|&amp;quot;..(linktext or galleryLink)..&amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	if not consistent and wp_ns == 0 then&lt;br /&gt;
		trackingCats = &amp;quot;[[Category:Inconsistent wikidata for Commons gallery]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	-- if gallery is not good, fall back looking for category&lt;br /&gt;
	local categoryLink&lt;br /&gt;
	categoryLink, consistent = _lookupCategory(qid,false,commonsSitelink)&lt;br /&gt;
	if categoryLink and consistent then&lt;br /&gt;
		return &amp;quot;[[Commons:Category:&amp;quot;..categoryLink..&amp;quot;|&amp;quot;..(linktext or categoryLink)..&amp;quot;]]&amp;quot;..trackingCats&lt;br /&gt;
	end&lt;br /&gt;
	if not consistent and wp_ns == 0 then&lt;br /&gt;
		trackingCats = trackingCats..&amp;quot;[[Category:Inconsistent wikidata for Commons category]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	return searchResult..trackingCats&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Make a string bold, italic, or both&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   s = string to format&lt;br /&gt;
--   bold = make it bold&lt;br /&gt;
--   italic = make it italic&lt;br /&gt;
-- Returns:&lt;br /&gt;
--   string modified with html tags&lt;br /&gt;
local function _formatResult(s,bold,italic)&lt;br /&gt;
	local resultVal = &amp;quot;&amp;quot;&lt;br /&gt;
	if bold then resultVal = &amp;quot;&amp;lt;b&amp;gt;&amp;quot; end&lt;br /&gt;
	if italic then resultVal = resultVal..&amp;quot;&amp;lt;i&amp;gt;&amp;quot; end&lt;br /&gt;
	resultVal = resultVal..s&lt;br /&gt;
	if italic then resultVal = resultVal..&amp;quot;&amp;lt;/i&amp;gt;&amp;quot; end&lt;br /&gt;
	if bold then resultVal = resultVal..&amp;quot;&amp;lt;/b&amp;gt;&amp;quot; end&lt;br /&gt;
	return resultVal&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Return link(s) Commons gallery, or category, or both from wikidata&lt;br /&gt;
-- Arguments:&lt;br /&gt;
--   defaultGallery = default gallery link to use, instead of wikidata&lt;br /&gt;
--   defaultCategory = default category link to use, instead of wikidata&lt;br /&gt;
--   categoryText = if both gallery and category, text to use in category link (&amp;quot;category&amp;quot; by default)&lt;br /&gt;
--   bold = whether to make first link bold&lt;br /&gt;
--   italic = whether to make first link italic&lt;br /&gt;
--   qid = qid of page to lookup in wikidata (testing only)&lt;br /&gt;
function p._getGalleryAndCategory(defaultGallery,defaultCategory,linkText,categoryText,bold,italic,oneSearch,qid)&lt;br /&gt;
	local wp_title, wp_ns&lt;br /&gt;
	wp_title, wp_ns, qid = _getTitleQID(qid)&lt;br /&gt;
	categoryText = categoryText or &amp;quot;category&amp;quot;&lt;br /&gt;
	-- construct default result (which searches for title)&lt;br /&gt;
	local searchResult = _formatResult(&amp;quot;[[Commons:Special:Search/&amp;quot;..wp_title..&amp;quot;|&amp;quot;..(linkText or wp_title)..&amp;quot;]]&amp;quot;,bold,italic)&lt;br /&gt;
	if not oneSearch then&lt;br /&gt;
		searchResult = searchResult..&amp;quot; ([[Commons:Special:Search/Category:&amp;quot;..wp_title..&amp;quot;|&amp;quot;..categoryText..&amp;quot;]])&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	local trackingCats = &amp;quot;&amp;quot;&lt;br /&gt;
	local galleryLink, galleryConsistent&lt;br /&gt;
	local commonsSitelink = nil&lt;br /&gt;
	if defaultGallery then&lt;br /&gt;
		galleryLink = defaultGallery&lt;br /&gt;
		galleryConsistent = true&lt;br /&gt;
	else&lt;br /&gt;
		galleryLink, galleryConsistent, commonsSitelink = _lookupGallery(qid,true)&lt;br /&gt;
	end&lt;br /&gt;
	local galleryGood = galleryLink and galleryConsistent&lt;br /&gt;
	if not galleryConsistent and wp_ns == 0 then&lt;br /&gt;
		trackingCats = &amp;quot;[[Category:Inconsistent wikidata for Commons gallery]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	local categoryLink, categoryConsistent&lt;br /&gt;
	if defaultCategory then&lt;br /&gt;
		categoryLink = defaultCategory&lt;br /&gt;
		categoryConsistent = true&lt;br /&gt;
	else&lt;br /&gt;
		categoryLink, categoryConsistent = _lookupCategory(qid,defaultGallery,commonsSitelink)&lt;br /&gt;
	end&lt;br /&gt;
	local categoryGood = categoryLink and categoryConsistent&lt;br /&gt;
	if not categoryConsistent and wp_ns == 0 then&lt;br /&gt;
		trackingCats = trackingCats..&amp;quot;[[Category:Inconsistent wikidata for Commons category]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	local firstLink&lt;br /&gt;
	if galleryGood then&lt;br /&gt;
		firstLink = galleryLink&lt;br /&gt;
		linkText = linkText or galleryLink&lt;br /&gt;
	elseif categoryGood then&lt;br /&gt;
		firstLink = &amp;quot;Category:&amp;quot;..categoryLink&lt;br /&gt;
		linkText = linkText or categoryLink&lt;br /&gt;
	else&lt;br /&gt;
		return searchResult..trackingCats&lt;br /&gt;
	end&lt;br /&gt;
	local resultVal = _formatResult(&amp;quot;[[Commons:&amp;quot;..firstLink..&amp;quot;|&amp;quot;..linkText..&amp;quot;]]&amp;quot;,bold,italic)&lt;br /&gt;
	if galleryGood and categoryGood then&lt;br /&gt;
		resultVal = resultVal..&amp;quot; ([[Commons:Category:&amp;quot;..categoryLink..&amp;quot;|&amp;quot;..categoryText..&amp;quot;]])&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	return resultVal..trackingCats&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Testing-only entry point for _getTitleQID&lt;br /&gt;
function p.getTitleQID(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	local text, ns, qid = _getTitleQID(args[1])&lt;br /&gt;
	return text..&amp;quot;,&amp;quot;..ns..&amp;quot;,&amp;quot;..(qid or &amp;quot;nil&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Testing-only entry point for _lookupFallback&lt;br /&gt;
function p.lookupFallback(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	local fallback = _lookupFallback(args[1],args[2])&lt;br /&gt;
	return fallback or &amp;quot;nil&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find the Commons gallery page associated with article&lt;br /&gt;
function p.getGallery(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._getCommons(&amp;quot;&amp;quot;,args[1],args.linktext,args.search,args.lcfirst,args.qid)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Find the Commons category page associated with article&lt;br /&gt;
function p.getCategory(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._getCommons(&amp;quot;Category&amp;quot;,args[1],args.linktext,args.search,args.lcfirst,args.qid)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.getGalleryOrCategory(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._getGalleryOrCategory(args[1],args.linktext,args.search,args.qid)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.hasGallery(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._hasGallery(args.qid) or &amp;quot;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.hasCategory(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._hasCategory(args.qid) or &amp;quot;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.hasGalleryOrCategory(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._hasGallery(args.qid) or p._hasCategory(args.qid) or &amp;quot;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.getGalleryAndCategory(frame)&lt;br /&gt;
	local args = getArgs(frame,{frameOnly=true,parentOnly=false,parentFirst=false})&lt;br /&gt;
	return p._getGalleryAndCategory(args[1],args[2],args.linktext,args.categoryText,&lt;br /&gt;
		args.bold,args.italic,args.oneSearch,args.qid)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Hike395</name></author>
		
	</entry>
</feed>