Anonymous user
Module:Authority control: Difference between revisions
Jump to navigation
Jump to search
+Support for Category:AC using state parameter tracking, from sandbox
Richardpruen (talk | contribs) m (1 revision imported: Template for journal ) |
(+Support for Category:AC using state parameter tracking, from sandbox) |
||
Line 13: | Line 13: | ||
local catName = '' | local catName = '' | ||
if namespace == 0 then | if namespace == 0 then | ||
catName = ' | catName = 'Articles with '..id..' identifiers' | ||
elseif namespace == 2 and not title.isSubpage then | elseif namespace == 2 and not title.isSubpage then | ||
catName = 'User pages with '..id..' identifiers' | catName = 'User pages with '..id..' identifiers' | ||
Line 33: | Line 33: | ||
function p.createRow( id, rawValues, link, links, withUid, specialCat, prefix) | function p.createRow( id, rawValues, link, links, withUid, specialCat, prefix) | ||
local catName = ' | local catName = 'Articles with faulty '..(specialCat or id)..' identifiers' | ||
if links then -- all links[] use withUid = false; no check needed | if links then -- all links[] use withUid = false; no check needed | ||
local row = '' | local row = '' | ||
Line 910: | Line 910: | ||
'! colspan=4 | Tracking categories and page counts\n'.. | '! colspan=4 | Tracking categories and page counts\n'.. | ||
'|-\n'.. | '|-\n'.. | ||
'! [[:Category: | '! [[:Category:Articles with authority control information|'.. 'Articles]]\n'.. | ||
'! [[:Category:User pages with authority control information|'.. | '! [[:Category:User pages with authority control information|'.. 'User pages]]\n'.. | ||
'! [[:Category:Miscellaneous pages with authority control information|'.. | '! [[:Category:Miscellaneous pages with authority control information|'..'Misc. pages]]\n'.. | ||
'! [[:Category: | '! [[:Category:Articles with faulty authority control information|'.. 'Faulty IDs]]\n'.. | ||
'|-\n' | '|-\n' | ||
local lang = mw.getContentLanguage() | local lang = mw.getContentLanguage() | ||
local a, u, m, f, P = 0, 0, 0, 0, 0 --cumulative sums | |||
for _, conf in pairs( p.conf ) do | for _, conf in pairs( p.conf ) do | ||
local param, pid, section = conf[1], conf[2], conf[4] | local param, pid, section = conf[1], conf[2], conf[4] | ||
Line 932: | Line 933: | ||
local wpl = frame:expandTemplate{ title = 'Wikidata property link', args = args } | local wpl = frame:expandTemplate{ title = 'Wikidata property link', args = args } | ||
--cats | --cats | ||
local articleCat = ' | local articleCat = 'Articles with '..category..' identifiers' | ||
local userCat = 'User pages with '..category..' identifiers' | local userCat = 'User pages with '..category..' identifiers' | ||
local miscCat = 'Miscellaneous pages with '..category..' identifiers' | local miscCat = 'Miscellaneous pages with '..category..' identifiers' | ||
local faultyCat = ' | local faultyCat = 'Articles with faulty '..category..' identifiers' | ||
--counts | --counts | ||
local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) | local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) | ||
Line 941: | Line 942: | ||
local miscCount = lang:formatNum( mw.site.stats.pagesInCategory(miscCat, 'pages') ) | local miscCount = lang:formatNum( mw.site.stats.pagesInCategory(miscCat, 'pages') ) | ||
local faultyCount = lang:formatNum( mw.site.stats.pagesInCategory(faultyCat, 'pages') ) | local faultyCount = lang:formatNum( mw.site.stats.pagesInCategory(faultyCat, 'pages') ) | ||
--calcs | |||
P = P + 1 --property count | |||
a = a + lang:parseFormattedNumber(articleCount) | |||
u = u + lang:parseFormattedNumber(userCount) | |||
m = m + lang:parseFormattedNumber(miscCount) | |||
f = f + lang:parseFormattedNumber(faultyCount) | |||
--concat | --concat | ||
wikiTable = wikiTable..'\n'.. | wikiTable = wikiTable..'\n'.. | ||
Line 958: | Line 964: | ||
local wcd = { 'WorldCat-LCCN', 'WorldCat-VIAF' } | local wcd = { 'WorldCat-LCCN', 'WorldCat-VIAF' } | ||
for _, w in pairs(wcd) do | for _, w in pairs(wcd) do | ||
local articleCat = ' | local articleCat = 'Articles with '..w..' identifiers' | ||
local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) | local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(articleCat, 'pages') ) | ||
local appearsAs | local appearsAs | ||
Line 966: | Line 972: | ||
appearsAs = '[https://www.worldcat.org/identities/containsVIAFID/12345789 WorldCat (via VIAF)]' | appearsAs = '[https://www.worldcat.org/identities/containsVIAFID/12345789 WorldCat (via VIAF)]' | ||
end | end | ||
a = a + lang:parseFormattedNumber(articleCount) | |||
wikiTable = wikiTable..'\n'.. | wikiTable = wikiTable..'\n'.. | ||
'|-\n'.. | '|-\n'.. | ||
Line 977: | Line 984: | ||
'||style="text-align: right;"|—' | '||style="text-align: right;"|—' | ||
end | end | ||
--append sums | |||
wikiTable = wikiTable..'\n'.. | |||
'|-\n'.. | |||
'! style="text-align: right;" colspan=3|Totals'.. | |||
'||style="text-align: right;"|'..lang:formatNum(P).. | |||
'||style="text-align: right;"|'..lang:formatNum(a).. | |||
'||style="text-align: right;"|'..lang:formatNum(u).. | |||
'||style="text-align: right;"|'..lang:formatNum(m).. | |||
'||style="text-align: right;"|'..lang:formatNum(f) | |||
return require('Module:Suppress categories').main(wikiTable)..'\n|}' | return require('Module:Suppress categories').main(wikiTable)..'\n|}' | ||
Line 1,098: | Line 1,115: | ||
} | } | ||
-- Deprecated aliases to p.conf; tracked in [[Category: | -- Deprecated aliases to p.conf; tracked in [[Category:Articles with deprecated authority control identifiers]] | ||
-- Format: { 'deprecated parameter name', 'replacement parameter name in p.conf' } | -- Format: { 'deprecated parameter name', 'replacement parameter name in p.conf' } | ||
p.deprecated = { | p.deprecated = { | ||
Line 1,118: | Line 1,135: | ||
local iParentArgs = 0 --count original/manual parent args only later | local iParentArgs = 0 --count original/manual parent args only later | ||
local worldcatCat = '' | local worldcatCat = '' | ||
local elementsCat = '' | |||
local multipleIdCat = '' | local multipleIdCat = '' | ||
local suppressedIdCat = '' | local suppressedIdCat = '' | ||
local suppressedIdCatArts = '' | |||
local deprecatedIdCat = '' | local deprecatedIdCat = '' | ||
local differentOnWDCat = '' | local differentOnWDCat = '' | ||
local sameOnWDCat = '' | local sameOnWDCat = '' | ||
local stateCat = '' | |||
-- | --redirect aliases to proper parameter names | ||
for _, a in pairs( p.aliases ) do | for _, a in pairs( p.aliases ) do | ||
local alias, param = a[1], a[2] | local alias, param = a[1], a[2] | ||
Line 1,132: | Line 1,152: | ||
end | end | ||
-- | --redirect deprecated parameters to proper parameter names, and assign tracking cat | ||
for _, d in pairs( p.deprecated ) do | for _, d in pairs( p.deprecated ) do | ||
local dep, param = d[1], d[2] | local dep, param = d[1], d[2] | ||
Line 1,138: | Line 1,158: | ||
parentArgs[param] = parentArgs[dep] | parentArgs[param] = parentArgs[dep] | ||
if namespace == 0 then | if namespace == 0 then | ||
deprecatedIdCat = '[[Category: | deprecatedIdCat = '[[Category:Articles with deprecated authority control identifiers|'..dep..']]' | ||
end | end | ||
end | end | ||
end | end | ||
-- | --use QID= parameter for testing/example purposes only | ||
local itemId = nil | local itemId = nil | ||
if namespace ~= 0 then | if namespace ~= 0 then | ||
Line 1,157: | Line 1,177: | ||
--Wikidata fallback if available | --Wikidata fallback if available | ||
if itemId then | if itemId then | ||
local suppressedIdCount = 0 | |||
local iMatches = 0 | local iMatches = 0 | ||
for _, params in ipairs( p.conf ) do | for _, params in ipairs( p.conf ) do | ||
Line 1,165: | Line 1,186: | ||
if wikidataIds[1] then | if wikidataIds[1] then | ||
if val == '' and (namespace == 0 or testcases) then | if val == '' and (namespace == 0 or testcases) then | ||
suppressedIdCat = '[[Category: | suppressedIdCount = suppressedIdCount + 1 | ||
suppressedIdCat = '[[Category:Articles with suppressed authority control identifiers|'..params[1]..']]' | |||
else | else | ||
parentArgs[params[1]] = wikidataIds[1] --add ID from WD | parentArgs[params[1]] = wikidataIds[1] --add ID from WD | ||
Line 1,186: | Line 1,208: | ||
if iMatches > 0 and iMatches == iParentArgs then | if iMatches > 0 and iMatches == iParentArgs then | ||
sameOnWDCat = '[[Category:Pages using authority control with parameters all matching Wikidata]]' | sameOnWDCat = '[[Category:Pages using authority control with parameters all matching Wikidata]]' | ||
end | |||
if parentArgs['arts'] == 'arts' and suppressedIdCount > 0 then | |||
if namespace == 0 or testcases then | |||
local s = 's' | |||
if suppressedIdCount == 1 then s = '' end | |||
local sCat = 'ACArt with '..suppressedIdCount..' suppressed element'..s | |||
suppressedIdCatArts = '[[Category:'..sCat..']]'..p.redCatLink(sCat) | |||
end | |||
end | end | ||
end | end | ||
-- | |||
--configure rows | |||
local rct = 0 | local rct = 0 | ||
local sectionOrder = {'General','National libraries','Art galleries and museums', | local sectionOrder = {'General','National libraries','Art galleries and museums', | ||
Line 1,202: | Line 1,233: | ||
['Other'] = {} | ['Other'] = {} | ||
} | } | ||
-- | --don't show NLP if PLWABN is present, since they both go to the National Library of Poland | ||
-- and the library has deprecated NLP IDs in favor of PLWABN IDs | --and the library has deprecated NLP IDs in favor of PLWABN IDs | ||
if parentArgs.PLWABN or parentArgs.plwabn then | if parentArgs.PLWABN or parentArgs.plwabn then | ||
parentArgs.NLP = '' | parentArgs.NLP = '' | ||
Line 1,258: | Line 1,289: | ||
table.insert( sections['General'], p.createRow( 'VIAF', viafId, '[https://www.worldcat.org/identities/containsVIAFID/'..viafId..' WorldCat (via VIAF)]', nil, false ) ) | table.insert( sections['General'], p.createRow( 'VIAF', viafId, '[https://www.worldcat.org/identities/containsVIAFID/'..viafId..' WorldCat (via VIAF)]', nil, false ) ) | ||
if namespace == 0 then | if namespace == 0 then | ||
worldcatCat = '[[Category: | worldcatCat = '[[Category:Articles with WorldCat-VIAF identifiers]]' | ||
end | end | ||
rct = rct + 1 | rct = rct + 1 | ||
Line 1,267: | Line 1,298: | ||
table.insert( sections['General'], p.createRow( 'LCCN', lccnId, '[https://www.worldcat.org/identities/lccn-'..lccnIdFmtd..' WorldCat (via Library of Congress)]', nil, false ) ) | table.insert( sections['General'], p.createRow( 'LCCN', lccnId, '[https://www.worldcat.org/identities/lccn-'..lccnIdFmtd..' WorldCat (via Library of Congress)]', nil, false ) ) | ||
if namespace == 0 then | if namespace == 0 then | ||
worldcatCat = '[[Category: | worldcatCat = '[[Category:Articles with WorldCat-LCCN identifiers]]' | ||
end | end | ||
end | end | ||
Line 1,273: | Line 1,304: | ||
end | end | ||
elseif worldcatId == '' then --if WORLDCATID suppressed | elseif worldcatId == '' then --if WORLDCATID suppressed | ||
suppressedIdCat = '[[Category: | suppressedIdCat = '[[Category:Articles with suppressed authority control identifiers|WORLDCATID]]' | ||
end | end | ||
--configure Navbox | |||
local outString = '' | local outString = '' | ||
if rct > 0 then | if rct > 0 then | ||
local Navbox = require('Module:Navbox') | |||
local sectionID = 1 | local sectionID = 1 | ||
local args = { pid = 'identifiers' } -- #target the list of identifiers | local args = { pid = 'identifiers' } -- #target the list of identifiers | ||
Line 1,318: | Line 1,344: | ||
end | end | ||
local auxCats = worldcatCat..elementsCat..multipleIdCat..suppressedIdCat.. | --auxCats | ||
deprecatedIdCat..differentOnWDCat..sameOnWDCat | if rct == 0 or rct >= 25 then | ||
if namespace == 0 or testcases then | |||
local eCat = 'AC with '..rct..' elements' | |||
elementsCat = '[[Category:'..eCat..']]'..p.redCatLink(eCat) | |||
end | |||
end | |||
if parentArgs.state then | |||
if namespace == 0 or testcases then | |||
local sCat | |||
if parentArgs.state == 'collapsed' then sCat = 'AC using state parameter: collapsed' | |||
elseif parentArgs.state == 'expanded' then sCat = 'AC using state parameter: expanded' | |||
elseif parentArgs.state == 'autocollapse' then sCat = 'AC using state parameter: autocollapse' | |||
else sCat = 'AC using state parameter: other' | |||
end | |||
stateCat = '[[Category:'..sCat..']]'..p.redCatLink(sCat) | |||
end | |||
end | |||
local auxCats = worldcatCat..elementsCat..multipleIdCat..suppressedIdCat..suppressedIdCatArts.. | |||
deprecatedIdCat..differentOnWDCat..sameOnWDCat..stateCat | |||
if testcases then | if testcases then | ||
auxCats = mw.ustring.gsub(auxCats, '(%[%[)(Category)', '%1:%2') --for easier checking | auxCats = mw.ustring.gsub(auxCats, '(%[%[)(Category)', '%1:%2') --for easier checking | ||
end | end | ||
--out | |||
outString = outString..auxCats | outString = outString..auxCats | ||
if namespace ~= 0 then | if namespace ~= 0 then | ||
outString = mw.ustring.gsub(outString, '(%[%[)(Category: | outString = mw.ustring.gsub(outString, '(%[%[)(Category:Articles)', '%1:%2') --by definition | ||
end | end | ||