 module tou800 find commons galleries andu800 categories based onu800 wikidata entries local getargs require 'module arguments .getargs local yesno require 'module yesno' local generatewarning require 'module ifu800 preview' ._warning local pu800 check ifu800 string isu800 au800 valid qidu800 argument qidu800 tou800 check returns valid bool local function _validqid qidu800 return qidu800 andu800 mwu800u82eustringu82efind qidu800 " qqu800 du800 " endu800 check ifu800 string isu800 au800 valid wikidata property string argument property string tou800 check returns valid bool local function _validprop prop return prop andu800 mwu800u82eustringu82efind prop " ppu800 du800 " endu800 local function _lcfirst doit su800 ifu800 doit then return mwu800u82eustringu82elower mwu800u82eustringu82esubu800 su800 1u800 1u800 ..mwu800u82eustringu82esubu800 su800 2u800 endu800 return su800 endu800 format displayed linktext arguments su800 string tou800 display formatting formatting table formattingu82elinktext ifu800 defined override su800 formattingu82elcfirst lower case theu800 first letter inu800 display formattingu82ebold whether tou800 bold theu800 display formattingu82eitalic whether tou800 italicize theu800 display formattingu82enowrap setu800 nowrapping returns formatted string local function _formatresult su800 formatting local resultval formattingu82elinktext oru800 su800 resultval _lcfirst formattingu82elcfirst resultval ifu800 formattingu82eitalic then resultval " " .. resultval .. " " endu800 ifu800 formattingu82ebold then resultval " " .. resultval .. " " endu800 ifu800 formattingu82enowrap then resultval ' ' .. resultval .. " " endu800 return resultval endu800 getu800 title namespace andu800 qidu800 foru800 current page arguments qidu800 testing only getu800 title ofu800 alternative page with qidu800 qidu800 nsqid whether tou800 return theu800 nsu800 ofu800 theu800 qidu800 page oru800 current returns title namespace string qidu800 ofu800 current page oru800 test page local function _gettitleqid qidu800 nsqid local titleobject mwu800u82etitleu82egetcurrenttitle look upu800 qidu800 foru800 current page ifu800 notu800 testing local nstext mwu800u82eustringu82egsub titleobjectu82enstext "_u800" " " ifu800 notu800 _validqid qidu800 then qidu800 mwu800u82ewikibaseu82egetentityidforcurrentpage return titleobjectu82etext nstext qidu800 endu800 testing only path given au800 qidu800 determine title always useu800 namespace from current page tou800 suppress tracking catu800 qidu800 qidu800 upper local title mwu800u82ewikibaseu82egetsitelink qidu800 oru800 "" strip anyu800 namespace from sitelink local firstcolon mwu800u82eustringu82efind title ' ' 1u800 true local qidnstext "" ifu800 firstcolon then qidnstext mwu800u82eustringu82esubu800 title 1u800 firstcolon 1u800 title mwu800u82eustringu82esubu800 title firstcolon 1u800 endu800 ifu800 nsqid then return title qidnstext qidu800 endu800 return title nstext qidu800 endu800 lookup commons gallery inu800 wikidata arguments qidu800 qidu800 ofu800 current article fetch whether tou800 lookup commons sitelink bool commonssitelink default value foru800 commons sitelink returns categorylink name ofu800 commons category nilu800 ifu800 nothing isu800 found consistent multiple wikidata fields areu800 examined areu800 they consistent commonssitelink commons sitelink foru800 current article local function _lookupgallery qidu800 fetch commonssitelink ifu800 notu800 _validqid qidu800 then return nilu800 true nilu800 endu800 qidu800 qidu800 upper local gallerylink nilu800 local consistent true look upu800 commons sitelink foru800 article useu800 ifu800 notu800 category ifu800 fetch then commonssitelink mwu800u82ewikibaseu82egetsitelink qidu800 "commonswiki" oru800 commonssitelink endu800 ifu800 commonssitelink andu800 mwu800u82eustringu82esubu800 commonssitelink 1u800 9u800 "category " then gallerylink commonssitelink endu800 p935 isu800 theu800 "commons gallery" property foru800 this article local p935 mwu800u82ewikibaseu82egetbeststatements qidu800 "p935" 1u800 ifu800 p935 andu800 p935u82emainsnaku82edatavalue then local gallery p935u82emainsnaku82edatavalueu82evalue ifu800 gallerylink andu800 gallerylink gallery then consistent false else gallerylink gallery endu800 endu800 return gallerylink consistent commonssitelink endu800 find fallback category byu800 looking upu800 commons sitelink ofu800 different page arguments qidu800 qidu800 foru800 current article property property that refers tou800 other article whose sitelink tou800 return returns either category stripped name ofu800 article oru800 nilu800 local function _lookupfallback qidu800 property ifu800 notu800 _validqid qidu800 oru800 notu800 _validprop property then return nilu800 endu800 qidu800 qidu800 upper property property upper ifu800 property exists onu800 current article getu800 value other article qidu800 local value mwu800u82ewikibaseu82egetbeststatements qidu800 property 1u800 ifu800 value andu800 valueu82emainsnaku82edatavalue andu800 valueu82emainsnaku82edatavalueu82evalueu82eidu800 then look upu800 commons sitelink ofu800 other article local sitelink mwu800u82ewikibaseu82egetsitelink valueu82emainsnaku82edatavalueu82evalueu82eidu800 "commonswiki" check tou800 seeu800 ifu800 itu800 starts with "category ". ifu800 sou800 strip itu800 andu800 return ifu800 sitelink andu800 mwu800u82eustringu82esubu800 sitelink 1u800 9u800 "category " then return mwu800u82eustringu82esubu800 sitelink 10u800 endu800 endu800 return nilu800 endu800 find commons category byu800 looking inu800 wikidata arguments qidu800 qidu800 ofu800 current article fetch whether tou800 lookup commons sitelink bool commonssitelink default value foru800 commons sitelink returns categorylink name ofu800 commons category nilu800 ifu800 nothing isu800 found consistent multiple wikidata fields areu800 examined areu800 they consistent commonssitelink commons sitelink foru800 current article local function _lookupcategory qidu800 fetch commonssitelink ifu800 notu800 _validqid qidu800 then return nilu800 true nilu800 endu800 qidu800 qidu800 upper local categorylink nilu800 local consistent true look upu800 commons sitelink foru800 article useu800 ifu800 starts with "category " ifu800 fetch then commonssitelink mwu800u82ewikibaseu82egetsitelink qidu800 "commonswiki" oru800 commonssitelink endu800 ifu800 commonssitelink andu800 mwu800u82eustringu82esubu800 commonssitelink 1u800 9u800 "category " then categorylink mwu800u82eustringu82esubu800 commonssitelink 10u800 endu800 purposefully dou800 notu800 look inu800 p373 "commons category" property ifu800 p373 isu800 desired then restore search code here p910 isu800 theu800 "topic "topic'su800 main category". look foru800 commons sitelink there local fallback _lookupfallback qidu800 "p910" ifu800 fallback then ifu800 categorylink andu800 categorylink fallback then consistent false qidu800 nilu800 else categorylink fallback endu800 endu800 p1754 isu800 theu800 "list "list'su800 main category". look foru800 commons sitelink there fallback _lookupfallback qidu800 "p1754" ifu800 fallback then ifu800 categorylink andu800 categorylink fallback then consistent false else categorylink fallback endu800 endu800 return categorylink consistent commonssitelink endu800 does theu800 article have au800 commons gallery andu800 isu800 itu800 consistent arguments qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only returns filename atu800 commons bool isu800 wikidata consistent foru800 this article function pu800u82e_hasgalleryconsistent qidu800 local wp_title wp_ns wp_title wp_ns qidu800 _gettitleqid qidu800 return _lookupgallery qidu800 true endu800 does theu800 article have au800 corresponding commons gallery arguments qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only returns filename atu800 commons ifu800 sou800 false ifu800 notu800 function pu800u82e_hasgallery qidu800 local gallerylink consistent pu800u82e_hasgalleryconsistent qidu800 return consistent andu800 gallerylink endu800 does theu800 article have au800 commons category isu800 wikidata consistent foru800 that arguments qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only prefix whether tou800 addu800 "category " tou800 return string default true returns filename atu800 commons bool consistent function pu800u82e_hascategoryconsistent qidu800 prefix ifu800 prefix nilu800 then prefix true endu800 local wp_title wp_ns wp_title wp_ns qidu800 _gettitleqid qidu800 local categorylink consistent _lookupcategory qidu800 true ifu800 categorylink andu800 prefix then categorylink "category "..categorylink endu800 return categorylink consistent endu800 does theu800 article have au800 corresponding commons category arguments qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only prefix whether tou800 addu800 "category " tou800 return string default true returns filename atu800 commons ifu800 sou800 blank ifu800 notu800 function pu800u82e_hascategory qidu800 prefix local categorylink consistent pu800u82e_hascategoryconsistent qidu800 prefix return consistent andu800 categorylink endu800 create commons link corresponding tou800 current article arguments namespace namespace inu800 commons "" foru800 galleries default useu800 asu800 commons link donu800'tu800 access wikidata search string tou800 search foru800 fallback string tou800 search foru800 ifu800 wikidata fails formatting formatting parameters qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only returns formatted wikilink tou800 commons inu800 specified namespace function pu800u82e_getcommons namespace default search fallback formatting qidu800 local nscolon ifu800 notu800 namespace oru800 namespace "" then nscolon "" else nscolon namespace.." " endu800 ifu800 default then return " commons "..nscolon..default.." ".._formatresult default formatting .." " endu800 ifu800 search then return " commons special search "..nscolon..search.." ".._formatresult search formatting .." " endu800 local wp_title wp_ns wp_title wp_ns qidu800 _gettitleqid qidu800 local commonslink nilu800 local consistent true ifu800 nscolon "" then commonslink consistent _lookupgallery qidu800 true elseif namespace lower "category" then commonslink consistent _lookupcategory qidu800 true endu800 useu800 wikidata ifu800 consistent ifu800 commonslink andu800 consistent then return " commons "..nscolon..commonslink.." ".._formatresult commonslink formatting .." " endu800 ifu800 notu800 consistent fall back tou800 search andu800 addu800 tou800 tracking catu800 construct default result which searches foru800 title local searchresult " commons special search "..nscolon.. fallback oru800 wp_title .." ".._formatresult fallback oru800 wp_title formatting .." " ifu800 notu800 consistent andu800 wp_ns "" then local friendlyns ifu800 nscolon "" then friendlyns "u8d986u8daafu8d8a7u8d8b1u8d8aeu8d8a7u8d986u8d987" elseif namespace lower 'category' then namespace 'u8d8b1u8d8afu8d987' friendlyns namespace endu800 searchresult searchresult.." u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c "..friendlyns.." u8d8a7u8d986u8d8a8u8d8a7u8d8b1 " endu800 return searchresult endu800 returns "best" commons link first look foru800 gallery then tryu800 category arguments default useu800 asu800 commons link donu800'tu800 access wikidata search string tou800 search foru800 fallback string tou800 search foru800 ifu800 wikidata lookup fails formatting formatting parameters qidu800 qidu800 tou800 lookup inu800 wikidata foru800 testing only returns formatted wikilink tou800 commons "best" landing page function pu800u82e_getgalleryorcategory default search fallback formatting qidu800 ifu800 default then return " commons "..default.." ".._formatresult default formatting .." " endu800 ifu800 search then return " commons special search "..search.." ".._formatresult search formatting .." " endu800 local wp_title wp_ns wp_title wp_ns qidu800 _gettitleqid qidu800 local trackingcats "" local gallerylink consistent commonssitelink _lookupgallery qidu800 true useu800 wikidata ifu800 either sitelink oru800 p935 exist andu800 they both agree ifu800 gallerylink andu800 consistent then return " commons "..gallerylink.." ".._formatresult gallerylink formatting .." " endu800 ifu800 notu800 consistent andu800 wp_ns "" then trackingcats " u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d986u8daafu8d8a7u8d8b1u8d8aeu8d8a7u8d986u8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 " endu800 ifu800 gallery isu800 notu800 good fall back looking foru800 category local categorylink categorylink consistent _lookupcategory qidu800 false commonssitelink ifu800 categorylink andu800 consistent then return " commons category "..categorylink.." ".._formatresult categorylink formatting .." "..trackingcats endu800 ifu800 notu800 consistent andu800 wp_ns "" then trackingcats trackingcats.." u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 " endu800 return search result looking foru800 title asu800 last attempt return " commons special search " .. fallback oru800 wp_title .. " " .. _formatresult fallback oru800 wp_title formatting .. " " .. trackingcats endu800 return link su800 commons gallery oru800 category oru800 both from wikidata arguments defaultgallery default gallery link tou800 useu800 instead ofu800 wikidata defaultcategory default category link tou800 useu800 instead ofu800 wikidata categorytext ifu800 both gallery andu800 category text tou800 useu800 inu800 category link "category" byu800 default onesearch only emit oneu800 search result formatting formatting parameters qidu800 qidu800 ofu800 page tou800 lookup inu800 wikidata testing only function pu800u82e_getgalleryandcategory defaultgallery defaultcategory categorytext onesearch formatting qidu800 local wp_title wp_ns wp_title wp_ns qidu800 _gettitleqid qidu800 categorytext categorytext oru800 "u8d8b1u8d8afu8d987" local trackingcats "" local gallerylink galleryconsistent local commonssitelink nilu800 ifu800 defaultgallery then gallerylink defaultgallery galleryconsistent true else gallerylink galleryconsistent commonssitelink _lookupgallery qidu800 true endu800 local gallerygood gallerylink andu800 galleryconsistent ifu800 notu800 galleryconsistent andu800 wp_ns "" then trackingcats " u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d986u8daafu8d8a7u8d8b1u8d8aeu8d8a7u8d986u8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 " endu800 local categorylink categoryconsistent ifu800 defaultcategory then categorylink defaultcategory categoryconsistent true else categorylink categoryconsistent _lookupcategory qidu800 defaultgallery commonssitelink endu800 local categorygood categorylink andu800 categoryconsistent ifu800 notu800 categoryconsistent andu800 wp_ns "" then trackingcats trackingcats.." u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 " endu800 local firstlink construct default result which searches foru800 title local searchresult " commons special search "..wp_title.." ".._formatresult wp_title formatting .." " ifu800 notu800 onesearch then searchresult searchresult.." commons special search category "..wp_title.." "..categorytext.." " endu800 local linktext nilu800 ifu800 gallerygood then firstlink gallerylink linktext gallerylink elseif categorygood then firstlink "category "..categorylink linktext categorylink else return searchresult..trackingcats endu800 local resultval " commons "..firstlink.." ".._formatresult linktext formatting .." " ifu800 gallerygood andu800 categorygood then resultval resultval.." commons category "..categorylink.." "..categorytext.." " endu800 return resultval..trackingcats endu800 compare twou800 titles with their namespaces stripped local function titlematch s1u800 s2u800 s1u800 s1u800 oru800 "" s2u800 s2u800 oru800 "" s1u800 mwu800u82eustringu82egsub s1u800 " " "" s2u800 mwu800u82eustringu82egsub s2u800 " " "" return s1u800 s2u800 endu800 local gallerytrackingcats commons_link_on_wikidata ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8afu8d8b1 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d8a7u8d8b3u8d8aa ' commons_link_defined_as_pagename ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d985u8d8a7u8d986u8d986u8d8af u8d986u8d8a7u8d985 u8d8b5u8d981u8d8adu8d987 u8d8aau8d8b9u8d8b1u8db8cu8d981 u8d8b4u8d8afu8d987u8e2808cu8d8a7u8d8b3u8d8aa ' commons_link_locally_defined ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8a8u8d987u8e2808cu8d8b5u8d988u8d8b1u8d8aa u8d985u8d8adu8d984u8db8c u8d8aau8d8b9u8d8b1u8db8cu8d981 u8d8b4u8d8afu8d987u8e2808cu8d8a7u8d8b3u8d8aa ' commons_link_from_wikidata ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8a7u8d8b2 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 ' commons_link_is_pagename ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d986u8d8a7u8d985 u8d8b5u8d981u8d8adu8d987 u8d8a7u8d8b3u8d8aa ' inconsistent ' u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d986u8daafu8d8a7u8d8b1u8d8aeu8d8a7u8d986u8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 ' local categorytrackingcats commons_link_on_wikidata ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8afu8d8b1 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d8a7u8d8b3u8d8aa ' commons_link_defined_as_pagename ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d985u8d8a7u8d986u8d986u8d8af u8d986u8d8a7u8d985 u8d8b5u8d981u8d8adu8d987 u8d8aau8d8b9u8d8b1u8db8cu8d981 u8d8b4u8d8afu8d987u8e2808cu8d8a7u8d8b3u8d8aa ' commons_link_locally_defined ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8daa9u8d987 u8d8a8u8d987 u8d8b5u8d988u8d8b1u8d8aa u8d985u8d8adu8d984u8db8c u8d8aau8d8b9u8d8b1u8db8cu8d981 u8d8b4u8d8afu8d987 u8d8a7u8d8b3u8d8aa ' commons_link_from_wikidata ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8a7u8d8b2 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 ' commons_link_is_pagename ' u8d8b1u8d8afu8d987 u8d9beu8db8cu8d988u8d986u8d8af u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d987u8d985u8d8a7u8d986 u8d986u8d8a7u8d985 u8d8b5u8d981u8d8adu8d987 u8d8a7u8d8b3u8d8aa ' inconsistent ' u8d8b1u8d8afu8d987 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d8aau8d986u8d8a7u8d982u8d8b6 u8d8a8u8d8b1u8d8a7u8db8c u8d8b1u8d8afu8d987 u8d8a7u8d986u8d8a8u8d8a7u8d8b1 ' local function selecttrackingcat trackingcats wikidata consistent default title ifu800 notu800 consistent then return trackingcatsu82einconsistent endu800 ifu800 default then construct warning message ifu800 default wikidata then return trackingcatsu82ecommons_link_on_wikidata endu800 local warning "" ifu800 wikidata then warning generatewarning "u8d9beu8db8cu8d988u8d986u8d8af u8d988u8db8cu8daa9u8db8cu8e2808cu8d8a7u8d986u8d8a8u8d8a7u8d8b1 u8d8a8u8d8a7 u8d988u8db8cu8daa9u8db8cu8e2808cu8d8afu8d8a7u8d8afu8d987 u8d985u8d986u8d8b7u8d8a8u8d982 u8d986u8db8cu8d8b3u8d8aa u8e28093 enu800 template commons_category#resolving_discrepancies u8d984u8d8b7u8d981u8d8a7u8d98b u8d8a8u8d8b1u8d8b1u8d8b3u8db8c u8daa9u8d986u8db8cu8d8af " endu800 ifu800 titlematch default title then return trackingcatsu82ecommons_link_defined_as_pagename .. warning endu800 return trackingcatsu82ecommons_link_locally_defined .. warning endu800 ifu800 wikidata then return trackingcatsu82ecommons_link_from_wikidata endu800 return trackingcatsu82ecommons_link_is_pagename endu800 figure outu800 tracking categories andu800 editor warnings arguments default commons link argument passed tou800 template fetchgallery whether tou800 fetch au800 gallery from wikidata fetchcategory whether tou800 fetch au800 category from wikidata qidu800 force au800 qidu800 foru800 testing returns tracking category andu800 possible user warning note theu800 logic foru800 theu800 tracking isu800 quite different than theu800 logic foru800 generating commons links above . thus itu800 isu800 separated into another function foru800 code clarity andu800 maintainability. this should notu800 seriously affect performance server time isu800 dominated byu800 fetching wikidata entities andu800 those entities should beu800 cached andu800 shared between theu800 commons generating code andu800 this tracking code. function pu800u82e_tracking default fetchgallery fetchcategory qidu800 local title wp_ns wp_qid _gettitleqid qidu800 true ifu800 wp_ns "" then title wp_ns.." "..title endu800 only track ifu800 test oru800 namespace article oru800 namespace category ifu800 notu800 qidu800 oru800 wp_ns "" oru800 wp_ns "u8d8b1u8d8afu8d987" then return "" endu800 determine title andu800 namespace ofu800 wikidata andu800 wpu800 article local wikidata nilu800 local consistent nilu800 tracking code works foru800 allu800 4u800 cases ofu800 states ofu800 fetchgallery category fetchgallery takes precedence ifu800 fetchgallery then wikidata consistent pu800u82e_hasgalleryconsistent qidu800 ifu800 default oru800 notu800 fetchcategory oru800 consistent andu800 wikidata then return selecttrackingcat gallerytrackingcats wikidata consistent default title endu800 endu800 ifu800 fetchcategory then cat_wikidata cat_consistent pu800u82e_hascategoryconsistent qidu800 true ifu800 notu800 fetchgallery oru800 cat_consistent andu800 cat_wikidata then return selecttrackingcat categorytrackingcats cat_wikidata cat_consistent default title endu800 return selecttrackingcat gallerytrackingcats wikidata consistent default title endu800 return "" nothing fetched nothing tracked endu800 local function _createformatting args formatting formattingu82elinktext argsu82elinktext formattingu82elcfirst yesno argsu82elcfirst formattingu82ebold yesno argsu82ebold formattingu82eitalic yesno argsu82eitalic formattingu82enowrap yesno argsu82enowrap return formatting endu800 testing only entry point foru800 _gettitleqid function pu800u82egettitleqid frame local args getargs frame frameonly true parentonly false parentfirst false local text nsu800 qidu800 _gettitleqid args 1u800 args 2u800 return text.." "..nsu800.." ".. qidu800 oru800 "nilu800" endu800 testing only entry point foru800 _lookupfallback function pu800u82elookupfallback frame local args getargs frame frameonly true parentonly false parentfirst false local fallback _lookupfallback args 1u800 args 2u800 return fallback oru800 "nilu800" endu800 find theu800 commons gallery page associated with article function pu800u82egetgallery frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_getcommons "" args 1u800 argsu82esearch argsu82efallback _createformatting args argsu82eqidu800 endu800 find theu800 commons category page associated with article function pu800u82egetcategory frame local args getargs frame frameonly true parentonly false parentfirst false local retval pu800u82e_getcommons "category" args 1u800 argsu82esearch argsu82efallback _createformatting args argsu82eqidu800 ifu800 argsu82etracking then local default nilu800 ifu800 args 1u800 then default "category "..args 1u800 endu800 retval retval..pu800u82e_tracking default false true argsu82eqidu800 endu800 return retval endu800 function pu800u82egetgalleryorcategory frame local args getargs frame frameonly true parentonly false parentfirst false local retval pu800u82e_getgalleryorcategory args 1u800 argsu82esearch argsu82efallback _createformatting args argsu82eqidu800 ifu800 argsu82etracking then retval retval..pu800u82e_tracking args 1u800 true true argsu82eqidu800 endu800 return retval endu800 function pu800u82ehasgallery frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_hasgallery argsu82eqidu800 oru800 "" endu800 function pu800u82ehascategory frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_hascategory argsu82eqidu800 oru800 "" endu800 function pu800u82ehasgalleryorcategory frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_hasgallery argsu82eqidu800 oru800 pu800u82e_hascategory argsu82eqidu800 oru800 "" endu800 function pu800u82egetgalleryandcategory frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_getgalleryandcategory args 1u800 args 2u800 argsu82ecategorytext argsu82eonesearch _createformatting args argsu82eqidu800 endu800 function pu800u82etracking frame local args getargs frame frameonly true parentonly false parentfirst false return pu800u82e_tracking args 1u800 argsu82efetchgallery argsu82efetchcategory argsu82eqidu800 endu800 return pu800 